Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a usage-limited thread no longer auto-settles #28359

OpenEhsanulHaqueSiam(GitHub profile, opens in a new tab)wants to merge 13 commits intomain fromrefs/pull/28359/headopened View on GitHub

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

Problem

When a run stops on a usage limit, the auto-settle sweep can settle the thread in the same second. The run that kept the thread active has ended, so nothing holds it. Settle-on-merge passes whenever the PR merged after the last user-authored message, which is common when PR-watch or system wakes keep a thread working without a new user message. Inactivity settling hits the same thread when the reset is further out than the inactivity window. Settled threads are excluded from limit recovery, so "Resume at reset", "Snooze until reset" and an armed auto-resume all stop working, and the thread drops out of the active list right when it needs attention.

Seen in a real thread: run 4 failed with usage_limit at 20:46:13Z, and ThreadSettlementServiceV2.sweep dispatched thread.auto-settle at 20:46:13Z. Four recovery attempts at 20:49 to 20:51Z were all rejected. The user never sent a thread.settle.

Change

A usage limit interrupts work rather than finishing it, so the sweep now leaves such a thread alone, the same way it already does for pending runtime requests and link requests.

  • getSettlementCandidates (ProjectionStore.ts) skips a thread whose latest executed run failed and whose latest root error is usage_limit. It uses the same run selection as the shell's blocked join and getLimitRecoveryCandidates, so a message queued behind the limit does not hide it. Like threadErrorSummary, a newer session error that differs from the failure message replaces the limit, so the thread is then treated like any other failed thread. A cheap EXISTS on usage-limit error items runs first, so other threads skip the per-thread run sort.
  • isAutoSettlementCandidate applies the same rule to shell threads (status: "failed", lastErrorClass: "usage_limit"), so the candidate and the shell agree. Subagents are the exception: they reach the sweep only once their parent is put away, so abandoned limited subagents still settle for cleanup.

A thread that failed for any other reason still settles as before. Once the user sends a message or recovery resumes the thread, its latest run is no longer a usage-limit failure, so it becomes eligible again.

Why "never settle" rather than "settle after the reset"

A limited thread waits on the user, like a pending request, so it is handled the same way: it stays visible until someone acts, and the user can still settle it by hand. Exempting it only until the reset would need the reset time in both the SQL and shell candidates, plus a grace window so the sweep cannot settle the thread in the minute before auto-resume fires. That is more code for the case of a limited thread nobody returns to.

Scope

Fixes pingdotgg/t3code#28362 (auto-settle on PR merge settles a usage-limited thread, so "Resume at reset" and "Snooze until reset" always fail) and pingdotgg/t3code#18928 (inactivity auto-settle cancels a pending usage-limit auto-resume). This is one bug: the settle sweep defeats the existing usage-limit recovery. It adds no setting and no new behavior beyond keeping these threads unsettled. The banner and error-message side of #28362 is #28360.

Verification

  • ProjectionSettlement.test.ts › sql: discovers settlement work with the same activity and background semantics as the shell seeds a usage-limited thread, a thread with a message queued behind its limit, and a usage limit that ended after a newer failed run, all excluded, plus a provider_error thread and a limit superseded by a differing session error, both eligible. It fails on main (97cfc07759) and passes here.
  • vp run check:changed origin/main: format, lint, knip, graphql, typecheck and 107 tests pass.
  • Live, through the real Codex adapter: the real codex CLI pointed at a localhost stub that answers 429 usage_limit_reached, on an isolated server home, with the server clock moved so the 1-day inactivity window applies. On main both threads auto-settle (one on PR merge, one after 3 idle days). On this branch neither does, and both keep auto-resume armed. The transcript and the script are in the comments.
  • Not checked: an armed auto-resume firing at a real reset time, and a first-party Claude or ChatGPT account hitting a real limit. On main, limitRecoveryCommand returns nothing for a settled thread, so the armed resume cannot fire there; this is from the code, not observed.

Fixes pingdotgg/t3code#28362 Fixes pingdotgg/t3code#18928

Model and harness: Claude Opus 5.5 in Claude Code, run through T3 Code.

    1. Pushed9cda0f5

Sign in to join this conversation.