Repository navigation
Add bb tasks detach and list live task threads first - #2167
Merged
Merged
Conversation
Task thread attachments were append-only: the store had deleteTaskThread but no RPC, CLI command, or UI control reached it, so an orchestrator that respawned a worker accumulated every dead predecessor on the task. listTaskThreads also ordered rows oldest-first, so the first row in `bb tasks threads`, `bb tasks show`, and the task page was the dead one. Add taskThreadsDetach to the delegation RPC contract (inverse of taskThreadsAttach; fails when the thread is not attached), a `bb tasks detach <key> [--thread <id>]` command that resolves the thread the same way attach does, and a confirm-then-detach control on each thread card. Order listTaskThreads live-first, newest-first so the thread holding the work leads the list everywhere the array is rendered. Fixes #1761 Co-Authored-By: Claude <[email protected]>
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.
What was wrong
Task thread attachments in the Tasks plugin were append-only.
upsertTaskThreadinserts one row per(task_id, thread_id)and the store'sdeleteTaskThreadwas dead code: no RPC indelegationRpcContract, no CLI command, and no UI control reached it. An orchestrator that respawns a worker and attaches each replacement therefore accumulates every dead predecessor on the task, and a thread that moves on to another task keeps its row on the old one. On top of that,listTaskThreadsordered rowsORDER BY attached_at, id(oldest first), so the first row inbb tasks threads,bb tasks show,--json, and the task page's "Agent threads" section was the dead predecessor. Issue: #1761. Report: https://get-bb.github.io/reports/issues/1761.htmlWhat changed
plugins/tasks/db/store.ts:listTaskThreadsnow orders live threads (starting/working/idle) before terminal ones (completed/failed), newest first within each group (attached_at DESC, id DESC). This is the single read path, so the CLI table,--json,bb tasks show, the detail page cards, the PR-pill ordering, and task mentions all follow.plugins/tasks/delegate/contract.ts,plugins/tasks/delegate/index.ts: newtaskThreadsDetachRPC, the inverse oftaskThreadsAttach. It deletes the(task, thread)row via the existinggetTaskThreadByThreadId+deleteTaskThread, publishesthreads:changedandtasks:changedlike attach, and fails withThread <id> is not attached to <KEY>when there is no row. Detaching from one task leaves the same thread's rows on other tasks alone. The reconcile service readstask_threads, so a detached thread is no longer tracked.plugins/tasks/cli/index.ts:bb tasks detach <key> [--thread <thread-id>] [--json]. Thread resolution is shared withattach(--thread, thenBB_THREAD_ID, then the CLI context thread) through a smallresolveInvokingThreadIdhelper. Root help and the registered command list includedetach.plugins/tasks/views/detail/threads.tsx,plugins/tasks/views/detail/index.tsx: each thread card gets an X "Detach <title>" control that opens the plugin'sConfirmDialogand then callstaskThreadsDetach; the detail view refreshes the thread and PR queries. Errors surface through the existing detail toasts.plugins/tasks/README.md(command table + delegation section),plugins/tasks/skills/tasks/SKILL.md(step 6 tells agents to detach on hand-off/respawn),packages/templates/src/templates/bb-guide-plugins.md, andapps/server/src/services/skills/builtin-skills/bb-cli/SKILL.md.Plugin-internal only: nothing on the server/host-daemon wire changes, so no
HOST_DAEMON_PROTOCOL_VERSIONbump.attached_atis left untouched on re-attach (it still means "first attached"); a revived thread moves to the live group because the upsert refresheslive_status.How you verified
New tests (all fail on origin/main, pass on this branch):
plugins/tasks/db.test.ts"lists live task threads before terminal ones, newest first" — before:AssertionError: expected [ 'thr_dead_first', …(3) ] to deeply equal [ Array(4) ].plugins/tasks/delegate/delegate.test.ts"detaches an attached thread through taskThreadsDetach and invalidates" — before:plugin "tasks" has no rpc method "taskThreadsDetach".plugins/tasks/cli/cli.test.ts"detaches a thread withbb tasks detachand lists live threads first" — before:expected 'Usage: bb tasks <command> [options]\n…' to contain 'detach …'.plugins/tasks/views/detail/threads.test.tsx"detaches a thread from its card after confirmation and refetches the list" — before:Unable to find role="button" and name "Detach Worker".Fail-before was produced by checking out the six source files from
origin/mainwith the new tests in place (4 failed | 1 passed), then restoring the branch (4 passed).From the committed tree (
git status --porcelainempty):pnpm exec turbo run typecheck --filter=bb-plugin-tasks --filter=@bb/templates --filter=@bb/server --filter=@bb/cli→Tasks: 8 successful, 8 totalpnpm exec turbo run test --filter=bb-plugin-tasks --filter=@bb/cli --force→Tasks: 7 successful, 7 total(tasks: 35 test files passed; cli: 48 passed)Manual repro on my own dev instance with the builtin tasks plugin installed from this branch, mirroring the issue's transcript (one codex thread forced into
errorwith a bogus model, one real idle thread, both attached to SC-1 in that order):In the app (headless Chrome via doobie), the SC-2 page listed the Idle thread above the Failed one, the X control opened "Detach thread?", and confirming removed the card;
bb tasks threads SC-2then showed only the live thread.Fixes #1761
Independent verification
Verified on a fresh worktree at
4db9a918b(branch is directly on top oforigin/mainf6fb434ab;git merge-base --is-ancestor origin/main HEADexit 0).Commands:
pnpm install --frozen-lockfile --prefer-offline && pnpm exec turbo run build->Tasks: 18 successful, 18 totalgit checkout origin/main -- plugins/tasks/cli/index.ts plugins/tasks/db/store.ts plugins/tasks/delegate/contract.ts plugins/tasks/delegate/index.ts plugins/tasks/views/detail/index.tsx plugins/tasks/views/detail/threads.tsx, then fromplugins/tasks:pnpm exec vitest run db.test.ts delegate/delegate.test.ts cli/cli.test.ts views/detail/threads.test.tsx -t "live task threads before terminal|taskThreadsDetach|bb tasks detach|detaches a thread from its card"->4 failed:AssertionError: expected [ 'thr_dead_first', …(3) ] to deeply equal [ Array(4) ](receivedthr_dead_firstfirst, expectedthr_live_new)Error: plugin "tasks" has no rpc method "taskThreadsDetach"(code: 'unknown_method')AssertionError: expected 'Usage: bb tasks <command> [options]\n…' to contain 'detach …'TestingLibraryElementError: Unable to find role="button" and name "Detach Worker"git checkout HEAD -- <same files>(tree clean), same vitest command ->4 passed.pnpm exec turbo run typecheck --filter=bb-plugin-tasks --filter=@bb/templates --filter=@bb/server --filter=@bb/cli->Tasks: 8 successful, 8 totalpnpm exec turbo run test --filter=bb-plugin-tasks --filter=@bb/cli --force->Tasks: 7 successful, 7 total(tasks 35 files / 363 tests, cli 48 files / 453 tests)Repro of the issue on the fixed branch (own dev instance,
builtin:tasksinstalled from this branch, codex thread with a bogus model ->error, then a real idle thread; both attached to SC-1 dead-first):Headless Chrome (doobie) on the SC-2 task page: the Idle card renders above the Failed card although it was attached later; each card has an
aria-label="Detach <title>"X control; clicking it opens the "Detach thread?" ConfirmDialog; confirming callstaskThreadsDetachand the Failed card disappears, confirmed bybb tasks threads SC-2afterwards.Review notes: fixes the root cause (ordering query plus the missing inverse at RPC/CLI/UI), plugin-internal so no
HOST_DAEMON_PROTOCOL_VERSIONchange is needed, no casts, no accepted-but-ignored fields, doc surfaces perdocs/cli-guide-and-skill.mdupdated. No consumer oflistTaskThreadsdepends on chronological order (PR resolution dedupes by URL; board/list meta filter by status; mentions just format). Reuses the plugin's existingConfirmDialoganduseRpc<DelegationRpcContract>patterns.CI: all checks green (
gh pr checks 2167: Checks, Package Smoke x2, Tests app-1/2/3, integration, packages, server all pass).Residual risks: a row reconciled into
completed/failedmoves down the list on the next refetch (cosmetic; lists are short). Re-attaching does not refreshattached_at. A reconcile tick in flight when a row is detached throwsTask thread not foundinsidetransitionThread; it is caught and logged as a warning and creates no comment. No in-app undo for detach; the dialog points atbb tasks attach.