# fix\(server\): usage-limit auto-resume retries a continuation refused right after the reset · PR \#33737 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/33737)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: open

Source repository: pingdotgg/t3code

Source branch: fix/issue-33708

Target branch: main

Head commit: edc9c03c8238d7a650f7d31b60571aea18a61e9c

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/33737)

[Commits](https://git.cafe/pingdotgg/t3code/pull/33737/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/33737/diffs?format=markdown)

## Description

---

## Problem

When usage-limit auto-resume sends "Continue where you left off." at the reset and the provider refuses that continuation with `usage_limit` and no reset later than now, recovery stops for good. Codex records the refusal with `resetAt: null`; a provider can also repeat the window that just expired. The recovery worker and its candidate query drop any failure without a reset later than the run's end, so the thread stays failed until the user continues it by hand.

Reproduced on main with the real orchestrator, event sink, SQLite projection and recovery sweep: run R0 fails `usage_limit` with a future reset, auto-resume arms and dispatches the continuation R1 at the reset, R1 fails `usage_limit` with a null or expired reset, and no continuation of R1 is ever created.

## Change

- A continuation that the provider refuses with no later reset now retries 2, 5 and then 15 minutes after the refusal. The fourth refusal in a row gives up and leaves the thread in today's failed state. The count comes from the existing `usageLimitContinuationOfRunId` chain, so there is no new persisted field, setting or wire field.
- One shared rule (`usageLimitRecoveryResetAt` in `packages/shared`) decides the retry time. Arm validation, continuation validation, Stop, the recovery worker and the candidate SQL all use it. The SQL bounds the chain with three indexed lookups, so a thread that gave up is no longer a candidate.
- A "Resume at reset" chosen for the refused run carries over to its retry. An automatic arm keeps a manual snooze that ends later than the retry time.
- The web banner and the mobile card show the armed retry time with **Cancel auto-resume**, and **Wake now** while the retry owns a snooze. After Cancel, Stop or giving up, they show the provider's reset as before. Worktree cleanup holds a thread while its retry is armed.
- The thread sidebar guide now says that a refused scheduled continuation is retried a few times.

## Scope and approval

Fixes pingdotgg/t3code#33708

## Verification

- New rows in `apps/server/src/orchestration-v2/runtimeLayer.test.ts` (suite `usage-limit recovery`, `retries a usage-limit continuation the provider refuses with …`): `no-reset`, `expired-reset`, `no-reset under a per-thread resume`, and `expired-reset past a later manual snooze`. They check that no continuation exists 1 ms before each deadline and that one exists at it. After the fourth refusal they check that the thread is not re-armed and is no longer returned by `getLimitRecoveryCandidates`, with global auto-resume on and off.
  - On the test-only commit `8bfc0a1c0d`: `2 failed`, `AssertionError: a refused continuation with no later reset should be retried after a backoff: expected undefined to not equal undefined`.
  - At `cbe1b7d96b`: all rows pass.
- New rows in `apps/server/src/storageCleanup.test.ts`: a missing or expired provider reset with an armed retry is held; the same with auto-resume off is not.
- New rows in `packages/client-runtime/src/state/threadExecution.test.ts` for the notice reset: armed retry, cancelled, after Stop, an owned snooze still pending, and one that has passed.
- Focused suites pass: `runtimeLayer`, `UsageLimitRecoveryWorker`, `ProjectionStore`, `Orchestrator.control-reads`, `DelegatedCompletionDelivery`, `TaskCancelUsageLimit.integration`, `storageCleanup`, `threadExecution`, `UsageLimitRecoveryCard`, `ChatView.logic`. `vp run check:changed` passes: format, lint, knip, typecheck of 35 packages, 14 test files, react compiler.

| State | Before | After | Diff0 | DiffT |
|---|---|---|---|---|
| Web banner and mobile card: refused continuation, retry armed | not attached | not attached | — | — |
| Web banner and mobile card: after Cancel or Stop | not attached | not attached | — | — |
| Web banner and mobile card: retry owns a snooze (Wake now) | not attached | not attached | — | — |
| SHA | `934c7f8d8e` | `cbe1b7d96b` | | |

Not checked: before/after captures of the web banner and mobile card in these states are not attached yet. The client change is covered only by the `threadExecution` rows above. A live provider refusal at a real reset was not exercised; the provider failure is injected as provider events.

AI-assisted; verified with the tests and tools listed above.


Fixes pingdotgg/t3code#22026

