fix(server): a Claude steer no longer waits behind a running foreground command #36170
main fromrefs/pull/36170/head·opened View on GitHubProblem#
A steer sent to a Claude thread while the agent runs a long foreground Bash command is not read until the command ends. The adapter offers the steer with priority: "now", but Claude Code holds a "now" message behind a foreground Bash call (only WebFetch and WebSearch step aside for it). I hit this daily: the agent started a long render, I sent a follow-up nearly 4 minutes in, and the thread said nothing for 6 more minutes, until the command reached its 600 s timeout and the CLI moved it to the background by itself. Only then did the agent answer.
Steps: Follow-up behavior = Steer. Ask Claude to run a foreground command that takes 2 minutes. While it runs, send "Reply with only the word PONG." Expected: an answer in seconds, with the command still running. Actual: the answer arrives only after the command finishes.
Change#
steerTurn already moves the turn's foreground subagents to the background with Query.backgroundTasks(toolUseId) before it offers the steer. It now does the same for the turn's running foreground commands (command_execution tool calls in the active turn's toolCalls). The SDK documents that request as backgrounding "in-flight foreground tasks (Bash commands and subagents)", the control-request version of the terminal's Ctrl+B. The tool call returns at once with "Command was manually backgrounded", the steer is read, and the command keeps running. Its task_notification reaches the session when it ends, and the adapter already handles a foreground command that moves to the background (the same path that shows the CLI's own timeout backgrounding).
This matches the terminal. In Claude Code 2.1.323, a message typed during a foreground command is queued behind it (T3's Queue). Its explicit send-now, ctrl+x ctrl+s, moves the shell to the background and the agent answers immediately with "1 shell still running". Steer is T3's send-now, so Queue keeps its current behavior and only Steer changes.
Nothing new is relied on: Query.backgroundTasks is the SDK method the subagent path already calls, so this needs no raw control-channel writes. When the move fails or is not answered within the existing 5 s budget, the steer goes out as before. Only root calls are moved; a subagent's commands move with the subagent.
Scope#
Fixes #15720 for Claude. This is the narrower version of #18641 ("background running commands when steering"), which was closed on Nov 12 in the backlog cleanup as stale, not rejected. It was rebuilt against main from Nov 13 as one function in ClaudeAdapterV2.ts, with no new state. The open question on #18641 was approval of the backgrounding default. The terminal's send-now answers it: it does exactly this.
Verification#
Live Claude: a dev server (vp run dev --home-dir <temp> --no-seed) with a real Claude Code 2.1.323 login, claude-haiku-5-5. A thread asked Claude to run python3 -c "import time; time.sleep(120); print('SLEEP_DONE')" in the foreground. 8 s into the command, a t3_thread_send with mode: "steer" (the same steer path the composer uses) said "Reply with only the word PONG."
| Steer sent | PONG | Command | |
|---|---|---|---|
| main (4aec277f79) | 12:27:52 | 12:29:46, 114 s later, after the command exited at 12:29:44 | foreground until it ended |
| this PR | 12:25:24 | about 2.3 s later | same PID kept running, exited at 12:27:09, then the agent reported SLEEP_DONE with exit code 0 |
Provider log of the PR run:
12:25:24.945 out query.background_tasks toolUseId=<the Bash call>
12:25:24.946 out prompt.offer priority=now <- the steer
12:25:25.099 in tool_result "Command was manually backgrounded by user with ID: ..."
12:25:27.201 in assistant "PONG"
12:27:08.080 in task_notification completed
The same check through the SDK alone, against the CLI with no T3 involved: with backgroundTasks(toolUseId) before a "now" message, backgroundTasks returned true and PONG arrived 1.6 s after sending, while the command finished in the background at 46 s. Without it, there was no answer until the command ended.
Tests: a new adapter case, moves a running foreground command to the background before a steer, starts a turn with a running Bash call and a running Read call and steers it. It asserts that only the Bash call is moved and that the move happens before the steer is offered. It fails on main (expected [] to deeply equal [ 'toolu-steer-render' ]) and passes here. vp run check:changed passes format, lint, knip, graphql and typecheck. In its tests, all of ClaudeAdapterV2.test.ts, ClaudeAutomaticDelivery, SteeringCompletion and BackgroundWorkStop pass (485 tests), except persists a todo_list from inline Claude task-tool frames. That one fails identically on unmodified main on my machine (ClaudeReplayFrameMismatchError at replay cursor 0), so it is unrelated.
Not checked: macOS and Windows, desktop and mobile clients (the change is server-only), and a session with CLAUDE_CODE_DISABLE_BACKGROUND_TASKS set, where the SDK throws and the steer goes out unchanged as before. I drove the steer through t3_thread_send rather than the web composer because the preview browser on this host is blocked by AppArmor. Both reach steerTurn the same way.
Written with Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code
- 1
MohamedTahaAmer(GitHub profile, opens in a new tab) linked this to fix #15720
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
No actionable comments were generated in the recent review.
Walkthrough
-
When a Claude turn is steered, the adapter backgrounds foreground command calls as well as eligible subagents before offering the steer. A test checks this ordering for a running Bash command.
Changes: Claude steer handling
Layer / File(s) Summary Background foreground work
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsThe adapter includes foreground commands in backgrounding work during a steer. It retains in-flight move reuse, records only subagent moves in the backgrounded-subagent registry, and logs distinct warnings for command and subagent move failures. The test checks that the running command is moved before the steer is offered. Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge,t3dotgg
Merge Risk:
Minimal · up to9bb55-
This change lets a Claude steer reach the agent right away instead of waiting behind a running foreground command, by moving that command to the background first. No concrete defect was established. One unverified detail remains: whether a moved command is tracked as background work afterward, which could matter if the session is later replaced.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the core change: a Claude steer no longer waits behind a running foreground command. The change backgrounds running foreground commands via Query.backgroundTasks before offering the st… Description check The description covers the problem, the change, scope, and verification in detail, and it follows the template's section structure. It links issue #15720and explains why the change is narrow. It also…Linked Issues check The only directly linked issue, #15720, is closed and completed. Under the assessment rules, it supplies historical context only. No active linked targets remain, so no linked-issue coding requirement…Out of Scope Changes check The change set has two files. ClaudeAdapterV2.ts: steerTurn moves running root foreground command_execution calls to the background with Query.backgroundTasks(toolUseId) before it offers a "now" steer… Full details: Title check
-
Explanation
The title names the core change: a Claude steer no longer waits behind a running foreground command. The change backgrounds running foreground commands via Query.backgroundTasks before offering the steer, which matches the title. The title follows the conventional commit form the template recommends.
Full details: Description check
-
Explanation
The description covers the problem, the change, scope, and verification in detail, and it follows the template's section structure. It links issue
#15720and explains why the change is narrow. It also states the model and harness used. The Scope section gives a reason for the change and the issue link, which the template requires. The description is complete and matches the changeset.
Full details: Linked Issues check
-
Explanation
The only directly linked issue,
#15720, is closed and completed. Under the assessment rules, it supplies historical context only. No active linked targets remain, so no linked-issue coding requirements apply. The PR summary shows that steerTurn in ClaudeAdapterV2.ts now calls backgroundTasks for running root command_execution calls before it offers a priority "now" steer. This matches the behavior#15720describes. The new test 'moves a running foreground command to the background before a steer' covers the change. The head moved from 16067a8 to 9bb55fe. The raw summary does not show what changed in that increment. The assessment relies on the whole-PR summary and the PR description. No direct diff hunks were inspected.
Full details: Out of Scope Changes check
-
Explanation
The change set has two files. ClaudeAdapterV2.ts: steerTurn moves running root foreground command_execution calls to the background with Query.backgroundTasks(toolUseId) before it offers a "now" steer. It reuses the per-tool-use move tracking that the subagent path already uses. Command and subagent move failures now log separate warnings. Subagent registry checks and backgrounded-task bookkeeping are retained. ClaudeAdapterV2.test.ts: adds one regression test for the command move. Both changes serve one goal: a steer reaches the agent while a foreground command runs. The PR description states that Queue behavior is unchanged. No unrelated change appears in the summary. Evidence limit: this result relies on the whole-PR summary and PR description. No diff hunks were inspected for the incremental change from 16067a8 to 9bb55fe.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 56fd98b
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
9049d430-7620-4cad-8216-810b59beb000
Commits-
Reviewing files that changed from the base of the PR and between 16067a8eb2446d77965cdd1add8de96a95d6fcb8 and 9bb55fe43c6b15203bb701d01b7554c9688ce60e.
Files selected for processing: 2-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
juliusmarminge added labelstakeover:in-progress
juliusmarminge added labelstakeover:needs-julius
juliusmarminge removed labelstakeover:in-progress
Hit this today on Claude Opus 5.5: steered at 14:57:55 UTC while the agent ran a 560 s polling Bash command. The steer sat unread until the command ended at 15:04:26, about 6.5 minutes later, and was answered right after. Same symptom as the repro here. +1, this is the fix I need.
Hit this today too, on Claude Opus 5.5. Timeline from the thread (UTC):
Time Event ~16:47:18 Agent starts a long foreground Bash call (full pytest tests/unitrun)16:51:51 Steer: "how's it going? …" 16:53:22 Steer: "did you see my message? please acknowledge" 16:53:29 I pressed Stop, which interrupted the command and ended the run No tool boundary came between the command starting and the Stop, so Claude never read either steer. Stop then threw them away. When I resent them in the next turn, the agent said it had never received any of them. The UI showed both as normal sent messages with nothing marking them undelivered.
So there are two parts. This PR fixes the delay. The second part, that Stop silently drops steers the CLI hasn't read yet, overlaps with #22423 and still needs its own fix even with this change. Without it, the obvious response to an agent that looks like it's ignoring you (pressing Stop) loses the messages.
Thanks for this. #37756 makes the same change and is the one being kept.
#37756 carries this fix forward and also keeps automatic server deliveries from backgrounding a running command. That distinction is covered by its regression test and makes it the more complete change to keep.
Your original commit and authorship are preserved in the replacement, along with the foreground-command fix.
Closing as a duplicate.
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Steer now automatically backgrounds running foreground commands so Claude can respond while those commands continue. This changes Steer's default execution behavior and needs confirmation that concurrent continuation is the intended product behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).