Repository navigation
refactor(server): one completion decision for both cohort owners - #471
Merged
tannerpolley merged 2 commits intoNov 18, 2026
Merged
Conversation
Issue closeout moves from ForkDelegatedCompletion into IssueCommentEffects. The "result still owed work" decision behind task_status, wait and the parent wake now has one owner (ForkDelegatedCompletion.taskResultPending). Finalize reuses delegatedCompletionPlanEvents instead of an inline copy. Fix: a late, unobserved result read of a thread-owned (run-less managed) task acknowledged it and dropped it from the queued wake. It now follows upstream's late-read rule for both owners. Narrows reads: run-less admission reads only the parent thread row, reuseManagedChild reads only the current owner's task, and the closed-child pending check reads only this task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannerpolley
marked this pull request as ready for review
November 18, 2026 01:43
tannerpolley
deleted the
issue-435-418-step-3-unify-managed-completion-and
branch
November 18, 2026 01:43
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Step 3 of #418 asks for one completion path for both cohort owners: ordinary delegation keeps its cohort on the parent run, and run-less managed admissions keep it on the parent thread. Three pieces still sat in the wrong place or were duplicated:
task_status, wait and the parent wake was split betweenOrchestrator.tsand the fork helper;delegatedCompletionPlanEvents.Writing tests for both owners also found a real defect. A late, unobserved result read of a thread-owned task (
observedByRunId: null, for example a wait that ends after its turn did) acknowledged the result and dropped it from the queued wake, so the parent never saw it. Upstream's rule from PR pingdotgg#32573 (36d0dcbf55, wake idle parents for late delegated results) says an unseen read must not acknowledge a result; the fork's 2026-11-11 sync merge (436c0d0f32) had exempted run-less tasks from it.Fix
makeIssueCloseoutinissues/IssueCommentEffects.ts.issueCloseoutEffectis now private to it, andForkDelegatedCompletionno longer imports issue code. The span nameOrchestrator.publishIssueCloseoutis kept.taskResultPendingnow also covers the untagged case (progress with shell background tasks, then recovery continuation).Orchestrator.delegatedTaskResultPendingreads the child and calls it.task.runId !== nullexemption indispatchDelegatedTaskCompletionDeliveryResolution. Run-less tasks now follow the same late-read branch as run-owned ones. The existing post-commitofferDelegatedCompletionDeliveriesalready covers the thread cohort.reuseManagedChildreads only the current owner's task (subagentChildThreadIds), not all of the previous parent's subagents;taskResultPendingreads only this task (subagentIds), not all of the parent's subagents.readDelegatedCompletionPlanRecords);Closes #435. Part of #418 (step 3 of 4).
Rollout (owner decision)
The late-read fix changes result hand-back, so before the first rollout that includes it:
set_repository_work_paused).In-flight restart recovery is still covered by the fixture tests below; the pause and drain are the owner's choice, not a substitute for them.
Evidence
Case ledger. All new tests are in
DelegatedCompletionDelivery.fork.test.tsand run each case for both owners (run and thread). They extend the existing thread-owned restart test rather than adding a parallel file.restart recovery adds a second worker to a queued {run,thread}-owned delivery and settles both: a second worker joins the queued wake without a new message ID or generationa {observed,late} result read of a {run,thread}-owned task settles its queued wake only when seen. An observed read acknowledges and cancels the wake. A late read leaves the result claimed in the queued wake.a {run,thread}-owned worker that finishes after its parent was {archived,deleted,stopped}. Archived and deleted givedisposedwith no offer. A stopped run cohort givesdisposed.stoppedcase is the pre-#418 whole-mailbox stop. It reopens, and the result is reserved and offered with one message ID and generation. All fixtures are committed events, recovered byrecoverDelegatedTasks.a {run,thread}-owned worker whose workspace preparation fails wakes its parent with the failure: realdefer_startthenprepared-run.fail; waits on the persistedsubagent.updatedeventDelegatedCompletionDelivery.test.ts"holds a follow-up open while the child's own subagent still runs"No sleeps: tests use committed events,
recoverDelegatedTasks, and persisted-event streams.Failing first. Before the fix,
a late result read of a thread-owned task …failed withexpected 'acknowledged' to equal 'claimed'. The run-owned variant passed. After the fix, all 35 tests in the file pass.One changed expectation.
ThreadLaunchService.repositoryHandoff.fork.test.tssent an unobserved acknowledgement to an idle root, which has no run, and expected the result to leave the root's wake. That encoded the defect. It now expects the result to stay in the wake.Runs (
agent-heavy, Node from vite-plus fallback-bin):IssueCommentEffectsfiles gave 81/81. Files:.forkcopy;.forkcopy;vp run check:changed: format, lint, both knip runs and GraphQL pass. Tests: 118 passed across 7 files.scriptsandevalspass.apps/serverfails only onMcpHttpServer.test.ts(1711)(TS2375/TS377004), in a file this PR does not touch. Restoringorigin/main's versions of all six changed files reproduces the same two errors.df594d7fcb(PR fix(server): tool-hiding test provides the issue services it needs #473).Footprint: whole-file
Orchestrator.tsnumstat. These are fork totals, not issue-only counts.7d32075e37(plan pin)b387e3a179(newest sync, #469)ForkDelegatedCompletion.ts: +16 / −90. The other five shared files are unchanged.What remains, and which step owns it:
Orchestrator.tskeeps the cohort-owner accessor (completionCohort/completionCohortEvent) and the null-parentRunIdbranches the persisted thread cohort requires.recoverDeletedChildrenstill reads all of a recovering parent's subagents at startup. It was not in the two reads flagged in Server event loop stalls for up to 11 s every few minutes, and every request in flight stalls with it #367, so it is left as is.Merge Danger
Door: two-way. No migration and no persisted-format change. Rolling back restores the old late-read behavior.
Blast radius: delegated result hand-back for run-less managed workers. A late, unobserved read no longer acknowledges a result, so the parent sees it through its wake instead. Live userdata was not read or copied, and no dev server was started.
Implemented with Claude Opus 5.5 through the Claude Code harness in T3 Code.
🤖 Generated with Claude Code