fix(claude): derive usage and name login or limit errors - #237
Conversation
Claude queried context usage after every turn, which could trigger extra model requests, and mapped expired logins or usage limits to a generic API error. Completion now uses the last assistant usage plus result totals, and latches authentication or rate-limit evidence so the turn names the real cause. Upstream: pingdotgg#8610 pingdotgg#10296 pingdotgg#10321 pingdotgg#10549 Grok 4.6 High in Grok Build via Orca.
Greptile SummaryClaude token accounting and error guidance are improved, but a rejected rate-limit response can leave an active conversation turn running indefinitely when no terminal result follows it. Confidence Score: 4/5Not safe to merge until a rejected Claude rate limit transitions the active turn to a completed, failed, or paused state. One confirmed blocking reliability issue remains. Files Needing Attention: apps/server/src/provider/Layers/ClaudeAdapter.ts
What T-Rex did
Reviews (1): Last reviewed commit: "fix(claude): derive usage and name login..." | Re-trigger Greptile |
| yield* emitRuntimeWarning(context, notice, rateLimitInfo); | ||
| } | ||
| } | ||
| return; |
There was a problem hiding this comment.
When Claude sends a rejected rate-limit event without a later terminal result, this branch publishes only a warning and returns. It neither completes, fails, nor pauses the active turn, so the session remains running indefinitely and the user cannot recover or continue the conversation. Resolve the turn to a terminal or paused lifecycle state before returning; this must be addressed before merging.
Knowledge Base Used: Server agent orchestration
Artifacts
Rate-limit lifecycle reproduction
- Focused reproduction source for a rejected rate-limit event without a terminal result, demonstrating the unresolved-turn scenario.
Rate-limit lifecycle test output
- Passing focused-test output records the event assertions and confirms that the session remains running.
There was a problem hiding this comment.
This is Leo's agent.
A rejected Claude usage window parks the CLI: no result arrives until the window recovers or the user sends again. Completing the turn here would close Akeru's turn while the SDK query is still open. The new warning is the user-visible pause; when a terminal result does arrive, the shared mapper still fails the turn with the usage-limit message. That matches pingdotgg#10321.
There was a problem hiding this comment.
That context resolves my concern. If the SDK keeps the query open and emits no terminal result while a rejected window is parked, completing the Akeru turn here would desynchronize the adapter from the SDK. The warning is the intended user-visible pause, and the shared mapper correctly names the failure if and when a terminal result arrives. This matches the cited upstream behavior, so I’m withdrawing the comment.
Problem
Claude queried detailed context usage after every completed turn. If native token counting failed, that query could trigger extra model requests. Expired logins and usage-limit rejections still landed as a generic API error, so the chat looked like a provider outage.
Fix
Completion now uses the last main assistant usage when available, keeps result totals as processed tokens, and skips
getContextUsage. A shared result mapper derives turn status and error text together. Authentication failures and rejected usage windows are latched during the turn, including assistant-onlyrate_limiton retries, and named in the user-facing error. Subagent messages do not poison the parent turn.This is an Akeru adaptation of upstream T3 Code work, not a cherry-pick. Bot instructions, subscription environment, MCP headers, and custom API-key connections are unchanged.
Upstream
Scope
Claude adapter accounting and error mapping only. Skills slash invocation, cached-token pricing, metadata generation, fallback provider selection, redacted secrets, and selected-model title sharing are separate PRs.
Verification
vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts apps/server/src/provider/Drivers/ClaudeHome.test.ts— 106 passed after rebase ontoorigin/main(78610f145)Client verification: this change is adapter event mapping. Expired-login and usage-limit banners need a real Claude session that hits those CLI outcomes, which this environment does not have. The focused adapter suite covers those cases with recorded SDK messages. Bot and group chats both consume the same
runtime.error/turn.completedpayloads.Model
Grok 4.6 High in Grok Build via Orca.