Skip to content

Avoid duplicate Tasks startup reconciliation - #3213

Open
bb-slop-cop[bot] wants to merge 1 commit into
mainfrom
slopcop/issue-3209
Open

Avoid duplicate Tasks startup reconciliation#3213
bb-slop-cop[bot] wants to merge 1 commit into
mainfrom
slopcop/issue-3209

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Tasks lifecycle registration awaited the same tracked-thread reconciliation twice. Each pass performs one SDK lookup for every tracked row that remains non-terminal, so startup repeated the full lookup pass without any intervening work. The direct reproduction and root-cause report is at https://get-bb.github.io/reports/issues/3209.html.

What changed

Removed the duplicate startup reconciliation call and added a focused lifecycle regression test that requires one lookup for one non-terminal tracked thread. Updated existing lifecycle expectations and periodic-sweep setup to reflect the intended single startup pass. This changes 20 text lines across 2 files and does not change any wire contract, CLI surface, dependency, generated file, migration, or stored data.

How you verified

  • The focused regression test failed on unchanged origin/main: one tracked thread recorded two threads.get calls instead of one.
  • The same failure reproduced in a second clean checkout at 06aeaa994942ae7527dc49d2268c1f801e8542a0 after a frozen install and full build.
  • The focused regression test passes after the fix.
  • pnpm exec turbo run test --filter=bb-plugin-tasks — 35 files and 365 tests passed.
  • pnpm exec turbo run typecheck --filter=bb-plugin-tasks — passed.
  • pnpm exec turbo run build --filter=bb-plugin-tasks — passed.
  • git diff --check — passed.
  • The required pre-push EAP codename scan was clean for tracked content, changed lines, and the commit message.

Fixes #3209

AGENT GENERATED

ymichael added a commit that referenced this pull request Sep 10, 2026
## Human comments

## What was wrong

Every global thread lifecycle event made Tasks enumerate all tasks and
query each task's worker mappings before filtering by the event's thread
ID. On current main `f41d564163180f87304986b61706db6d69314759`, an
unrelated event executes 202 SQL statements with 200 tasks and 505 with
501 tasks. The task-list method itself performs two statements per page,
so method-call counts understated the database work. Original
investigation: https://get-bb.github.io/reports/issues/3210.html.

## What changed

Use an internal lookup returning every mapping for the event's thread ID
through the existing `idx_task_threads_thread` index. Unrelated events
now execute one lookup; legitimate multi-task fan-out, comments,
notifications, recovery, and terminal protection remain intact. Startup
and periodic reconciliation are unchanged; #3213 addresses the separate
duplicate-startup issue.

Added SQL-level coverage using real in-memory SQLite and the Tasks
schema migrations, alongside the original no-scan regression. Removed
two existing non-semantic comments to satisfy repository lint. No
schema/index, public SDK/CLI, configuration, or server/daemon wire
changes; no host-daemon protocol bump is needed.

## How you verified

- Before production changes, eight SQL-budget regressions failed on
unchanged current main; two reconciliation checks passed.
- Compared baseline and fixed behavior with zero, one, 200, and 501
mappings, all five event types, and one thread mapped to 1, 3, or 200
tasks. Verified created-event status mapping, task status changes,
deletion cascade, comments, recovery, idempotence, and notifications.
- SQLite EXPLAIN confirms the existing thread-ID index is used. Sorting
is limited to matching rows. These are structural SQL improvements; no
end-user latency improvement was measured.
- An expanded 21-case audit passed with each implementation's measured
SQL budgets. The two startup/periodic audit cases remain outside the
patch to avoid adding expectations that constrain #3213.
- `pnpm exec turbo run test typecheck build lint
--filter=bb-plugin-tasks`: 388 tests passed in 36 files, plus
typecheck/build. Tasks has no lint script, so explicit changed-file
oxlint was also run.
- Separately typechecked the new regression through Turbo. Changed-file
oxlint, oxfmt check, and `git diff --check` passed.
- Started `pnpm start:worktree`; server and daemon health checks passed.
Installed/enabled the bundled Tasks plugin and confirmed 12 sample tasks
across 3 projects through the running API/CLI. No browser-driven UI
verification is claimed.

Fixes #3210

> AGENT GENERATED

---------

Co-authored-by: Sawyer Hood <sawyerjhood@gmail.com>
Co-authored-by: Michael Yong <610102+ymichael@users.noreply.github.com>
Co-authored-by: Fabio <81859+fgrehm@users.noreply.github.com>
Co-authored-by: Jason Son <jasonson2004@gmail.com>
Co-authored-by: vznh <nailguninthebackpocket@gmail.com>
Co-authored-by: Michael Yong <wrong92@gmail.com>
Co-authored-by: Hemanth Soni <git@soni.im>
Co-authored-by: Scott <github@smsunarto.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Ilya Martynov <ilya@martynov.org>
Co-authored-by: Tom <87342167+MacHatter1@users.noreply.github.com>
Co-authored-by: brsbl <brsabel.t@gmail.com>
Co-authored-by: noih <33519169+noih@users.noreply.github.com>
Co-authored-by: bb-slop-cop[bot] <316425484+bb-slop-cop[bot]@users.noreply.github.com>
Co-authored-by: Andrew Chan <andrewkchan.akc@gmail.com>
Co-authored-by: kongenpei <kongenpei.jojo@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tasks plugin reconciles every tracked worker thread twice on each plugin load

1 participant