Repository navigation
Conversation
…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.
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.
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_usercard 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.sendInputqueues 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.mjsfixture +local-agents.test.js):call-tooldrives a real loopback MCPtools/call) and models stdin fidelity: input arriving during a tool_result wait queues for the turn boundary;--drop-mid-tool-inputmakes it vanish, matching the observed real CLI.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(inds-bot/) — fullnpm run test:windows: 8624 pass / 0 fail / 7 skippednode scripts/build-client.mjs --check— no client changes, check cleannpm run lint— 0 errorsindex.jsorsrc/host// 改了index.js或src/host/时跑冒烟测试 — cannot run locally (no deepseek-harness source on this machine); see Not verified belowRed/green evidence: on the pre-fix sources the drop-mode regression test fails (
ok: bluenever 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.js244 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 / 检查
src/client/changed →npm run buildran andclient.jsis committed. / 改了src/client/就已重新 build 并提交client.js。(N/A — no client changes)Co-authored-by. / 没有把 AI 工具写成作者或Co-authored-by。Co-authored-by(GitHub noreply, unless opted out), or N/A. / 促成改动的高质量外部 Issue/想法已按规范加Co-authored-by(GitHub noreply 邮箱,对方介意除外),或不适用。(N/A)