Skip to content

fix(local-agents): queue input while Claude waits on a tool result (#1170) - #3262

Draft
Fei2411 wants to merge 1 commit into
devfrom
fix/1170-claude-suspended-input
Draft

Fei2411 wants to merge 1 commit into
devfrom
fix/1170-claude-suspended-input

Conversation

@Fei2411

@Fei2411 Fei2411 commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Issue

Fixes #1170

Agent

Agent: DS Bot (SWE-2.1)

What changed / 改了什么

Root cause: the Claude CLI never reads stdin while a tool_use waits for its tool_result — the loopback MCP response it blocks on is the only way out of that state. Input written into that window is silently lost. This is deterministic for the most common case: an answered ask_user card produces a step in which the conclusion tool result and the user's answer are processed together, so the adapter writes the answer to stdin microseconds before the CLI even receives the HTTP response that unblocks it. The answer vanishes — never enqueued, never echoed, never seen.

Fix (claude.js + adapter.js):

  • ClaudeEngine.steerDropsInput(session) reports exactly that window: a tool_result is pending (pendingToolUses / awaitingToolResult) and no permission or hook wait is open. Permission and hook waits are excepted deliberately — the control protocol answers those over stdin, so the CLI must keep reading there, and existing steered-input behaviour depends on it.
  • sendInput queues input arriving in that window (same mechanism ACP already uses). The drain sends it as the next prompt when the turn closes, inside the same step — the design's own fallback for a CLI that cannot take the steer (docs/plans/2026-11-04-local-agents.md: "Steering while a CLI turn runs is passed to the CLI when it supports it, else it goes out as the next prompt in the same step"). Queued input is not counted as handed until it is actually sent, so aborts and session closes re-deliver it instead of losing it.

Tests (fake-claude.mjs fixture + local-agents.test.js):

  • The fixture gained a faithful MCP-bridge mode (call-tool drives a real loopback MCP tools/call) and models stdin fidelity: input arriving during a tool_result wait queues for the turn boundary; --drop-mid-tool-input makes it vanish, matching the observed real CLI.
  • Regression test (red before the fix, green after): the conclusion tool result + user answer in one step, CLI in drop mode → the answer must still reach the CLI after the turn closes.
  • Companion tests: same flow against the queueing (non-drop) CLI, and the normal path — input after the turn settled starts its own turn, unqueued.

Changelog

Fixed Claude Code Bots silently losing messages sent while a card or tool call was open — answers to questions now reliably reach the agent.

How I checked it / 怎么验证的

  • npm test (in ds-bot/) — full npm run test:windows: 8624 pass / 0 fail / 7 skipped
  • node scripts/build-client.mjs --check — no client changes, check clean
  • npm run lint — 0 errors
  • Smoke test, for changes to index.js or src/host/ / 改了 index.js 或 src/host/ 时跑冒烟测试 — cannot run locally (no deepseek-harness source on this machine); see Not verified below
  • Screenshot attached, for interface changes / 界面改动已附截图 — no interface changes

Red/green evidence: on the pre-fix sources the drop-mode regression test fails (ok: blue never arrives — the answer is written into the tool_result wait window and lost), and the queue-mode companion also fails; after the fix all three pass. Targeted: test/local-agents.test.js 244 pass / 0 fail / 1 skipped; related files (local-agent-context, local-agent-lifecycle, local-agents-2479-2564, local-agents-2918, context-pr2-local-agents) 95/95. Leak scan: must fix 0.

Verified on Mac.

Not verified: behaviour against the real Claude CLI (no Claude CLI on this machine) — the drop-window model rests on the issue's transcript evidence (inputs mid-turn show enqueue records, inputs during the suspension window do not). Whether the real CLI consumes steered input during permission waits is likewise unverified; this PR deliberately keeps the existing steer behaviour there and changes nothing for it.

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 改了 src/client/ 就已重新 build 并提交 client.js。(N/A — no client changes)
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息,截图里也没有。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。
  • Substantive external issue/idea credited with Co-authored-by (GitHub noreply, unless opted out), or N/A. / 促成改动的高质量外部 Issue/想法已按规范加 Co-authored-by(GitHub noreply 邮箱,对方介意除外),或不适用。(N/A)

…1170)

The Claude CLI never reads stdin while a tool_use waits for its
tool_result: the loopback MCP response it blocks on is the only way out.
Input steered into that window is silently lost — the exact shape an
answered ask_user produces, where the conclusion tool result and the
user's answer ride the same step and stdin is always written before the
HTTP response unblocks the CLI.

Queue the input instead and let the drain send it as the next prompt
when the turn closes, inside the same step — the design's own fallback
for a CLI that cannot take the steer. Permission and hook waits keep
steering: the control protocol answers those over stdin, so the CLI
must keep reading there.

The fake CLI fixture now models both behaviours: input arriving during
a tool_result wait queues for the turn boundary, and --drop-mid-tool-input
makes it vanish, matching the observed real CLI.
@Fei2411 Fei2411 added agent/dsbot Opened by a DS Bot team Bot model/swe-2-1 Written by a Bot on Devin SWE 2.1 needs-product-ok Waiting for maintainer product/UI approval before merging to dev labels Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/dsbot Opened by a DS Bot team Bot model/swe-2-1 Written by a Bot on Devin SWE 2.1 needs-product-ok Waiting for maintainer product/UI approval before merging to dev

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant