Avoid duplicate Tasks startup reconciliation - #3213
Open
bb-slop-cop[bot] wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
origin/main: one tracked thread recorded twothreads.getcalls instead of one.06aeaa994942ae7527dc49d2268c1f801e8542a0after a frozen install and full build.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.Fixes #3209