Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): usage-limit auto-resume no longer arms subagents of archived or deleted parents #30363

Mergedspoukyii(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/30363/headmerged by maria-rcks View on GitHub

Problem

#27951 stopped the usage-limit recovery sweep from freshly arming a subagent whose parent is settled. The same query still arms a subagent whose parent is archived or deleted. With Resume after usage limits on (or snooze), that child is armed and resumed at its reset. It runs a full turn on the user's quota for a task whose parent the user has put away, and its completion cannot wake the parent: delivery to an archived or deleted parent is disposed. A deleted parent never comes back to read the result. An archived one keeps it on the parent's task, but nobody asked for the turn that produced it.

Agent-started subagent threads cannot take messages, so nothing but this sweep drives such a child. The query already treats an archived thread like a settled one when the thread itself is the candidate. Since #27951 it checks the parent's settled state too, but not its archived or deleted state.

Change

In getLimitRecoveryCandidates, the parent check that #27951 added now also matches a parent with archivedAt set or a non-null deleted_at, not just settledOverride = 'settled'. It covers both arm branches, auto-resume and snooze. The parent is still found by its primary key, only for rows that passed the usage-limit pre-filter.

As in #27951, the resume branch is unchanged, so a recovery armed before the parent was put away still resumes. Unarchiving the parent emits a thread.* event, which makes the sweep due again and offers the child once more, within the same limits as any fresh arm (auto-resume only within 24 hours of the reset, snooze only while the reset is still ahead).

Scope and approval

This is a small, focused fix for an obvious bug, so it needs no prior issue. It is one SQL condition plus #27951's existing test extended from two parent states to four. The harm differs from #27951's: there the resumed child reopened a settled parent, while here the wake is disposed and the cost is the quota spent on a turn for put-away work. The rule is the one the query already applies to the thread itself.

Related open work: #30175 cancels already-armed resumes of settled parents' children in Orchestrator.dispatchMessage. It does not touch this query, so the two do not conflict. If both merge, an already-armed resume of an archived or deleted parent's child still runs at its reset; that is a follow-up, kept out of this PR. #20072 cascades archive and delete to subagent descendants. It conflicts with main, does not touch this query, and would not cover children of parents archived before it lands.

Verification

apps/server/src/orchestration-v2/ProjectionStore.test.ts: the #27951 case, renamed does not freshly arm limit recovery for a subagent of a put-away parent, now builds four parent/child pairs (settled, archived, deleted, open parent) and checks that only the open parent's child is armed, under both autoResume and snooze.

On main with only the test commit (ce48080a22), from apps/server, vp test run src/orchestration-v2/ProjectionStore.test.ts -t "put-away parent":

× does not freshly arm limit recovery for a subagent of a put-away parent
AssertionError: only the child of the open parent is armed ({"now":"1970-01-01T00:00:00.000Z","autoResume":true,"snooze":false}): expected [ …(3) ] to deeply equal [ Array(1) ]
+   "thread:settled-parent-limit:archived:child",
+   "thread:settled-parent-limit:deleted:child",
Tests  1 failed | 50 skipped (51)

The settled child is already excluded on main, so the test fails only on the two new parent states.

With the fix, from apps/server:

  • vp test run src/orchestration-v2/ProjectionStore.test.ts src/orchestration-v2/UsageLimitRecoveryWorker.test.ts: 56/56 pass.
  • vp run check:changed from the repo root: format, lint, knip, graphql, typecheck (3 packages) and tests beside the change all pass.

What I could not check: a runtime transcript. Reaching this path on a running server needs a provider to hit a real usage limit with a reset time, which cannot be triggered on demand. The test drives the real projection store and its candidate query, which is the only code this PR changes. There is no visible surface, so there are no captures.

Bug: usage-limit auto-resume arms subagents of archived or deleted parents

This was written with Claude Opus 5.5 in Claude Code, driven from T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Walkthrough

      Limit-recovery candidate selection now excludes subagents whose parent is settled, archived, or deleted. Tests cover those parent states alongside active parents, including a settled-parent child with recovery already armed.

      Changes: Limit recovery

      Layer / File(s)Summary
      Parent-state filtering and test coverage
      apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProjectionStore.test.ts
      The limit-recovery query excludes subagents with settled, archived, or deleted parents. The test covers these states and active parents, and retains coverage for an already-armed child of a settled parent.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Possibly related issues

      • pingdotgg/t3code#27944: The issue describes fresh recovery arms for delegated children of settled parents, which this change excludes.

      Suggested labels: bugfix

      Suggested reviewers: juliusmarminge

      Merge Risk: Minimal · up to fa3f5

      Children of put-away parents are excluded from fresh recovery arms; already-armed recoveries remain unchanged. No material merge-blocking issue was identified.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: preventing usage-limit recovery from freshly arming subagents whose parents are archived or deleted.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe pull request description includes all required sections. It clearly explains the problem, the code change, scope and approval rationale, focused verification results, failed baseline behavior, lim…
      Full details: Description check

      Explanation

      The pull request description includes all required sections. It clearly explains the problem, the code change, scope and approval rationale, focused verification results, failed baseline behavior, limitations, and the agent and harness used.

      Finishing Touches
      Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      CodeRabbit Verify

      • Run CodeRabbit Verify to test the changes in this pull request.
      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 0b5600b1c3df49f705ba245df5aa50c59dc91490 and fa3f5c029e51a6c31f269ed8b272ee4002cf9068.

      Files selected for processing: 2
      • apps/server/src/orchestration-v2/ProjectionStore.test.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

    3. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      Partial verification of fa3f5c029e51a6c31f269ed8b272ee4002cf9068 on Linux. This is not a runtime verification of the recovery fix.

      • Installed and ran github/main (7c22e24e3f) in a separate worktree, stopped its captured server process, then installed and ran the exact PR head. Only one dev server ran at a time.
      • Drove the real web app using repository Playwright and /usr/bin/google-chrome. Added a project pointing at a real git checkout through the app. No mocks, fixtures, demo data, or database writes.
      • On both versions, real Codex gpt-6.1-sol parent turns and T3-delegated child turns completed through the local proxy.
      • On the PR, archived and unarchived the parent through the UI, then sent another real Codex message. It returned RESTORED_PARENT_OK. Both recovery preferences persisted through a page reload.
      • Ran the existing projection-store and recovery-worker tests through blacksmith-check: 56 tests passed across two files. No source changes or pushes.

      PR head: real Codex parent and delegated child completed

      PR head: archive, restore, and a real Codex follow-up

      Runtime transcript

      Not verified

      The original bug was not reproduced on main, and fresh recovery filtering for archived/deleted parents was not exercised on the PR. Neither environment produced a real usage_limit failure with resetAt. The first PR turn encountered a proxy 429, but it was a recoverable transport_error (responseStreamDisconnected) without a reset timestamp and then completed. That does not prove usage-limit recovery.

      Consequently, auto-resume and snooze fresh-arm exclusion, re-eligibility after unarchive, and already-armed reset-time continuation remain unverified in the running app. Exercising them requires a genuine provider usage-limit failure with an exhausted account window and reset time. I did not fabricate that state or intentionally exhaust quota.

      Native desktop, iOS/Android, other providers, and remote/relay connections were not exercised.

    4. maria-rcks merged this144b78a

    5. maria-rcks closed this

Sign in to join this conversation.