Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): delegated completions wait behind a parent usage limit #41896

Openjuliusmarmingewants to merge 2 commits intomain fromrefs/pull/41896/headopened View on GitHub

juliusmarmingecommented

When a delegated task finished while its parent thread was stopped on a provider usage limit, the completion wake-up started a new run immediately. It hit the limit again and cancelled the auto-resume the user had armed. Now the wake-up queues behind the usage-limited run while the limit's reset is still in the future or auto-resume is armed, and it runs after the resumed turn.

  • Orchestrator dispatch queues a queue_after_active delegated completion behind the provider's usage-limit-blocked run when there is no active run.
  • The blocked-run lookup moved out of usageLimitHoldsQueue into usageLimitBlockedRunForProvider so both places share it.
  • A test in DelegatedCompletionDelivery.test.ts arms auto-resume on a limited parent, sends the wake, and checks that the wake stays queued and auto-resume still starts after the reset.

Fixes pingdotgg/t3code#41583

Supersedes #41892. The change is @zs-andy's; their commits are kept.

Reproduction on main

In the desktop app, start a Codex parent task that delegates work to another provider. Let the parent hit a usage limit while its child remains running, then select Resume at reset. Have the child finish before the reset: main wakes the parent, fails again, and changes the banner back to Resume at reset; this change should keep the completion queued and preserve the armed reset continuation. These steps were read from the issue and regression test, not executed.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • vp test run src/orchestration-v2/DelegatedCompletionDelivery.test.ts (apps/server): 69 passed
  • Same test with the usageLimitWaitingRun queue rule removed: the new test fails with expected 'starting' to equal 'queued' (fix proven)
  • vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (5 files, 108 tests) all pass

Not in this change

  • Notification (non-delegated) wake-ups that arrive behind a usage-limited parent are not queued here; the broader #41888 covers them.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

    1. tanstack-source added labelsbug

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: 8a9e8d1 · PR result: fa33e81 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. The automated pipeline stopped on this pull request and will not merge it:

      the fix is written and reviewed, but proving it needs something no worker has:

      • Permanent blocker: the reproduction requires first-party ChatGPT OAuth for a Codex parent to hit its subscription usage limit and arm Resume at reset. The brief explicitly lists first-party Claude and ChatGPT OAuth usage, limit, and renewal flows as unavailable on every VM. Generic ACP replay cannot reproduce those conditions. Completion queuing, preservation of armed auto-resume, and delivery after recovery remain unverified on both commits.

      It stays open for a person to finish or close.

    4. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The orchestrator now checks for a usage-limit-blocked run when dispatching a delegated-completion wake. The wake stays queued if the reset is pending or auto-resume is armed for that run. A test covers this behavior.

      Changes: Delegated completion handling

      Layer / File(s)Summary
      Usage-limit run lookup
      apps/server/src/orchestration-v2/Orchestrator.ts
      A helper finds a provider’s usage-limit-blocked run. The existing queue-hold check uses this helper.
      Delegated completion queue placement
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
      When there is no active run, a delegated completion stays queued behind a usage-limited run if its reset is pending or auto-resume is enabled for that run. The test verifies that the wake remains queued while auto-resume starts.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested labels: bugfix

      Suggested reviewers: stienswout, navidnadali, nsigel

      Merge Risk: Minimal · up to fa33e

      This change keeps a subagent's completion queued behind a usage-limited parent run, so an armed auto-resume is no longer cancelled. A regression test covers the main scenario. No concrete merge-blocking risk remains.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: delegated completions now wait behind a parent usage limit. It follows the conventional commit format. The changeset adds a queue rule in Orchestrator.ts and a regress…
      Description checkPassedThe description follows the template. It states the problem, the change, and the scope with a link to issue #41583. It also gives verification steps and results, and it names the model and harness. Th…
      Linked Issues checkPassedLinked issue #41583 is the only active direct target. Its coding requirement: a subagent completion must not cancel the parent's armed auto-resume while the parent is usage-limited. The PR summary sta…
      Out of Scope Changes checkPassedThe reviewed changes, as described in the summary, touch two areas: Orchestrator.ts (usageLimitBlockedRunForProvider helper extracted from usageLimitHoldsQueue, and a queue rule for delegated completi…
      Full details: Title check

      Explanation

      The title names the main change: delegated completions now wait behind a parent usage limit. It follows the conventional commit format. The changeset adds a queue rule in Orchestrator.ts and a regression test, and both match the title.

      Full details: Description check

      Explanation

      The description follows the template. It states the problem, the change, and the scope with a link to issue #41583. It also gives verification steps and results, and it names the model and harness. The Evidence section says real-app before/after capture is still pending. The template requires screenshots or recordings for UI changes, and this fix is server-side, so the gap is minor. The Problem section also has no explicit reproduction steps from the author's own run, and the author states these steps were not executed.

      Full details: Linked Issues check

      Explanation

      Linked issue #41583 is the only active direct target. Its coding requirement: a subagent completion must not cancel the parent's armed auto-resume while the parent is usage-limited. The PR summary states that Orchestrator dispatch now queues a queue_after_active delegated completion behind the usage-limited run when the reset is in the future or autoResume is armed for that run. The PR summary also states that the new DelegatedCompletionDelivery.test.ts case arms auto-resume, sends the wake, and asserts the wake stays 'queued' and auto-resume starts after the reset. The author reports 69 passing tests and a failing mutation check ('starting' vs 'queued') when the usageLimitWaitingRun queue rule is removed. This keeps the completion from starting a run that would re-hit the limit, which matches the issue's expected behavior. The issue's 'ideally' wording (hold the result, do not wake the parent) is met in substance by queuing; the parent is not started by the completion. Limits of this review: the repository diff for Orchestrator.ts could not be read (changed blobs unavailable), so the code-level claims rest on the supplied summary and the author-reported test results. The real-app before/after evidence is pending, but it is not a coding requirement.

      Full details: Out of Scope Changes check

      Explanation

      The reviewed changes, as described in the summary, touch two areas: Orchestrator.ts (usageLimitBlockedRunForProvider helper extracted from usageLimitHoldsQueue, and a queue rule for delegated completions with no active run) and DelegatedCompletionDelivery.test.ts (a regression test). The helper refactor is shared by the new rule and the existing check, so it supports the same objective. The test directly exercises the objective. The PR explicitly excludes notification (non-delegated) wake-ups, which are tracked in #41888, so their absence is not an out-of-scope change. No unrelated change is described. Limit: the diff hunks could not be read in this session, so this verdict relies on the summary and PR description.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 8a9e8d12a86fd5640a609ea277afba948a9470dd and fa33e8186c880ed52f6470c4df8fbfdb3bb0fb54.

      Files selected for processing: 2

      • apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
      • apps/server/src/orchestration-v2/Orchestrator.ts

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

Sign in to join this conversation.