Repository navigation
Conversation
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 <[email protected]>
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 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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 <[email protected]>
A Codex background command now keeps running after its turn, so its output keeps extending the settled turn's source range. Each new range changed the turn-details query key, the body fell back to "Loading turn details..." and remounted, and any group the user had expanded inside it collapsed again about once a second. The details query now keeps the previous rows for the same turn while the new range loads. Refs #6553 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #8158 found a Codex background task that stayed listed and stoppable after its process was gone: - When the Codex app-server crashed, or Codex closed the thread, the bridge forgot its running commands without closing them. It now closes each one (command interrupted, task stopped) through the same exit cleanup that already closes sub-agent rows. - When Codex answered that it had no terminal to terminate, the bridge reported success and the task never cleared. It now settles that task. - Commands still running when a turn ends by interrupt no longer become background tasks: Codex kills them and reports them finished right away, so the task only flickered open and changed the codex/stop-interrupt replay. The claude-code/subagent parity recording is re-recorded for the new stoppable flag on running tasks. Refs #6553 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With more than one command running, the banner header showed the newest
command and a count, and its stop button sat in the header. That command's
duration never appeared anywhere, and every row ended in a solid square
that read as a checkbox (the button's icon-size rule also overrode the
intended 12px, so it rendered at 16px).
- With several commands, the header is now a summary ("Running 3
background commands"). Collapsed on a wide card it adds the newest
command's name; expanded, every command, the newest included, is a row
in the drawer, as on mobile.
- Each row ends in "duration · Stop". Stop is a muted text link that turns
red on hover, with an enlarged tap area, and appears only on commands the
provider can stop.
- A single command on a wide card stays one header line with its own
"duration · Stop".
Refs #6553
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 25, 2026
) ## Human comments ## What was wrong Since #8068 graduated `agentCpuPriority` (merged 2026-11-24 04:53 UTC), `deprioritizeAgentWorkload` renices every provider process to nice 10 unconditionally. Before that it was a no-op unless the daemon turned it on, so `@bb/agent-runtime` test bridges ran at the Vitest worker's priority. Now each bridge a test spawns runs below the nice-0 Vitest workers. On a contended 4-vCPU Linux runner (turbo runs four suites at once), the bridges get a small share of CPU, so bridge startup and exit take seconds and tests with wall-clock bounds fail. macOS ignores nice across processes, so this never reproduces locally. In the failing run for #8158 ([run 45680230926, attempt 1](https://github.com/get-bb/bb/actions/runs/45680230926/job/139438721951)), every bridge-spawning test near the start of both files took 8–12 s; they normally take 0.2–2 s: - `uses the construction deadline for thread/'resume' (requestTimeoutMs=undefined)` hit the 15 s test timeout. Its siblings took 10.3 s and 8.3 s. - `fires onProcessExit when provider crashes` spent about 10 s in `ensureProvider`. It then gave the exit callback only the `waitForRuntimeState` default of 1 s. That window has to cover the bridge's `process.exit` plus the `close` event, which the runtime itself allows up to `PROVIDER_PROCESS_CLOSE_GRACE_MS` (1 s) to report. Main CI has hit the same problem. Of the 60 most recent failed main CI runs (Nov 16–25), the 49 before Nov 24 had no `@bb/agent-runtime` failures. On Nov 24, 7 of 10 failed main runs were `runtime.process-lifecycle.test.ts` tests timing out at 15 s on Linux: `ranks provider processes ahead of bb for the out-of-memory killer` (4 runs), `keeps an old-hash bridge process that still owns a thread` (3), `retires a threadless bridge process superseded by a new artifact hash`, and `waits for provider retirement before starting a same-key replacement`. The two tests named above did not appear in that scan. ## What changed - `packages/agent-runtime/src/test/keep-provider-process-priority.ts`, registered as a Vitest `setupFiles` entry, stubs `deprioritizeAgentWorkload` from `@bb/process-utils`. Test bridges now run at the worker's priority, as they did before #8068. Production renicing is unchanged. No agent-runtime test asserts nice values; `@bb/process-utils` keeps its own `workload-priority` test. - `fires onProcessExit when provider crashes` now awaits the `onProcessExit` callback instead of polling it against a 1 s deadline, and asserts it fired once. The construction-deadline test is unchanged. With bridges back at normal priority it runs in about 1.7 s. Its 1.5 s scripted response delay is what lets it tell the 120 s construction deadline from the 30 s request default, and that delay was not part of the failure. ## How you verified I reproduced this on Linux in an OrbStack `node:22-bookworm` container pinned to 4 CPUs (`--cpuset-cpus=0-3 --init`), with nice-0 busy-loop burners standing in for the other suites. At 6 burners, a nice-10 CPU job ran 5.3× slower than the same job at nice 0. | load | renice on (main) | renice off / this PR | | --- | --- | --- | | 6 burners, 7 runtime test files, ×2 | 122/122 pass, tests 118 s | 122/122 pass, tests 41 s | | 12 burners, same files, ×2 | 2 failed each run (`command-contract` real-time tests), tests 222–231 s | 122/122 pass, tests 57 s | | 64 burners, the target tests, ×2 | pass, at CI-like timings: `fires onProcessExit` 5.7–7.2 s, construction tests 7.5–9.5 s | 0.7–2.8 s | | 110 burners, the target tests | all 5 fail: `The bridge never received thread/start` / `thread/resume`, and 15 s timeouts for `fires onProcessExit` and `handles JSON-RPC error responses` | pass, ×2 runs on this PR's code | - With renice on at 110 burners, the time from `ensureProvider` resolving to `onProcessExit` firing was 484 ms in one run and 1762 ms in another. The second would fail the old 1 s wait. With renice off at 110 burners it was 175 ms. - A temporary probe confirmed the stub works on Linux: a spawned provider ran at nice 0 with the setup file and nice 10 without it. - With this PR on Linux at 12 burners: 305/305 passed. That run skipped `runtime.codex-topology` and `runtime.skill-roots-capability`, which need plugin packages the container's filtered install did not have. - Locally: `pnpm exec turbo run typecheck lint --filter=@bb/agent-runtime` passed, and `pnpm exec turbo run test --filter=@bb/agent-runtime` passed: 23 files, 316 passed, 1 skipped (the Linux-only OOM test). Not changed here: `apps/host-daemon` lifecycle scripts get the same nice-10 renice, and other `runtime.process-lifecycle` tests still poll exit callbacks with the 1 s default. Both are the same kind of issue, but neither failed in the runs above once bridges were back at normal priority. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/6553-stop-a-single-background-command-from-the-t-thr_eig6ijdgpg
branch
November 25, 2026 21:42
ymichael
added a commit
that referenced
this pull request
Nov 26, 2026
…n needs them (#8203) ## Human comments ## What was wrong #8152 was squash-merged from its first commit only. The three follow-up commits on the branch were never pushed, so two load-order fixes for lazy plugin parts did not land: - A lazy chunk's shim waits for its host-loaded runtime slots, such as the 556 KB diff viewer, before the chunk evaluates. That wait only starts once the chunk has downloaded. So reloading a thread with Git's Diff tab open fetched the chunk and then the diff viewer, one after the other. - A lazy part only started loading when its host rendered it or at idle warming. The restored Diff tab requested its chunk about a second after Git's code had run. A plugin's own page also waited for every lazy part of that plugin, including parts the page does not show. ## What changed - **Chunk downloads start their slots too.** `bb plugin build` (`packages/plugin-build/src/build-plugin-app.ts`) rewrites each dynamic import of a chunk to call `loadRuntimeSlot` for the host-loaded slots in that chunk's static import closure that the entry does not already load. The chunk and its slots download together, and the shim's own call joins the pending load. `HOST_LOADED_RUNTIME_SLOTS` in `runtime-shims.mjs` lists those slots. - **The restored screen's lazy parts start early.** `apps/app/src/lib/restored-lazy-parts.ts` lists, before plugin frontends load, the parts the restored screen shows: - a plugin's settings sections on its settings page - its nav panel on its own page - on a thread route, the open right-panel tab from the thread's saved panel state: a plugin tab, a plugin panel action, or every plugin's Info rows and sections A plugin that a listed part names prefetches its lazy chunks with its entry. Its listed parts start loading as soon as its registrations are collected. Only a plugin's own page or settings page holds its publish, and only for the parts that page shows, with the same 3-second limit. This replaces the old page-owner rule. - **Boot stays small.** Boot works out the settings-page and plugin-page parts synchronously with `restoredPageLazyParts`, which only matches the route. `readStoredPanelTabs` moves into `fixed-panel-tabs-state.ts`, so client-core's panel-state parser stays out of boot. Thread-panel parts start when the plugin loader runs. Boot is 417.1 KB brotli, against 416.5 KB on main. - **Doc comment fix.** `PluginSdkApp`'s doc comment moves back onto `PluginSdkApp`. It had attached itself to `ExperimentalLazyComponent`. - **SDK version bump to 0.6.204.** `app-contract.ts` changes here, and #8152 and #8158 both shipped 0.6.203. - **Docs.** `docs/ui-code-splitting.md` and the `experimental_lazy` entry in `docs/api_to_audit.md` describe the new behaviour. No wire, daemon-protocol or CLI changes. ## How you verified **Performance**, measured on `pnpm start:worktree` with the same data dir for both builds. Base is `65477919199` (#8152); after is this PR. Each run used headless Chromium at 1440×900 with an empty cache and a localStorage snapshot from a returning user (Git remembered as the panel-tab provider). Slow 4G is CDP at 562.5 ms RTT and 1.44 Mbps. Values are medians of 5 runs, and run-to-run spread was under 0.15 s on Slow 4G. | Scenario | Base | After | | --- | --- | --- | | Reload a thread with the Diff tab open, Slow 4G: diff visible | 27.41 s | 27.14 s | | Same: Diff tab chunk starts / diff viewer starts | 14.05 s / 19.00 s | 10.13 s / 10.81 s | | Same, unthrottled: diff visible | 539 ms | 503 ms | | Cold thread load, composer visible: Slow 4G / unthrottled | 11.15 s / 283 ms | 11.16 s / 253 ms | | Reload onto bb connect settings, Slow 4G | 13.14 s | 13.11 s | | Reload onto the automations page, Slow 4G | 11.74 s | 11.74 s | The Diff tab's code now arrives about 8 s earlier on Slow 4G, but the diff shows only 0.27 s sooner. What holds it back is Git's RPC chain: `status` runs twice in a row, each 432-byte response takes 4.5–7 s on the shared link, and then `files` and `fileSide` follow. An earlier version of this PR loaded the restored-part check with a dynamic import. That put it inside the 157 KB plugin-frontend chunk, which delayed bb connect's settings by 0.9 s on Slow 4G (14.03 s). The current version measures at 13.11 s. - `pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/plugin-build --filter=@get-bb/plugin-sdk --filter=@bb/server` passes. - `pnpm exec turbo run test --filter=@bb/plugin-build --filter=@get-bb/plugin-sdk` passes. That includes the new `build-plugin-app.test.ts` cases for the slot preloads that dynamic imports start. - `pnpm exec turbo run test --filter=@bb/app` passes: 711 files, 7,526 tests. That includes the new `restored-lazy-parts.test.ts` and the updated `plugin-frontend-load-order.test.ts`. - `node .github/workflows/check-plugin-sdk-version.mjs` passes. - `node apps/app/scripts/check-bundle-budget.mjs` passes after a local `turbo run build --filter=@bb/app`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[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.
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 listwas empty.What changed
One stop path, used by the banner, the CLI and the SDK:
Provider bridge protocol: a pending
backgroundTaskthe provider can stop carriesstoppable: true. The runtime sendsthread/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 withtaskStatus: "stopped".Host daemon: new
thread.background_task.stop {environmentId, threadId, itemId}command returning{stopped}.HOST_DAEMON_PROTOCOL_VERSION284 → 285. It never wakes a sleeping host.Server / public API:
GET /threads/:id/background-tasksandPOST /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 indocs/api_to_audit.md. The app's Stop button calls the same SDK method.CLI:
bb thread background-tasks list [id]andbb thread background-tasks stop <task-id> [id].App: the background-command banner lists every running command as a row ending in "duration · Stop". Stop is a muted text link that turns red on hover, and it appears only on commands the provider can stop. With several commands, the header is a summary ("Running 3 background commands"); collapsed on a wide card it adds the newest command's name. Before, the header showed the newest command without its duration, so that duration appeared nowhere. A single command on a wide card stays one header line with its own "duration · Stop".
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_bashbackground task, linked to its command row, and it settles when Codex reports the command finished. Stop calls Codex'sthread/backgroundTerminals/terminate. A stopped command settles as interrupted, without Codex's-1killed exit code, and its task settles as stopped.claude-code/subagentparity recording re-recorded (pnpm --filter @bb/provider-parity rerecord --provider claude-code --cell subagent). The diff is the newstoppable: trueon running tasks, plus output the current Claude bridge already produces and a fresh random provider thread id.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,listOpenCommandItemRowsByItemIdsandlistCommandOutputDeltaTexts, each with query-cost cases.Codex background tasks never outlive their process:
Turn details stay put: a running Codex command keeps extending its finished turn's source range, so the turn-details query key changes with every output chunk. The details query now keeps the previous rows for the same turn while the next range loads (
placeholderData). Before, the body fell back to "Loading turn details..." and collapsed any group the user had opened inside it about once a second.Side effect worth knowing: because Codex background commands are now open background tasks, the daemon's idle-session reaper keeps their Codex session alive, as it already does for Claude. On main, the reaper closed the idle Codex session a few minutes after the turn, which killed those commands without bb ever showing them.
Stopping a task does not end the turn, interrupt the agent or start a new turn.
Not in this PR:
thread/backgroundTerminals/terminate: requires Codex 0.140+. Older Codex versions show the "Failed to stop background task." toast.How you verified
stopped: false.pnpm exec turbo run typecheck lint --filter='...[origin/main]'(167 tasks),check:query-costsfor@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.pnpm start:worktreeinstance: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.interruptedand the taskitem/backgroundTask/completedwithtaskStatus: "stopped". Before this change, the same Codex thread showed no banner.d270fc361bcit collapsed every second.codex app-serverunder two running background commands. Both shells died; both commands closed as interrupted and both tasks as stopped;background-tasks listreturned empty. Before the fix the tasks stayed listed and Stop failed with a 502.bb thread stop. No background-task events were written and the shell was gone.Fixes #6553
🤖 Generated with Claude Code