fix(server): subagent completion no longer cancels a usage-limited parent's armed auto-resume #41888
Closedfour1er(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/41888/headopened View on GitHubfour1er(GitHub profile, opens in a new tab) linked this to fix #41583
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelstakeover:in-progress
- @@ -8279,3 +8307,4 @@82798307 // A restart cancels its run; nobody knows whether the provider read the steer, so a person decides.82808308 ...(worktreeMissingRun !== undefined ||82818309 steerFollowUpSource?.status === "cancelled" ||8310+ limitedRunForAutomaticWake !== undefined ||
Pushed35827e8
- @@ -8075,5 +8084,20 @@8075- const pendingMergeBackTransfers = pendingMergeBackTransfersForThread(projection);80768084 const startsOrQueuesRun =80778085 dispatchMode.type === "defer_start" ||80788086 dispatchMode.type === "start_immediately" ||80798087 dispatchMode.type === "queue_after_active";8088+ // An automatic wake (buffered provider output included) that starts while an8089+ // auto-resume is armed would fail on the same limit and drop it. Hold the wake8090+ // behind the limited run; the resumed run's completion releases it.8091+ const armedRecovery = projection.thread.limitRecovery;8092+ const limitedRun =8093+ activeRun === undefined &&8094+ armedRecovery?.autoResume === true &&8095+ command.createdBy === "agent" &&8096+ command.usageLimitContinuationOfRunId === undefined &&8097+ (command.delegatedCompletion !== undefined || command.notification !== undefined) &&8098+ startsOrQueuesRun &&8099+ usageLimitHoldsQueue(projection, modelSelection.instanceId, yield* DateTime.now)8100+ ? usageLimitBlockedRunForInstance(projection, modelSelection.instanceId)8101+ : null;8102+ const limitedRunForAutomaticWake =8103+ limitedRun !== null && limitedRun.id === armedRecovery?.runId ? limitedRun : undefined;
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
four1er(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough
The orchestrator now holds qualifying agent-created wakes behind a usage-limit-blocked run when auto-resume is armed. Tests cover delegated-completion, background-task, and buffered provider-notification wakes during recovery.
Changes: Usage-limit recovery wake queue
apps/server/src/orchestration-v2/Orchestrator.ts,apps/server/src/orchestration-v2/runtimeLayer.test.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Possibly related PRs
usageLimitHoldsQueuereports a limited provider.Suggested reviewers:
juliusmarminge,alb11747Merge Risk:
Low · up to
35827The change keeps a usage-limited parent's armed auto-resume intact when a subagent finishes early. A server restart in a narrow window after the continuation completes could delay delivery of the subagent result until another run on the thread completes. The risk is bounded and recoverable, so the change is mergeable with owner awareness of that follow-up.
Pre-merge checks:
4
#41583. Change explains the hold mechanism and the exem…#41583] Requirement: a subagent completion that arrives while the parent is usage-limited must not cancel the armed auto-resume. The parent must resume at reset with the subagent result available. Th…Full details: Title check
Explanation
The title names the main change: a subagent completion no longer cancels a usage-limited parent's armed auto-resume. The raw summary shows dispatchMessage now holds qualifying automatic wakes behind an armed usage-limit recovery, which matches the title. The title is 93 characters, slightly long, but it is specific and conventional.
Full details: Description check
Explanation
The description follows the template sections (Problem, Change, Scope, Verification). Problem states the bug and reproduction context, and links
#41583. Change explains the hold mechanism and the exemptions. Scope names one bug fix and links the issue. Verification lists focused test results, pre-existing failures, and what was not verified. The template's Verification section asks for focused checks and observed results, which the description gives. The template's agent attribution line is present as 'Built with Muse Spark via Muse.' The description is mostly complete.Full details: Linked Issues check
Explanation
[
#41583] Requirement: a subagent completion that arrives while the parent is usage-limited must not cancel the armed auto-resume. The parent must resume at reset with the subagent result available. The issue also states that ideally the parent should not be woken before reset and the result should be held for delivery on resume.Evidence: The whole-PR summary for apps/server/src/orchestration-v2/Orchestrator.ts states that dispatchMessage holds agent-created notification or delegated-completion wakes when no run is active, auto-resume is armed, and the provider instance is still usage-limit blocked. The held message queues behind the limited run with queueHeld set. No new limited run is created, so the armed limitRecovery is not replaced. The PR description states that releaseUnattendedHolds releases the held wake after the reset continuation run completes. This matches the issue's expected behavior and its 'ideally not woken' preference.
Tests: The summary of runtimeLayer.test.ts describes tests that assert the wake stays queued and held, limitRecovery is unchanged, the reset resume targets the original run, and the held wake starts after that run completes. The PR reports that these tests fail on unfixed code and pass with the fix.
Limits: The Orchestrator.ts diff could not be read. The repository diff returned unavailable, and the file read at head is truncated at 16000 bytes with no line range. The dispatchMessage logic is therefore established from the summary, not from source lines. The summary and PR description conflict on buffered provider notifications: the PR description says they are exempt, while the test summary says they stay held. The issue does not state a requirement for buffered notifications, so this conflict does not change this verdict. The live end-to-end scenario is not verified.
#18928is a different trigger and is not required here.Full details: Out of Scope Changes check
Explanation
The changed files, per the summaries, are apps/server/src/orchestration-v2/Orchestrator.ts and apps/server/src/orchestration-v2/runtimeLayer.test.ts. The Orchestrator.ts change adds the usage-limit hold to dispatchMessage for agent-created wakes. It exempts user messages and the usage-limit resume dispatch. It extracts usageLimitBlockedRunForInstance from usageLimitHoldsQueue so that the hold path and the existing usage-limit check use the same limited-run lookup. This extraction supports the hold path and is not an unrelated refactor. The test additions verify the
#41583behavior. The Orchestrator.control-reads.test.ts failures (statement.stat is not a function) are reported as failing identically on clean main, so they are not caused by this PR.Limits: The Orchestrator.ts diff could not be read, so the scope of the code change rests on the summaries. The buffered-notification exemption conflict noted in the linked-issue assessment is a behavior detail within the same hold feature, not a separate unrelated change.
Finishing Touches
Generate unit tests (beta)