Repository navigation
fix(agent): auto-approve CLI tool permissions & improve error visibility - #321
Conversation
…ity (#320) - Add can_use_tool callback to auto-approve CLI permission requests. Without it, network tools (read_messages, send_message) fail silently with "Tool permission stream closed before response received". - Handle UserMessage from SDK — update _last_activity so idle timeout doesn't start counting prematurely after tool results. - Stop deduplicating [api:request] events — each API call gets a unique counter (API #1, #2, #3) so user can track multi-turn conversations. - Log unhandled SDK message types at warning level. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- test_stderr_api_request_counter_not_deduped: each [api:request] gets unique counter (API #1, #2, #3), not deduped like other stage events - test_user_message_does_not_break_stream: UserMessage from SDK (tool results sent back to Claude) doesn't break the event stream Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
@claude review. Focus on critical issues: bugs, security vulnerabilities, logical errors, data loss risks, performance problems. Do NOT nitpick style, naming conventions, minor formatting, or subjective preferences — only flag issues that could break functionality or cause real harm in production. |
|
Claude finished @axisrow's task in 1m 39s —— View job Code Review
Overall the changes are correct and address real bugs. No critical security vulnerabilities or data loss risks. Two minor issues worth noting: Issue 1 —
|
|
Re: Issue 2 ( |
_api_request_count was not reset between retry attempts, causing "API #4" instead of "API #1" on retries. Reset to 0 at the start of each attempt alongside other per-attempt state. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
@claude review. Focus on critical issues: bugs, security vulnerabilities, logical errors, data loss risks, performance problems. Do NOT nitpick style, naming conventions, minor formatting, or subjective preferences — only flag issues that could break functionality or cause real harm in production. |
|
Claude finished @axisrow's task in 1m 35s —— View job Code Review
The previous review found two issues. Here's the current status: Issue 1 — Issue 2 — No critical issues found in the current diffAll four changes are correct:
TestsThree new tests cover all three behavioral changes. Test logic is sound:
The filter No blocking issues. Ready to merge. |
…ut error When API rate limit status is "rejected", emit⚠️ warning event to user instead of a silent status line. Include last rate limit info in idle timeout error message so user understands WHY the agent hung. Before: "Стрим Claude замолчал на 90с. Возможно, соединение потеряно." After: "Стрим Claude замолчал на 90с. Последний rate limit: rejected." Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
_last_rate_limit stored "Rate limit: status, NN%" but timeout message prepended another "Последний rate limit:" → double prefix. Now stores just "status, NN%" for clean output. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ity (#321) * fix(agent): auto-approve CLI tool permissions & improve error visibility (#320) - Add can_use_tool callback to auto-approve CLI permission requests. Without it, network tools (read_messages, send_message) fail silently with "Tool permission stream closed before response received". - Handle UserMessage from SDK — update _last_activity so idle timeout doesn't start counting prematurely after tool results. - Stop deduplicating [api:request] events — each API call gets a unique counter (API #1, #2, #3) so user can track multi-turn conversations. - Log unhandled SDK message types at warning level. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * test(agent): cover API request counter and UserMessage handling - test_stderr_api_request_counter_not_deduped: each [api:request] gets unique counter (API #1, #2, #3), not deduped like other stage events - test_user_message_does_not_break_stream: UserMessage from SDK (tool results sent back to Claude) doesn't break the event stream Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(agent): reset API request counter on retry attempt _api_request_count was not reset between retry attempts, causing "API #4" instead of "API #1" on retries. Reset to 0 at the start of each attempt alongside other per-attempt state. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(agent): surface rate limit rejected as warning & include in timeout error When API rate limit status is "rejected", emit⚠️ warning event to user instead of a silent status line. Include last rate limit info in idle timeout error message so user understands WHY the agent hung. Before: "Стрим Claude замолчал на 90с. Возможно, соединение потеряно." After: "Стрим Claude замолчал на 90с. Последний rate limit: rejected." Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(agent): remove duplicate "Rate limit:" prefix in timeout error _last_rate_limit stored "Rate limit: status, NN%" but timeout message prepended another "Последний rate limit:" → double prefix. Now stores just "status, NN%" for clean output. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Summary
can_use_toolauto-approve: Claude CLI v2.1.88 sendscan_use_toolcontrol requests for network tools (read_messages, send_message, etc.). Without a callback, the SDK raises "canUseTool callback is not provided" → tools fail silently with "Tool permission stream closed before response received". Added_auto_approve_toolcallback that auto-approves all tool calls (our own PermissionGate handles permissions separately).UserMessagehandling: SDK yieldsUserMessageafter tool results are sent back to Claude. Previously ignored →_last_activitynot updated → idle timeout starts counting too early. Now updates_last_activity.API request counter:
[api:request]events were deduplicated (same label). Third API request (after tool call) was invisible. Now each API request gets a unique counter: "API Add channel statistics #1", "API Add Claude Code GitHub Workflow #2", "API Refactor project into role-based layers #3".Unhandled message logging: Unknown SDK message types logged at warning level for diagnostics.
Root cause trace
Session data showed:
Tools appeared as ✅ in TUI but actually returned errors to Claude.
Test plan
ruff checkpassespytest tests/test_agent.py tests/test_agent_errors.py -n auto)test_chat_stream_options_have_can_use_tool— verifiescan_use_toolis setpython -m src.main agent chat→ "Получи последние 10 сообщений из чата 1877929309"🤖 Generated with Claude Code