Skip to content

fix(claude): derive usage and name login or limit errors - #237

Open
leoisadev1 wants to merge 1 commit into
mainfrom
leoisadev1/t3-port-claude-metadata
Open

fix(claude): derive usage and name login or limit errors#237
leoisadev1 wants to merge 1 commit into
mainfrom
leoisadev1/t3-port-claude-metadata

Conversation

@leoisadev1

Copy link
Copy Markdown
Member

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-only rate_limit on 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 onto origin/main (78610f145)
  • Targeted lint on the changed server files
  • Server typecheck: no new errors in these files

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.completed payloads.

Model

Grok 4.6 High in Grok Build via Orca.

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.
@github-actions github-actions Bot added type:provider Agent provider contribution. vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 10, 2026
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

Claude 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/5

Not 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

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex produced a proof for the posted P1 finding and associated it with the corresponding review comment.
  • The rate-limit lifecycle reproduction in TypeScript was executed to demonstrate the conditions described by the finding.
  • The reproduction test output was captured in a log for review.

View all artifacts

T-Rex Ran code and verified through T-Rex

Fix all with Greploop Fix All in Claude Code

Reviews (1): Last reviewed commit: "fix(claude): derive usage and name login..." | Re-trigger Greptile

Comment on lines +3718 to 3721
yield* emitRuntimeWarning(context, notice, rateLimitInfo);
}
}
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Resolve rejected rate limits

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.

View artifacts

T-Rex Ran code and verified through T-Rex

Fix in Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L type:provider Agent provider contribution. vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant