Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): limited threads auto-resume when allowance returns early #24511

Closedonly21mil(GitHub profile, opens in a new tab)wants to merge 27 commits intomain fromrefs/pull/24511/headopened View on GitHub

only21mil(GitHub profile, opens in a new tab)commented

Problem

With auto-resume armed, a thread stopped by a usage limit waits for the reset time saved with the failure, even when a reset credit or provider-side refresh brings the allowance back sooner. In https://git.cafe/pingdotgg/t3code/issues/22307 the reporter redeemed a Claude reset at 11:44 UTC. Their three armed threads stayed stopped until they resumed each by hand; the saved reset was 15:10 UTC.

Change

  • The sweep reads the provider usage snapshot (usageLimits). A reading taken after the failure with every window below 100% sends the continuation early.
  • The SQL candidate query also returns armed threads before their reset, still only for threads with a usage-limit failure. Main removed the memory store; the merge preserves that removal.
  • The Claude probe dates a reading by when Claude Code fetched it.

Scope

Fixes https://git.cafe/pingdotgg/t3code/issues/22307, which asks for this and for cancellation and the other guards to keep working. It extends auto-resume from https://git.cafe/pingdotgg/t3code/pulls/12686 and adds no setting.

Bug fix: armed threads stay stopped after the allowance is back.

Verification

Re-checked 2026-11-20. af1be44cce merges main 5872b0a488, resolving the threadExecution.ts conflict from #37419. An AI agent ran the checks below.

Setup. Linux servers from source, fresh data per commit. Browser panel, light, 1280x800 (T1 continued 1280x700). Signed-in Claude Code 2.1.328, Haiku 5.5. A local proxy returns a usage-limit 429 in place of one Claude API response per thread (reset in 3 hours) and forwards all other requests. An AI agent ran this check.

Steps. With auto-resume on, arm the proxy for each thread and send "Work on this." to hit the 429. After the last limit, wait 2 minutes, then use Settings → Providers → Refresh provider status twice, 2 minutes apart.

Before 5872b0a488After af1be44cce

5872b0a488 after two fresh readings: still limited, one run only

5872b0a488 after two fresh readings: still limited, one run only

af1be44cce after one fresh reading: 'Continue where you left off.' sent, Haiku replied

af1be44cce after one fresh reading: 'Continue where you left off.' sent, Haiku replied

Also on af1be44cce, one thread at a time, each guard applied before the next was limited. Archive (T4) and a new message (T5) are in the run events:

T2 after Cancel auto-resume: Resume at reset; no limit-resume run

T2 after Cancel auto-resume: Resume at reset; no limit-resume run

T3 after sidebar Snooze, In 1 hour: Snoozed, 1h left; no limit-resume run

T3 after sidebar Snooze, In 1 hour: Snoozed, 1h left; no limit-resume run

T6 after sidebar Settle: Settled, no resume action; no limit-resume run after either reading

T6 after sidebar Settle: Settled, no resume action; no limit-resume run after either reading

The PR's five test files fail on 5872b0a488's production files and pass on af1be44cce's tree; output, proxy timeline and run events are in the details.

Links. Runtime test.

Not shown

  • A really exhausted plan or a real reset credit.
  • The takeover now exercises the recovery sweep in the existing runtime tests.
  • Signed-in web coverage was not run for early resume with automatic snooze, explicit stop, un-settle after settle, provider changes, pending or stale requests, an alternate Claude cache filename, recovery timing per provider, a full Claude monthly window, a second usage limit, or Antigravity, Grok, OpenCode or Cursor. Desktop and mobile were not run.
Change detail, tests, the signed-in run's logs and merge history

Problem detail: Main's recovery sweep waits for the saved reset and does not consult the provider usage snapshot.

Change detail:

  • The usage snapshot is the one shown on the Usage page. The continuation carries that reading time as usageLimitClearedAt, and the orchestrator accepts it only when that time is after the failed run ended. Every other guard stays: cancel, stop, archive, settle, snooze, pending requests and the recovery request id.
  • Early delivery gets its own command id, so a rejected early attempt cannot take the receipt the delivery at the reset needs.
  • Claude Code can answer a usage read from a reading it cached earlier. The Claude probe now dates the reading by when Claude Code fetched it, from Claude Code's own cache file read before and after the call, so a reading cached before the failure no longer counts as taken after it. With no cache entry it keeps the probe time. A cache read that fails or takes over 2 seconds leaves that probe without a reading, and the last one stands.

A run that fails again before the previous reset gets a recovery marked waitForReset, which resumes only at the reset, so each limit episode gets at most one early resume.

A missing reading, or one at 100%, falls back to the reset time, as do providers with no usage windows. With "Snooze limited threads" on, the thread is snoozed until the reset; when the early continuation goes out, that snooze ends and the thread leaves Snoozed. A snooze set from the sidebar still holds the thread until it ends.

usageLimitClearedAt rides on message.dispatch because the recovery continuation already travels as that command. A client could already send that continuation by hand, and the orchestrator still checks the run, the recovery and waitForReset. Both new contract fields are optional, so older clients ignore them and stored recoveries read as not waiting.

  • The probe uses its start time when there is no entry at the expected Claude cache path. An alternate cache filename was not tested.
  • Desktop and mobile clients: the change is in the server; the shared error summary has its unit test.
  • How soon each provider's snapshot shows a restored allowance. Antigravity, Grok, OpenCode and Cursor were not exercised.
  • A Claude account whose monthly spend window reads 100% waits for the reset even after its session window clears.
  • If the early retry hits the limit again, it waits for the reported reset or, when the provider supplies none, for the saved reset. A newly reported reset can also schedule a snooze when automatic snooze is enabled.

Tests, by an AI agent on 2026-11-20:

Setup. Fresh clones, Node 26.13.1 on macOS 27.0.1 and Linux 7.2.8.

Steps. Run the five PR test files with 5872b0a488 production files → run them on the rebuild.

Before, 5872b0a488 production files with tests from 2ee818787c:

 Test Files  4 failed (4)
      Tests  11 failed | 265 passed | 1 skipped (277)
 Test Files  1 failed (1)
      Tests  1 failed | 36 passed (37)

After, 2ee818787c, the unsigned rebuild of af1be44cce with the same parents and tree. The server run adds reconcileV2PreviewMigration.test.ts.

 Test Files  5 passed (5)
      Tests  281 passed | 1 skipped (282)
 Test Files  1 passed (1)
      Tests  37 passed (37)

Also passed on 2ee818787c: four package typechecks, vp run check:changed 5872b0a488, #37419’s 67 web tests and 11 Claude probe tests on Linux.

Signed-in run, 01:35Z to 01:55Z on 2026-11-20. Proxy timeline (turn requests and usage readings from its log, UTC):

-- base 5872b0a488 (server started 01:35:56) --
2026-11-20T01:36:01.542Z GET /api/oauth/usage 200 passed                         server start-up reading
2026-11-20T01:37:12.779Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   base thread limited
2026-11-20T01:37:13.304Z GET /api/oauth/usage 200 passed                         reading taken with the limit
2026-11-20T01:39:18.479Z GET /api/oauth/usage 200 passed                         FRESH READING 1 (Refresh provider status 01:39:17.870)
2026-11-20T01:41:22.809Z GET /api/oauth/usage 200 passed                         FRESH READING 2 (Refresh provider status 01:41:22.098)
                                                                                 no turn request through 01:43:23 (watch end); server stopped 01:43:5x
-- tip af1be44cce (server started ~01:44:05) --
2026-11-20T01:44:13.095Z GET /api/oauth/usage 200 passed                         server start-up reading
2026-11-20T01:45:10.435Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   T2 limited (Cancel auto-resume 01:45:21.524)
2026-11-20T01:45:46.001Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   T3 limited (sidebar Snooze, In 1 hour 01:46:25.258)
2026-11-20T01:45:46.502Z GET /api/oauth/usage 200 passed                         reading taken with the limit
2026-11-20T01:46:57.152Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   T4 limited (Archive thread 01:47:06.183)
2026-11-20T01:46:57.622Z GET /api/oauth/usage 200 passed                         reading taken with the limit
2026-11-20T01:47:14.189Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   T5 limited
2026-11-20T01:47:23.550Z POST /v1/messages 200 passed model=claude-haiku-5-5     T5 new message "Status?" ran as an ordinary turn
2026-11-20T01:47:53.494Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   T6 limited (sidebar Settle 01:48:03.545)
2026-11-20T01:48:31.027Z POST /v1/messages 429 INJECTED model=claude-haiku-5-5   T1 limited (no guard)
2026-11-20T01:48:31.517Z GET /api/oauth/usage 200 passed                         reading taken with the limit
2026-11-20T01:50:35.675Z GET /api/oauth/usage 200 passed                         FRESH READING 1 (Refresh provider status 01:50:35.045)
2026-11-20T01:50:39.175Z POST /v1/messages 200 passed model=claude-haiku-5-5     T1 early continuation, the only turn request on that reading
2026-11-20T01:52:38.863Z GET /api/oauth/usage 200 passed                         FRESH READING 2 (Refresh provider status 01:52:38.251)
                                                                                 no turn request through 01:54:40 (watch end)
The arm file was set to 1 before each thread's send and reset to 0 at its limit; no other 429 was injected.

Server runs on af1be44cce, from the server's own events:

2026-11-20T01:45:09.721Z T2 run 1 user message preparing
2026-11-20T01:45:09.812Z T2 run 1 user message starting
2026-11-20T01:45:10.510Z T2 run 1 user message failed
2026-11-20T01:45:45.365Z T3 run 1 user message preparing
2026-11-20T01:45:45.414Z T3 run 1 user message starting
2026-11-20T01:45:46.068Z T3 run 1 user message failed
2026-11-20T01:46:56.499Z T4 run 1 user message preparing
2026-11-20T01:46:56.570Z T4 run 1 user message starting
2026-11-20T01:46:57.194Z T4 run 1 user message failed
2026-11-20T01:47:13.545Z T5 run 1 user message preparing
2026-11-20T01:47:13.591Z T5 run 1 user message starting
2026-11-20T01:47:14.254Z T5 run 1 user message failed
2026-11-20T01:47:21.943Z T5 run 2 user message starting
2026-11-20T01:47:30.691Z T5 run 2 user message completed
2026-11-20T01:47:52.849Z T6 run 1 user message preparing
2026-11-20T01:47:52.898Z T6 run 1 user message starting
2026-11-20T01:47:53.540Z T6 run 1 user message failed
2026-11-20T01:48:30.349Z T1 run 1 user message preparing
2026-11-20T01:48:30.395Z T1 run 1 user message starting
2026-11-20T01:48:31.090Z T1 run 1 user message failed
2026-11-20T01:50:37.677Z T1 run 2 limit-resume (early) starting
2026-11-20T01:50:46.376Z T1 run 2 limit-resume (early) completed
2026-11-20T01:46:25.265Z thread.snoozed T3
2026-11-20T01:47:06.201Z thread.archived T4

T6 was settled before T1 was limited, so before both readings.

Tests. runtimeLayer.test.ts arms a recovery 3 hours before its reset and checks that only a fresh all-clear reading sends it early, once per limit episode. ClaudeCapabilitiesProbe.test.ts checks the reading's date. vp test run of runtimeLayer.test.ts, UsageLimitRecoveryWorker.test.ts, ProjectionStore.test.ts and ClaudeCapabilitiesProbe.test.ts in apps/server and threadExecution.test.ts in packages/client-runtime, on main 5872b0a488's production files with the test files of 2ee818787c, Node 26.13.1, macOS:

 FAIL  src/orchestration-v2/ProjectionStore.test.ts > SQL limit recovery loads armed threads before their reset
 FAIL  src/orchestration-v2/ProjectionStore.test.ts > ProjectionStoreV2 > projects only the latest failed root turn's limit into SQL and memory shells
 FAIL  src/orchestration-v2/UsageLimitRecoveryWorker.test.ts > idle sweeps skip SQL until the next wake time or a relevant event
 FAIL  src/orchestration-v2/runtimeLayer.test.ts > usage-limit recovery > preserves early recovery with global auto-resume off when retry reports reset: true
 FAIL  src/orchestration-v2/runtimeLayer.test.ts > usage-limit recovery > preserves early recovery with global auto-resume off when retry reports reset: false
 FAIL  src/provider/ClaudeCapabilitiesProbe.test.ts > dates a Claude usage reading by the cache entry it answered from
 FAIL  src/provider/ClaudeCapabilitiesProbe.test.ts > dates a Claude usage reading by a cache another session replaced during…
 FAIL  src/provider/ClaudeCapabilitiesProbe.test.ts > dates a Claude usage reading by a config dir relative to the probe's cwd
 FAIL  src/provider/ClaudeCapabilitiesProbe.test.ts > dates a Claude usage reading by the HOME the probe runs with
 FAIL  src/provider/ClaudeCapabilitiesProbe.test.ts > dates a Claude usage reading by nothing when the cache cannot be read
 FAIL  src/provider/ClaudeCapabilitiesProbe.test.ts > dates a Claude usage reading by nothing when the cache read does not an…
 Test Files  4 failed (4)
      Tests  11 failed | 265 passed | 1 skipped (277)
 FAIL  src/state/threadExecution.test.ts > thread execution presentation > derives the current root failure without inheriting errors from children or previous runs
 Test Files  1 failed (1)
      Tests  1 failed | 36 passed (37)

Two of them fail at the 120 s test timeout: on main the awaited event never comes.

ff55baa008 merges main 7d517188bd. Its one conflict, in ClaudeProvider.ts, keeps both sides: main's configurable Claude probe timeout and this branch's Claude Code cache file path. 33f3ef5fd4 merges main bc7fe11002; main had added the same HostProcess import to ClaudeProvider.ts (65e4272db1), so that merge keeps main's. af1be44cce merges main 5872b0a488, as above. The checks ran on 2ee818787c, an unsigned rebuild with the same parents and tree (e1c75f6390) as af1be44cce.

Prior PRs

takeover verification

Note

Written by gpt-6.1-sol on behalf of Maria

addressed the remaining cross-provider finding: reset waits now stay with the early retry's run id. early dispatch already records that id, so bounded retries remain intact. the pending-request receipt finding was already fixed by request-id rotation and remains covered.

fixed the saved-reset cancel-control issue in the shared error summary. both server shells and loaded web/desktop/mobile runtimes now use the matching recovery reset when an early retry omits one. explicit provider resets still take precedence.

merged github/main without rebasing and pushed two scoped fix rounds to the contributor's existing branch. final head: 9f7544a658676a72f48e648853490f1b5c9340dc. github reports CLEAN/MERGEABLE; all checks passed or were skipped, with none pending or failing. two independent source reviews found no remaining blockers. no unresolved review threads.

That was the takeover head. The PR head is now af1be44cce.

blacksmith check:changed passed format, lint, both knip checks, graphql, 35 package typechecks, and 196 tests. regressions failed before their fixes. no new test files.

playwright with system chrome verified the loaded client can cancel, rearm, snooze, and wake through the real server. the matching before/after captures use seeded early-retry state with no provider reset. this proves the control and mutation path, not real exhausted-provider allowance restoration. real allowance restoration, native clients, and relay/tunnel remain unverified this pass. the date-parsing nit is deferred to preserve scope.

before: missing reset hides recovery controls

after: saved reset restores cancel and snooze controls

cancel, rearm, snooze, and wake persist through the client and server

Fixes pingdotgg/t3code#22307

Generated with Claude Opus 5.5 in T3 Code Nightly

    1. Pushedaf1be44

    2. Note

      🤖 Opus 5.5 replying on behalf of Victor.

      I merged main 5872b0a488 into 33f3ef5fd4 as af1be44cce. The one conflict, in threadExecution.ts from #37419, keeps main's new threadErrorSummary call and lastErrorSource line, with this branch's two recovery arguments appended to that call. No other line of the fix changed.

    3. Note

      🤖 Opus 5.5 replying on behalf of Victor.

      Closing this PR to keep my open PR list small and focused on current fixes.

Sign in to join this conversation.