[Bug]: Queued Claude continuation replays a stale 429 after a newer successful run, so the thread shows Limited while the allowance is restored #45889
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server (Claude adapter), shows up in apps/web
Related#
Same family as #36405, which was closed after #39889 changed only the banner wording. The closing comment says the adapter part was not done and asks for a new issue if it still matters. It still happens on today's nightly. This report adds:
- The limit's reset time had not passed, so a fix that only drops rejections whose reset has passed would not catch it. The real signal is that a newer root run on the same native thread had already been served successfully.
- The wake appears to have been opened by a delegated-task report prompt that T3 itself offered into the live query (matched by frame order, not by uuid), rather than by Claude Code by itself.
- The open PR #36592 would not fix this case as described: it treats a buffered rejection as stale only when it is replayed at or after its reset. Here the replay happened about 4h20m before the reset, after a newer successful run and
allowedrate-limit events. - The exact replayed frame is confirmed by its native message id. Root cause and a regression test sequence are below.
Steps to reproduce / Expected / Actual#
Covered in detail under "Regression test to add". In short: when a thread is usage-limited while several delegated-task reports arrive back to back, a provider continuation gets queued. Then send a message after the allowance is restored. Expected: the thread ends healthy. Actual: the queued continuation replays the old 429 after the successful run, and the thread shows "Limited" plus the "Usage limit reached" banner.
Impact#
The thread looks blocked when it isn't. "Resume at reset", if enabled, schedules a needless resume. The stale failure also overrides the real outcome of the latest user run.
Version: T3 Code Nightly 0.1.14-nightly.20261130.5465 (pingdotgg/t3code). All line numbers are from upstream/main at 70cb73f869 (2026-11-29 20:48 PST), the newest upstream main from the same day as the nightly. The exact build commit is not verified.
Provider: Claude (claudeAgent, Claude Agent SDK). Model: Opus, high effort.
Symptom#
A thread hit the Claude 5-hour limit. Less than a minute later the account was allowed again. The user sent a message, and that run completed successfully: it replied and started five delegated tasks, which kept working. Even so, the sidebar row still shows "Limited" and the composer still shows the "Usage limit reached · Resets " (the old 09:00Z reset) banner with "Resume at reset / Snooze until reset". It stays that way until something else replaces the thread's latest run.
Every rate_limit_event after the successful run says status: "allowed" (5-hour window at 0-17%, new reset time, isUsingOverage: false). The account was not limited.
Root cause (summary)#
- While the limit was being hit, the parent thread received several delegated-task report prompts in a row. One of them (
Delegated task …cdc1a006…, offered at 04:38:28.112Z) went into the live Claude query while run 8 was still attached. The CLI ran it as its own native turn right after run 8's result. - That turn's
system/init(04:38:28.219Z) arrived in the gap after run 8 ended and before run 10 attached (04:38:28.394Z). With no turn attached,bufferWakeMessagetreated it as an idle wake start, buffered it and offered a provider continuation. That continuation became run…:ordinal:9, created at 04:38:28.243Z, 24 ms after the init. - By the time the turn's 429 frames arrived (04:38:28.673 / .677Z), run 10 was attached. They were sent before run 10's prompt echo, though. Most likely (inferred from code and timing, since the adapter's info logs aren't on disk) the prompt-echo gate held them, and
isClaudeResultForOtherTurnrecognised the result as not run 10's own. InpromptEchoMode === "early"the adapter then callsbufferWakeMessagefor the held frames plus the result (claude-wake-turn-before-prompt), so they joined the same wake buffer. Confirmed: the assistant message replayed later has native id468c7b8e-…, which is exactly the 04:38:28.673 frame. - The continuation stayed queued while three more runs went first, including the user's new message (run ordinal 12, 04:38:59.6Z to 04:40:02.456Z), which succeeded. Why it waited is not fully established.
Orchestrator.ts:8282says provider failures and usage limits re-hold the queue, and only client messages (not server continuations) release it. That fits the continuation running only after the user's message, but runs 10 and 11 still went ahead of it. - When run 12 finished, the continuation started (04:40:02.612Z, given ordinal 13). It drained the wake buffer and replayed the 94-second-old frames: the assistant text "You've hit your 5-hour limit" and then the stale error result.
handleSdkMessage(lastResult)settled it asfailedwith failure{class: "usage_limit", code: "api_error_429", resetAt: "…T09:00:00Z"}at 04:40:02.664Z. No new API call was made: the provider log has no SDK frame at 04:40:02.6. latestExecutedRun/runRanAfterchoose the run with the latestcompletedAt. That is the stale continuation (…02.664 > …02.456). So the thread'slastErrorClass = "usage_limit"andusageLimitResetAt = 09:00Z, and the web shows "Limited" plus the recovery banner.
Nothing in the drain path checks whether a buffered terminal result is stale, meaning it arrived before a later root run on the same native thread finished. Arrival times are already tracked in bufferedResultArrivals.
Evidence#
All times are UTC, 2026-11-30. Thread id 2e71e7ec-3cfc-4848-9b25-c1c454b3f42d, native session 35312a93-…. The same provider instance and session were used throughout.
Provider log (~/.t3/userdata/logs/provider/events.<threadId>.log)#
| Time | Frame |
|---|---|
| 04:38:26.589 | prompt.offer user "Delegated task …93435746…" (run 7) |
| 04:38:27.346 | rate_limit_event five_hour status: rejected, utilization 1, resetsAt 09:00Z |
| 04:38:27.348 / .353 | assistant <synthetic> "You've hit your 5-hour limit…" (api_error_status: 429) / result is_error: true, terminal_reason: api_error |
| 04:38:27.728 | prompt.offer "Delegated task …93435746…" (run 8) |
| 04:38:28.112 | prompt.offer "Delegated task …cdc1a006…" (sent while run 8 is attached) |
| 04:38:28.204 / .207 | 429 assistant / error result (ends run 8) |
| 04:38:28.219 | system/init: CLI starts a native turn for the cdc1a006 prompt; no run attached (run 8 ended, run 10 not yet) |
| 04:38:28.243 | (T3 DB) continuation run …:ordinal:9 created |
| 04:38:28.394 | (T3 DB) run 10 starts |
| 04:38:28.445 | prompt.offer (run 10) |
| 04:38:28.673 / .677 | 429 assistant / error result for the cdc1a006 turn, before run 10's prompt echo. The assistant frame's id 468c7b8e-… is the one replayed at 04:40:02.634 |
| 04:38:29.589 / .595 | 429 / error result (ends run 10) |
| 04:38:33.4 to .9 | run 11, same 429 |
| 04:38:59.660 | user's real message (run 12), which succeeds |
| 04:39:12.643 | rate_limit_event five_hour status: allowed, utilization 0, new resetsAt 09:30Z (the weekly counter also changed) |
| 04:40:02.443 | result subtype: success, terminal_reason: completed (run 12 done) |
| 04:40:02.6 | no SDK frames at all |
State DB (~/.t3/userdata/statev2.sqlite)#
orchestration_v2_projection_runs for the thread:
ordinal 12 id …:ordinal:12 completed requested 04:38:59.574 started 04:38:59.604 completed 04:40:02.456
ordinal 13 id …:ordinal:9 failed requested 04:38:28.243 started 04:40:02.612 completed 04:40:02.664
userMessageId message:thread:…:ordinal:1:d60171d4-… (provider-continuation)
Note the id says ordinal:9, but the run was given ordinal 13 when it finally started.
Events in orchestration_events for run …:ordinal:9:
- 04:38:28.243
run.created, command idprovider-continuation:message:thread:…:ordinal:1:d60171d4…. Its message is abackground_tasknotification, text "Background task completed.". - 04:40:02.634
message.updated, role assistant, text "You've hit your 5-hour limit · resets ". This is a replayed frame. - 04:40:02.662
turn-item.updated, typeerror,failure: {class: "usage_limit", message: "Claude API rate limit reached. Try again later.", code: "api_error_429", retryable: true, resetAt: "2026-11-30T09:00:00.000Z"}. - 04:40:02.664
run.updatedstatusfailed.
Code path (upstream/main 70cb73f869)#
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:
- ~11662
rate_limit_eventhandling; with no active turn, the frame goes tobufferWakeMessage. Other frames that arrive with no active turn and no settled turn also go there (see thecontext === nullbranch right after it). - ~13460 to 13510 prompt-echo gate in the attached-turn path. A gated
resultthatisClaudeResultForOtherTurnflags, withpromptEchoMode === "early", sendsheldRootFramesand the result tobufferWakeMessage(logorchestration-v2.claude-wake-turn-before-prompt). This is how the 04:38:28.673/.677 frames got into the wake buffer while run 10 was attached. - 10929 to ~11195
bufferWakeMessage.system/init(isWakeTurnStart, 11009),assistant,user,resultandrate_limit_eventall count as wake evidence and are appended towakeBuffers. A wake turn start or aresultpasses the gate at ~11132 and callscontinuationRequests.offer(...)(11186). This is how the cdc1a006 native turn became continuation run 9. - 7769
markAbsorbedWake, called at 13153 when a non-continuation turn's result is handled. It only marks a wake as absorbed when root-turn frames follow the buffer's lastresult. Here the buffer's tail is a result, so the user's successful run 12 neither absorbed nor cleared the stale wake buffer, and the continuation latch stayed open. - ~14997 to 15085 continuation start (the
sdkMessageLockblock afterif (userMessage !== null && !turnInput.resume)). It drainswakeBuffers, replays the non-result frames throughhandleSdkMessage, then at 15083 replayslastResultunlessemptyTurnBeforeNextTurn. That guard only covers an empty successful result followed by a turn start. A stale error result goes through and fails the run. - ~13155 to 13230 result finalisation:
usageLimited/providerFailureFromResult(message, bufferedResultArrivals.get(message) ?? completedAt, …)classifies the replayed 429 result asusage_limitwith the old reset time. (Replayed assistant frames skiplatestAssistantRateLimitbecause ofinput.replayed !== trueat ~12125, but the result alone is enough.) - 6773
bufferedResultArrivals: already records when each buffered result really arrived, so staleness can be detected.
Thread runtime and UI:
packages/shared/src/orchestrationV2ThreadError.ts:latestExecutedRun(62) andrunRanAfter(95) choose bycompletedAt, so the stale continuation wins.latestRootProviderFailurethen givesusage_limit, andthreadErrorSummarysetslastErrorClass/usageLimitResetAt.apps/web/src/components/Sidebar.logic.ts:1013→ "limited".apps/web/src/components/ChatView.tsx:2784useUsageLimitRecoveryBannerItem→ banner.apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.tsalso acts on this state (auto-resume or snooze at the reset), so the stale failure can trigger a pointless resume at the old reset time (09:00Z).
Suggested fix (for the implementing agent to decide)#
The fix belongs in the adapter, not the UI. Options, roughly in order of preference:
- Settle stale continuations as completed. In the continuation drain, if the result to replay arrived (
bufferedResultArrivals) before the most recent root result on the same native thread that belonged to a later-started non-continuation run, do not replay it as the run's terminal outcome. Replay the frames for the transcript if you want, thenfinalizeActiveTurn({ status: "completed" }). Or skip the run, or mark it superseded. At minimum, a staleusage_limitorapi_errorresult must not fail a run that starts after a newer successful run. - Retire the wake when a later user turn finishes. When a non-continuation turn's result is handled (13153), clear or retire a pending continuation latch whose buffered wake already has its own terminal
result(a complete, finished native turn). Then cancel the queued continuation run, or let it finish as completed with nothing to replay. This extendsmarkAbsorbedWake, which currently only handles the case where the buffer ends in root frames. - Don't treat a prompt T3 itself offered as an idle wake. The cdc1a006 native turn came from a prompt T3 sent into the live query (a delegated-task report). If the adapter remembered prompts it offered that weren't consumed by the attached run, it could route that turn's frames to the right place instead of buffering them as a wake. This is a bigger change.
Any of these should also make sure the queued continuation run doesn't get the highest ordinal and newest completedAt with a stale failure. If option 1 or 2 makes it "completed", the thread falls back to normal.
Regression test to add#
In apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts (use ClaudeAdapterV2.testkit.ts), reproduce the sequence:
- Run A is attached; offer prompt P1, and also offer a second prompt P2 while A is still running.
- SDK emits: A's
rate_limit_eventrejected, synthetic 429 assistant, error result (A ends failed / usage_limit, which is correct). - With no run attached, SDK emits
system/initfor P2's native turn. Expect a continuation to be offered and queued. - Attach run C and offer its prompt P3 (echo mode "early"). Before P3's echo, SDK emits P2's synthetic 429 assistant and its error result (whose prompt uuid is P2's). Expect these to be buffered into the wake, not to settle C. Then emit C's own echo, 429 and error result (C fails, which is correct).
- Start a user run B; SDK emits
rate_limit_eventallowed and a successful result. B completes. - Start the queued continuation.
Expected: the continuation does not end failed with usage_limit (completed or superseded). The thread's latest executed run has no failure, and threadErrorSummary(...).lastErrorClass is null.
Currently: the continuation ends failed, usage_limit, resetAt = the old reset, and the thread shows "Limited".
Workaround#
None needed for usage, since the account is fine. The sidebar status has no time check (Sidebar.logic.ts:1013 only looks at status === "failed" and lastErrorClass), so "Limited" does not clear at the reset time. The banner tracks resetPassed (UsageLimitRecoveryBanner.tsx:75), so its wording may change after the reset, but it keeps the same failed/usage_limit condition. They clear only when a later run on the thread completes. Sending any message to the thread fixes it. If "Resume at reset" is enabled, UsageLimitRecoveryWorker would also send a needless resume at the old reset time.
tanstack-source added labelsbug
zicozz876(GitHub profile, opens in a new tab) linked this to #46090
Sign in to join this conversation.