Skip to content

Stop a single background command from the thread banner, CLI and SDK - #8158

Open
ymichael wants to merge 4 commits into
mainfrom
bb/6553-stop-a-single-background-command-from-the-t-thr_eig6ijdgpg
Open

ymichael wants to merge 4 commits into
mainfrom
bb/6553-stop-a-single-background-command-from-the-t-thr_eig6ijdgpg

Conversation

@ymichael

@ymichael ymichael commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The background-command banner showed what was running and for how long, but nothing could stop one command; the only option was stopping the whole turn (#6553). No layer had a per-task stop: the provider bridge protocol, host daemon, server API, SDK and CLI could only interrupt a turn. Codex was also missing from the banner entirely: it keeps a command running after its turn ends as a background terminal, but bb never turned that into a background task, so Codex threads showed no banner and background-tasks list was empty.

What changed

One stop path, used by the banner, the CLI and the SDK:

  • Provider bridge protocol: a pending backgroundTask the provider can stop carries stoppable: true. The runtime sends thread/backgroundTask/stop {threadId, providerThreadId, familyId} only for items carrying that flag, so the flag is the capability and there is no handshake field. The provider settles the item through its normal notification with taskStatus: "stopped".

  • Host daemon: new thread.background_task.stop {environmentId, threadId, itemId} command returning {stopped}. HOST_DAEMON_PROTOCOL_VERSION 284 → 285. It never wakes a sleeping host.

  • Server / public API: GET /threads/:id/background-tasks and POST /threads/:id/background-tasks/:itemId/stop. Returns 404 if the task isn't running, 409 if the provider can't stop it, and 404 if it finished while the request was in flight.

  • SDK: bb.sdk.threads.experimental_backgroundTasks.{list, stop}, with an entry in docs/api_to_audit.md. The app's Stop button calls the same SDK method.

  • CLI: bb thread background-tasks list [id] and bb thread background-tasks stop <task-id> [id].

  • App: a Stop button on each stoppable row of the background-command banner.

  • Claude Code: running tasks are marked stoppable; stop calls the Claude SDK's query.stopTask(taskId).

  • Codex: every command still running when its turn completes becomes a stoppable local_bash background task, linked to its command row, and it settles when Codex reports the command finished. Stop calls Codex's thread/backgroundTerminals/terminate. A stopped command settles as interrupted, without Codex's -1 killed exit code, and its task settles as stopped.

  • Plugin SDK bumped to 0.6.203. The thread-lifecycle guide, CLI command index, plugin-authoring reference, provider docs and the verify-bb feature map are updated.

  • Timeline: a tool row whose background task is still running stays running when its turn settles. Before, the timeline marked every tool row still open at turn end as "interrupted" (interruptPendingToolMessages), so a Codex command still running after its turn read "interrupted" while the banner said it was running.

  • Dangling settlement: when the server force-settles a background task (daemon restart, lost or removed host), it now also completes the task's still-open command as interrupted, with the output it had streamed as aggregatedOutput. Resolved-item pruning then removes the per-chunk output rows; before, a Codex command killed by a daemon restart kept one event row per output chunk forever. This adds two queries on existing indexes, listOpenCommandItemRowsByItemIds and listCommandOutputDeltaTexts, each with query-cost cases.

Stopping a task does not end the turn, interrupt the agent or start a new turn.

Not in this PR:

How you verified

  • New tests:
    • agent-runtime: stops one background task through the provider and leaves the thread running.
    • Claude bridge: stops one background command through the Claude SDK; task translation marks only unsettled tasks stoppable.
    • Codex translation: a command still running at turn end opens a stoppable task; the task settles on natural exit, on stop, and on a withdrawn stop; commands that finish inside their turn are never treated as background.
    • Codex bridge against the fake app-server: terminate is called with the right process id, and a second stop is refused.
    • Server public API: list, stop, the 409/404 refusals, and the daemon returning stopped: false.
    • Server reconciliation: settling a dangling task completes its still-open command as interrupted with its streamed output, exactly once.
    • Timeline: a command whose background task outlives the turn stays pending, and becomes interrupted once the task is stopped. This test fails without the fix.
    • App: background-command card offers Stop only on stoppable rows and stops that row.
    • Contract and grammar snapshot tests.
  • pnpm exec turbo run typecheck lint --filter='...[origin/main]' (167 tasks), check:query-costs for @bb/db, and tests for host-daemon-contract, agent-runtime, sdk, thread-view, both provider plugins and the server background-task suites pass. The full server and app suites passed before the rebase.
  • Manual end-to-end on a pnpm start:worktree instance:
    • Claude Code: two background shells. Stopped one from the banner and one with bb thread background-tasks stop. Only the targeted shell process died, the thread stayed idle with no new turn, and a repeat stop returned 404. Also tapped Stop on a mobile viewport.
    • Codex (codex-cli 0.171): two background shells. The banner appeared, and stopping from the CLI and from the banner each killed only the targeted process. Stored events show the command interrupted and the task item/backgroundTask/completed with taskStatus: "stopped". Before this change, the same Codex thread showed no banner.
    • Codex running label: with both commands running after the turn, the turn reads "Ran 2 commands" with no "interrupted" (before: "2 interrupted"). After stopping one it reads "1 interrupted".
    • Codex daemon restart: restarted the dev server under two running Codex commands. Both commands got an interrupted completion carrying their output (4.2k and 4.6k chars), both tasks settled as stopped, and pruning removed all ~860 output-chunk rows.

Fixes #6553

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 4 commits November 24, 2026 20:23
The background-commands card above the composer showed a running command
and its timer with no way to stop it. The only stop was a whole-thread
stop, which ends every task and the provider session. Nothing in bb
called the Claude Agent SDK's per-task `stopTask`.

The Claude Code bridge now marks each running background task
`stoppable: true` on the backgroundTask item and handles a new bridge
request, `thread/backgroundTask/stop {threadId, providerThreadId,
familyId}`, with `query.stopTask(familyId)`. The task then settles
through Claude's normal stopped notification. The item flag is the
capability: providers that cannot stop one task omit it and core hides
the control.

- Runtime: `stopBackgroundTask({threadId, itemId})` resolves the bb item
  to the provider task id from its open-work state and refuses tasks the
  bridge did not mark stoppable.
- Daemon: new `thread.background_task.stop` command
  (HOST_DAEMON_PROTOCOL_VERSION 283 -> 284).
- Server: `GET /threads/:id/background-tasks` lists running tasks with
  `stoppable`; `POST /threads/:id/background-tasks/:itemId/stop` stops
  one (409 not stoppable, 404 not running).
- SDK: `threads.experimental_backgroundTasks.list/stop` (audit entry in
  docs/api_to_audit.md). CLI: `bb thread background-tasks list|stop`.
- UI: the card's rows carry a Stop button that calls the same SDK path;
  the timeline row gains `stoppable`.

Plugin SDK 0.6.202 -> 0.6.203 for the new provider-bridge export.

Refs #6553

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex keeps a command running after its turn ends as a background
terminal, but bb never surfaced it, so the background-command banner
stayed empty and there was no way to stop one.

The Codex plugin now opens a stoppable backgroundTask for every command
still running when its turn completes and settles it when Codex reports
the command finished. thread/backgroundTask/stop maps the task to its
Codex process and calls thread/backgroundTerminals/terminate; a stopped
command settles as interrupted and its task as stopped.

Refs #6553

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut when it is force-stopped

A Codex command that keeps running after its turn ends was labelled
"interrupted" in the turn, because the timeline interrupts every tool row
still open when its turn settles. A tool row whose background task is
still running now stays running until the task or the provider settles it.

When the server force-settles a dangling background task (daemon restart,
lost or removed host), its command row could stay open forever with every
output chunk stored as its own event. The server now completes that command
as interrupted with the output it streamed, so resolved-item pruning folds
the per-chunk rows away.

Refs #6553

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Stop a single background command from the thread UI

1 participant