Now I have a complete picture. Let me analyze:
Issue #1019 Analysis
The Bug
When a tool-use turn involves multiple LLM calls (e.g., tool call 1 → tool result → tool call 2 → tool result → ...), each LLM call that hits a rate limit increments _retryAttempt. The counter only resets on agent_end, but agent_end fires once per user prompt, not between individual LLM calls within a turn.
Example scenario:
- User sends prompt →
agent_start
- LLM call 1 → 429 →
_retryAttempt = 1 → retry → succeeds
- LLM call 2 → 429 →
_retryAttempt = 2 → retry → succeeds
- LLM call 3 → 429 →
_retryAttempt = 3 → exceeds max (3) → fails
agent_end fires (too late, we already failed)
Each individual LLM call succeeded after one retry, but the counter never reset between calls.
Current Code (agent-session.ts lines ~340-355)
The PR #1018 Approach
The PR resets counter at prompt() start:
This fixes accumulation across separate user prompts, but NOT the issue described in #1019 (accumulation within a single turn).
Proposed Fix
Reset _retryAttempt in the message_end handler when receiving a successful assistant message (not just at agent_end).
Location: packages/coding-agent/src/core/agent-session.ts, in _handleAgentEvent, within the message_end block (~lines 309-330)
Change: Add retry counter reset when an assistant message arrives successfully:
The existing agent_end handler reset can become a safety net (it will rarely trigger since message_end already resets).
Files Affected
packages/coding-agent/src/core/agent-session.ts - the fix
packages/coding-agent/CHANGELOG.md - document the fix