Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Queued Claude continuation replays a stale 429 after a newer successful run, so the thread shows Limited while the allowance is restored #45889

Opendavisonio(GitHub profile, opens in a new tab) opened this issue 0 comments

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

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 allowed rate-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)

  1. 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.
  2. 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, bufferWakeMessage treated 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.
  3. 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 isClaudeResultForOtherTurn recognised the result as not run 10's own. In promptEchoMode === "early" the adapter then calls bufferWakeMessage for 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 id 468c7b8e-…, which is exactly the 04:38:28.673 frame.
  4. 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:8282 says 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.
  5. 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 as failed with 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.
  6. latestExecutedRun / runRanAfter choose the run with the latest completedAt. That is the stale continuation (…02.664 > …02.456). So the thread's lastErrorClass = "usage_limit" and usageLimitResetAt = 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)

TimeFrame
04:38:26.589prompt.offer user "Delegated task …93435746…" (run 7)
04:38:27.346rate_limit_event five_hour status: rejected, utilization 1, resetsAt 09:00Z
04:38:27.348 / .353assistant <synthetic> "You've hit your 5-hour limit…" (api_error_status: 429) / result is_error: true, terminal_reason: api_error
04:38:27.728prompt.offer "Delegated task …93435746…" (run 8)
04:38:28.112prompt.offer "Delegated task …cdc1a006…" (sent while run 8 is attached)
04:38:28.204 / .207429 assistant / error result (ends run 8)
04:38:28.219system/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.445prompt.offer (run 10)
04:38:28.673 / .677429 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 / .595429 / error result (ends run 10)
04:38:33.4 to .9run 11, same 429
04:38:59.660user's real message (run 12), which succeeds
04:39:12.643rate_limit_event five_hour status: allowed, utilization 0, new resetsAt 09:30Z (the weekly counter also changed)
04:40:02.443result subtype: success, terminal_reason: completed (run 12 done)
04:40:02.6no 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 id provider-continuation:message:thread:…:ordinal:1:d60171d4…. Its message is a background_task notification, 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, type error, 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.updated status failed.

Code path (upstream/main 70cb73f869)

apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:

  • ~11662 rate_limit_event handling; with no active turn, the frame goes to bufferWakeMessage. Other frames that arrive with no active turn and no settled turn also go there (see the context === null branch right after it).
  • ~13460 to 13510 prompt-echo gate in the attached-turn path. A gated result that isClaudeResultForOtherTurn flags, with promptEchoMode === "early", sends heldRootFrames and the result to bufferWakeMessage (log orchestration-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, result and rate_limit_event all count as wake evidence and are appended to wakeBuffers. A wake turn start or a result passes the gate at ~11132 and calls continuationRequests.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 last result. 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 sdkMessageLock block after if (userMessage !== null && !turnInput.resume)). It drains wakeBuffers, replays the non-result frames through handleSdkMessage, then at 15083 replays lastResult unless emptyTurnBeforeNextTurn. 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 as usage_limit with the old reset time. (Replayed assistant frames skip latestAssistantRateLimit because of input.replayed !== true at ~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) and runRanAfter (95) choose by completedAt, so the stale continuation wins. latestRootProviderFailure then gives usage_limit, and threadErrorSummary sets lastErrorClass / usageLimitResetAt.
  • apps/web/src/components/Sidebar.logic.ts:1013 → "limited".
  • apps/web/src/components/ChatView.tsx:2784 useUsageLimitRecoveryBannerItem → banner.
  • apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.ts also 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:

  1. 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, then finalizeActiveTurn({ status: "completed" }). Or skip the run, or mark it superseded. At minimum, a stale usage_limit or api_error result must not fail a run that starts after a newer successful run.
  2. 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 extends markAbsorbedWake, which currently only handles the case where the buffer ends in root frames.
  3. 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:

  1. Run A is attached; offer prompt P1, and also offer a second prompt P2 while A is still running.
  2. SDK emits: A's rate_limit_event rejected, synthetic 429 assistant, error result (A ends failed / usage_limit, which is correct).
  3. With no run attached, SDK emits system/init for P2's native turn. Expect a continuation to be offered and queued.
  4. 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).
  5. Start a user run B; SDK emits rate_limit_event allowed and a successful result. B completes.
  6. 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.

  1. tanstack-source added labelsbug

Sign in to join this conversation.