#5641 · Foreground shell work enters the background-task lifecycle
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for the task misclassification. Reproduction label: partial-repro.
1. TL;DR
The trusted Claude provider emits an extra background-task item for a foreground Bash call. A hermetic test exercises the real translator and event assembler, not a replacement implementation, and reproduces this with both missing background metadata and explicit foreground metadata. The task type is treated as proof of background execution even though the existing command item is already running. This explains the misleading background presentation; it does not prove the reported multi-minute steer delay. No live provider session or browser was used, so SDK command scheduling and the visual appearance remain unverified.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| A foreground Bash call receives a background-task item. | Verified | Two cases fail in each of two trusted-base checkouts: omitted metadata and is_backgrounded: false. Both receive item/started with item.type: backgroundTask. |
| The item is described as background work. | Verified at event boundary | The received presentation label is Running background command. No screenshot or app-render claim is made. |
| A real long-running foreground invocation emits this SDK message sequence. | Unverified live | The sequence is synthesized from trusted code and the installed SDK contract. A provider process was not launched. |
| A steer is held until the shell finishes. | Unverified timing | The SDK input queue is consistent with deferred delivery, but no command/steer timing experiment ran. |
| A backgrounding control is possible through the SDK. | SDK surface verified only | The installed, lockfile-resolved SDK exposes Query.backgroundTasks(toolUseId?). BB's SDK session wrapper has no corresponding call. Wiring new UI/SDK/CLI controls is outside a provider-local repair. |
3. Environment
- Public target repository:
get-bb/bb. Trusted base:98ea40bb6de42bd5020423aed02fccc64c233b6a, BB0.46.1. - Linux
4.19.0-gvisor, x86_64; Node22.19.0; pnpm9.15.0; Vitest4.1.1. - Provider plugin
bb-plugin-provider-claude-code0.1.0;@anthropic-ai/claude-agent-sdkinstalled as0.3.245. No external Claude executable was invoked. - Two separate temporary Git worktrees at the same base, separately frozen-installed dependencies. No server ports, browser, production store, database, or real runtime data were used.
- The first checkout completed the normal full Turbo build:
67 successful, 67 total. The second completed the filtered upstream build:6 successful, 6 total.
4. Minimal reproduction
- Clone the trusted repository and check out the recorded base.
- Install and build with the frozen lockfile.
- Save the complete inline test in this report as
plugins/provider-claude-code/src/issue-5641.repro.test.ts. - Run the exact command below. The test does not execute
sleep; it translates a tool-use record and a task-start record.
git clone https://github.com/get-bb/bb.git bb-repro cd bb-repro git checkout 98ea40bb6de42bd5020423aed02fccc64c233b6a pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build cp /path/to/issue-5641.repro.test.ts plugins/provider-claude-code/src/ pnpm exec turbo run test --filter=bb-plugin-provider-claude-code -- --run src/issue-5641.repro.test.ts
Expected: The original commandExecution item starts, and the subsequent foreground task message produces no background item. Both regression cases pass.
Actual: Both cases fail with an extra background item. Relevant verbatim assertion output:
bb-plugin-provider-claude-code:test: AssertionError: expected [ { type: 'item/started', …(4) } ] to deeply equal []
bb-plugin-provider-claude-code:test:
bb-plugin-provider-claude-code:test: - Expected
bb-plugin-provider-claude-code:test: + Received
bb-plugin-provider-claude-code:test:
bb-plugin-provider-claude-code:test: - []
bb-plugin-provider-claude-code:test: + [
bb-plugin-provider-claude-code:test: + {
bb-plugin-provider-claude-code:test: + "item": {
bb-plugin-provider-claude-code:test: + "description": "Wait for completion",
bb-plugin-provider-claude-code:test: + "familyId": "shell-task",
bb-plugin-provider-claude-code:test: + "id": "cl-test-i2",
bb-plugin-provider-claude-code:test: + "parentToolCallId": "cl-test-i1",
bb-plugin-provider-claude-code:test: + "presentation": {
bb-plugin-provider-claude-code:test: + "icon": {
bb-plugin-provider-claude-code:test: + "glyph": "Terminal",
bb-plugin-provider-claude-code:test: + },
bb-plugin-provider-claude-code:test: + "label": {
bb-plugin-provider-claude-code:test: + "completed": "Background command finished",
bb-plugin-provider-claude-code:test: + "pending": "Running background command",
bb-plugin-provider-claude-code:test: + },
bb-plugin-provider-claude-code:test: + "title": "Wait for completion",
bb-plugin-provider-claude-code:test: + },
bb-plugin-provider-claude-code:test: + "skipTranscript": false,
bb-plugin-provider-claude-code:test: + "status": "pending",
bb-plugin-provider-claude-code:test: + "taskStatus": "running",
bb-plugin-provider-claude-code:test: + "taskType": "local_bash",
bb-plugin-provider-claude-code:test: + "type": "backgroundTask",
bb-plugin-provider-claude-code:test: + },
bb-plugin-provider-claude-code:test: + "providerThreadId": "",
bb-plugin-provider-claude-code:test: + "scope": {
bb-plugin-provider-claude-code:test: + "kind": "turn",
bb-plugin-provider-claude-code:test: + "turnId": "cl-test-t1",
bb-plugin-provider-claude-code:test: + },
bb-plugin-provider-claude-code:test: + "threadId": "",
bb-plugin-provider-claude-code:test: + "type": "item/started",
bb-plugin-provider-claude-code:test: + },
bb-plugin-provider-claude-code:test: + ]
bb-plugin-provider-claude-code:test:
Both runs finish with Tests 2 failed (2) and exit code 1. The reproducible evidence is inline; raw logs remain outside this public repository.
Complete test
import { expect, it } from "vitest";
import {
createClaudeDeltaHarness,
spawningToolUseMessage,
} from "./delta-test-harness.js";
it.each([{}, { is_backgrounded: false }])(
"does not open a background lifecycle for a foreground shell task (%j)",
(taskMetadata) => {
const harness = createClaudeDeltaHarness();
const context = { threadId: "foreground-reproduction" };
const command = harness.translate(
spawningToolUseMessage({
toolUseId: "shell-tool",
toolName: "Bash",
input: { command: "sleep 60" },
}),
context,
);
expect(command).toContainEqual(
expect.objectContaining({
type: "item/started",
item: expect.objectContaining({ type: "commandExecution" }),
}),
);
const events = harness.translate(
{
type: "system",
subtype: "task_started",
task_id: "shell-task",
tool_use_id: "shell-tool",
task_type: "local_bash",
description: "Wait for completion",
...taskMetadata,
},
context,
);
expect(
events.filter(
(event) =>
event.type === "item/started" && event.item.type === "backgroundTask",
),
).toEqual([]);
},
);
5. Root cause
isMaterializedTaskType accepts every local_bash task. The task-start handler checks whether the spawning tool was forwarded, but never consults its execution mode. It creates a tracked task and immediately opens an item. buildClaudeTaskShape hardcodes type: backgroundTask, and the presentation factory hardcodes the background label.
task_type: local_bash → admitted regardless of foreground/background state → buildClaudeTaskShape(...): type = backgroundTask → presentation.label.pending = Running background command
The task-start schema passes through unrecognized fields but does not type is_backgrounded. The existing Bash argument parser already derives run_in_background, but that information is not passed into task translation. The installed SDK distinguishes foreground from background at task start and reports later transitions via task_updated.patch.is_backgrounded. A repair must preserve both explicit background work and later promotion rather than discarding all shell tasks.
Separately, SdkSession.pushInput resolves its consumed promise only when the SDK asks for the message. That can explain waiting, but it is not live evidence of this issue's particular delay. Correcting classification does not make a foreground tool interruptible.
6. Proposed fix and autopilot decision
Parse the SDK foreground/background signal, fall back to the original Bash background flag only when metadata is absent, and retain foreground task state without emitting background items. Materialize a background lifecycle if an update explicitly backgrounds that task. Preserve the ordinary command item and its inline completion; suppress hidden-task progress, completion, and interruption events.
A local candidate does this in the existing Claude provider subsystem: 4 text files; 201 additions + 17 deletions = 218 changed lines. No dependencies, generated files, migrations, stored data, public protocol, or UI/SDK/CLI surface changes. The candidate is retained locally only, not shipped or published as a patch.
The expanded task test has 4 failed / 20 passed before in both trusted-base worktrees and 24 passed after. Typecheck and lint pass. The entire provider suite after the candidate has 5 failed / 387 passed, and untouched trusted main has the same five failures / 382 passed. The failures concern install-location fallback, two Plan sandbox cases, and permission refresh on start/steer, all in src/bridge/__tests__/bridge.test.ts.
No PR opened. The conservative automatic-fix gate requires a green relevant provider suite; that condition is not met in this environment. The candidate was not committed or pushed. Unrelated baseline failures were not modified. Composer queue/stop copy and a backgrounding action also remain separate product work; this candidate does not implement them.
7. Verification
The same agent repeated the reproduction in a second clean detached worktree at 98ea40bb6de42bd5020423aed02fccc64c233b6a, not an independent reviewer. Before adding tests, production source matched that commit. Dependencies were installed separately with the frozen lockfile; the provider's upstream build was run through Turbo. Both the expanded regression and the smaller standalone test were copied without any production change.
| Run | Command/result |
|---|---|
| First trusted-base checkout | turbo run test --filter=bb-plugin-provider-claude-code -- --run src/issue-5641.repro.test.ts: 2 failed; exit 1. |
| Second clean trusted-base checkout | The same command: 2 failed; exit 1; same unexpected background item and presentation. |
| Expanded regression, before | --run src/task-translation.test.ts: 4 failed, 20 passed in each checkout. |
| Local candidate, after | Task suite: 24 passed. Broader provider: 25 files passed, one failed, five pre-existing failures. Typecheck and lint passed. |
| Untouched main baseline | Provider suite: same one failed file and five failures; 382 passed. |
During test authoring, an initial assertion incorrectly used the dialect name command instead of the assembled event type commandExecution. It was corrected before the final before/after runs. The saved logs and report use the corrected test and fail at the intended background-task assertion. This does not alter the final root-cause finding.
No visual screenshot, live steer latency, or installed-client behavior is claimed. These limits are why the overall verdict is partial even though the translator defect is reproduced twice with high confidence.
8. Related issues and PR search
GitHub timeline cross-reference metadata and an open-PR search for issue 5641 found no linked open PR at investigation time. No linked branch or untrusted patch was executed. The repository search also found #5481, a distinct task-card lifecycle report, and #3709, a command-title feature request; neither establishes the foreground scheduling behavior tested here.
9. Appendix
Additional verification commands, run from the owning checkout root:
pnpm exec turbo run test --filter=bb-plugin-provider-claude-code -- --run src/task-translation.test.ts pnpm exec turbo run test typecheck lint --filter=bb-plugin-provider-claude-code git diff --check git diff --numstat origin/main pnpm exec turbo run test --filter=bb-plugin-provider-claude-code
The final command was repeated in untouched trusted main to distinguish pre-existing suite failures from candidate regressions. Verbatim final test summaries:
Expanded task regression, before (both checkouts):
Test Files 1 failed (1)
Tests 4 failed | 20 passed (24)
Candidate provider suite:
Test Files 1 failed | 25 passed (26)
Tests 5 failed | 387 passed (392)
Untouched main provider suite:
Test Files 1 failed | 25 passed (26)
Tests 5 failed | 382 passed (387)
Candidate lint:
Found 0 warnings and 0 errors.
Full trusted-base build:
Tasks: 67 successful, 67 total
The five failing test cases in both complete-suite runs were:
falls back to well-known install locations when PATH discovery fails prepares the 'full' sandbox before approving a Plan preset (undefined, undefined) prepares the 'full' sandbox before approving a Plan preset (true, undefined) refreshes permissions before turn/start and preserves the conversation refreshes permissions before turn/steer and preserves the conversation
Raw logs, the filled investigation brief, and the stopped candidate diff are retained locally outside the public reports repository.
Issue content was treated as untrusted hypotheses. All executed production code came from the trusted target main commit or a locally authored candidate based on repository evidence. No issue-provided script, linked pull-request branch, external attachment, private runtime, or credential was used.
AGENT GENERATED