chore: add diagnostic logging for AskUserQuestion / ExitPlanMode reply flow#66
Merged
Merged
Conversation
…y flow Pending replies (AskUserQuestion answers, ExitPlanMode approvals) aren't reaching the CLI reliably in production. Add INFO logs at every state transition so the agent-box.log trace shows exactly where the reply chain breaks: - main.py: log every incoming message, router outcome, and the has_pending_question flag before dispatching to the agent - claude_code.py run() entry: log prompt preview and current pending state (kind + tool_use_id), so it's visible whether a reply is about to be consumed as a tool_result or mistakenly sent as a fresh query - _send_tool_result: log the content being written and confirmation after the write - Interception block: log when AskUserQuestion / ExitPlanMode is detected, when _pending_ask is saved, and when run() returns to wait No behavior change — 183 tests still pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
quick-sort
approved these changes
Jun 19, 2026
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.
Summary
生产环境里 AskUserQuestion / ExitPlanMode 的回复流转有 bug:question 发到 channel 后用户回复,但 agent 不等回复就继续按默认情况执行。需要先加日志看清楚回复在哪一步丢了。
加 INFO 级别日志覆盖整条回复链路:
main.py
dispatch_loop received message— channel 收到用户消息handle_message entry— 进入 handlerrouter replied directly— router 直接回(没到 agent)dispatching to agent ... has_pending_question=X— 即将调 agent.runhandle_message doneclaude_code.py
run() entry ... pending_kind=X pending_tool_use_id=Y— 进入 agent.run,带 prompt 预览和 pending 状态no pending ask — sending prompt as fresh query— 走了新 query 分支(不该出现的时候出现就是 bug)consuming pending ask— 检测到 pending,开始消费用户回复sending tool_result to CLI/tool_result written to CLI stdin— 写 stdin 前后... detected — setting pending ask/... pending ask saved, returning from run()Test Plan
复现后要看的日志关键点
AskUserQuestion detected → pending ask saved, returning from run()dispatch_loop received message → handle_message entry → dispatching to agent has_pending_question=True → run() entry pending_kind=questionconsuming pending ask → sending tool_result to CLI第 2 步
has_pending_question=False或者pending_kind=None→ pending 状态丢了;第 3 步看不到sending tool_result→ 解析路径出问题。