fix(server): delegated completions wait behind a parent usage limit #41896
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.
Orchestratordispatch queues aqueue_after_activedelegated completion behind the provider's usage-limit-blocked run when there is no active run.- The blocked-run lookup moved out of
usageLimitHoldsQueueintousageLimitBlockedRunForProviderso both places share it. - A test in
DelegatedCompletionDelivery.test.tsarms 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
usageLimitWaitingRunqueue rule removed: the new test fails withexpected '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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
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.
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.tsA 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.tsWhen 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:
bugfixSuggested reviewers:
stienswout,navidnadali,nsigel
Merge Risk:
Minimal · up tofa33e-
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:
4-
Check name Status Explanation Title check 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 regress… Description check 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. Th…Linked Issues check Linked issue #41583is 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 check The 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
#41583is 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/pr-41892
- File: .coderabbit.config.ts
- Commit: fa33e81
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
aee303e7-f21d-4873-aeed-0143c0ebf9ac
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.tsapps/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.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
short turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsshort turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsBaseline:
8a9e8d1· PR result:fa33e81· Source CI: successScenario 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.