perf(server): stop each delegated child conversation once #18826
main fromrefs/pull/18826/head·merged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHubProblem#
Sending a follow-up to a delegated task reuses its child thread and adds another task row pointing at the same childThreadId. When the parent is stopped, stopDelegatedTasks walks every task row and recurses into the child's descendants each time. With k rows per child along a depth-d chain, that is k + k² + … + k^d dispatches and projection reads. Three nested descendants with eight follow-ups each cost 584 Stop dispatches and 585 projection reads instead of 3. Receipts deduplicate the repeated stops, but the traversal still delays descendant cancellation and holds the parent's effect lane.
Change#
stopDelegatedTasks skips child thread IDs it has already stopped at that level, so each child conversation and its subtree is visited once per Stop. Command IDs, reasons, and "try every sibling, then report the first failure" behavior are unchanged.
Scope and approval#
A small, focused performance fix (4 lines), so it uses the no-prior-issue exception.
Verification#
At 37dba4a0fd, integrated with upstream 70d60e03a7 on macOS, 2026-10-17:
- Focused selection:
vp test run apps/server/src/orchestration-v2/ThreadStop.test.ts: 22 passed (22). - Targeted lint and formatting pass; package typechecks pass for
apps/server. - Fresh read-only integration review by GPT-6.1 Sol (high), Codex through T3 Code: no remaining actionable findings for this exact tree. Claude quota prevented a new cross-model review.
- Current-head CI is green and Macroscope approved this exact head. The completed native fingerprint run passed; an older duplicate was cancelled. No new UI/native capture or live-provider verification was performed in this integration pass. Earlier media, measurements and fail-before results below retain their recorded revisions and limitations; they do not certify this head. Existing proof gaps remain.
Earlier verification#
- New
ThreadStop.test.tscases run the real service with SQLite projections and receipts, seeding duplicate task rows through the projection store. For 1, 2 and 8 rows per child, dispatches/reads go from 3/4, 14/15 and 584/585 onmainto 3/4 in every case (base). All three descendants still end with interrupted runs and Stop receipts. 13 passed (log), rerun after rebasing on currentmain. vp lintandapps/servertypecheck: clean.- Independent review by Claude Opus 5.5 (high) through a T3 delegated task: no defects. It checked receipts, retries, both service callers and nested traversal.
Found by a GPT-6.1 Sol (high) audit and implemented by GPT-6.1 Sol (high) in T3 Code. Reviewed by Claude Opus 5.5. Coordinated by Claude Opus 5.5 in Claude Code via T3 Code. Agent-authored, sponsored by Alex Southwell.
🤖 Generated with Claude Code
Fixes #20342
Integration and publication: GPT-6.1 Sol (high), Codex harness through T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
37dba4aMacroscope's review found this PR approvable — This is a small, self-contained performance fix that deduplicates repeated delegated-child stop traversal without changing distinct-child behavior. Focused tests verify that every unique descendant is still stopped exactly once.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
831096f9-a9b0-44ff-b2c0-e6f55eed187c
📥 Commits
-
Reviewing files that changed from the base of the PR and between 4f825ce8f68659f0a3077c22366038758d6f730d and 37dba4a0fd011b8dd7a206e39bd8c5c555e4b826.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/ThreadManagementService.tsapps/server/src/orchestration-v2/ThreadStop.test.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.
-
📝 Walkthrough
-
stopDelegatedTasksnow skips child thread IDs already processed during the same invocation. Tests cover descendant stopping and record reads across a three-level delegation chain with varying counts of historical tasks per child.Changes: Delegated thread stopping
Layer / File(s) Summary Distinct child traversal
apps/server/src/orchestration-v2/ThreadManagementService.ts,apps/server/src/orchestration-v2/ThreadStop.test.tsThe stop traversal skips child thread IDs it has already processed. Parameterized tests verify descendants are stopped once, persisted as interrupted with stop-command receipts, and read once across cases with 1, 2, or 8 historical tasks per child. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
37dba-
The delegated-child stop change is mergeable after normal checks.
Security architecture risk: 🔵 Low · up to
37dba-
The change reduces repeated cancellation work without expanding access or privileges. Under a transient failure, however, duplicate references no longer provide another cancellation attempt within the same request. Errors remain visible, and later cancellation attempts can recover.
Retained concerns
- Low · reliability · inferred: Marking a child visited before its stop and descendant traversal succeed removes same-request recovery through duplicate historical rows. If an attempt fails transiently before persistence or during recursive traversal, later references now skip the unfinished work. Direct MCP cancellation reports the partial failure but performs no internal retry, so descendants can remain active until another cancellation attempt. Worker retries and repeatable MCP cancellation limit the exposure.
Security review details
-
Security Blast Radius
- inferred — The identified failure-containment exposure concerns app-owned descendants of the thread being cancelled. The new set is local to one traversal invocation and neither broadens target selection nor grants authority over additional threads.
Trust Boundaries and Controls
- observed — Child command IDs remain derived from the initiating command and child identity. Existing dispatch handling replays accepted receipts for the same thread, rejects conflicting or previously rejected commands, and serializes dispatch under the target thread's lock.
Resilience and Maintainability Implications
- observed — The worker reschedules failed delegated-stop effects until its attempt limit, allowing a fresh traversal. Direct MCP cancellation instead returns an explicit partial-failure error; its terminal-task branch still permits another stop traversal. These are recovery paths, not guarantees that every failed cancellation will be retried.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Linked Issues check Issue [ #20342] requires Stop to skip already-finished delegated tasks and visit each child thread once. The change satisfies the second requirement by trackingchildThreadIdvalues in `stoppedChildT…Update stopDelegatedTasksto exclude terminal delegated tasks, including completed, failed, and cancelled tasks, before dispatchingthread.stop. Add a regression test with terminal tasks that reference distinct child threads and assert … Passed checks: 3 passed-
Check name Status Explanation Out of Scope Changes check The pull request changes only stopDelegatedTasksand adds a focused regression test. The child-thread de-duplication and its traversal-count assertions directly support issue [#20342]. No unrelated …Title check The title clearly and concisely describes the primary performance change: stopping each delegated child conversation only once. Description check The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the behavior, implementation, approval exception, focused tests, and verification limi… Full details: Out of Scope Changes check
-
Explanation
The pull request changes only
stopDelegatedTasksand adds a focused regression test. The child-thread de-duplication and its traversal-count assertions directly support issue [#20342]. No unrelated change is shown.
Full details: Description check
-
Explanation
The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the behavior, implementation, approval exception, focused tests, and verification limits.
-
Full details: Linked Issues check
-
Explanation
Issue [
#20342] requires Stop to skip already-finished delegated tasks and visit each child thread once. The change satisfies the second requirement by trackingchildThreadIdvalues instoppedChildThreadIds. It does not inspecttask.status, so a completed, failed, or cancelled task with a distinct child thread still triggersthread.stopand recursive traversal. The added test covers duplicate historical rows for the same child, but it does not prove that terminal tasks with distinct child threads are skipped.Resolution
Update
stopDelegatedTasksto exclude terminal delegated tasks, including completed, failed, and cancelled tasks, before dispatchingthread.stop. Add a regression test with terminal tasks that reference distinct child threads and assert that those threads are not stopped or traversed.
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Checked these leads against the current head,
37dba4a0fd.The maintainer direction tracks this issue under the child-conversation deduplication in this PR. A terminal task result does not mean its backing conversation is inactive: the existing
task_cancelcontract deliberately stops later child runs and descendants even after a task is terminal. The integration test covers a completed task with an active follow-up. Filtering terminal task rows would change that supported Stop behavior, so I am keeping the distinct-child traversal.Deduplication does remove incidental repeat attempts supplied by duplicate historical rows. That is a real limit, but those rows were not a dependable retry policy: the previous traversal still returned failure after any caught error, even if a later duplicate succeeded. The Stop worker can retry failed invocations within its configured limit; direct MCP cancellation reports partial failure and permits another cancellation. Neither guarantees recovery from persistent failure. No retry machinery is added here.
Fresh read-only GPT-6.1 Sol high review through T3 completed with no actionable findings on the full two-file diff. This was a same-model independent review; no new cross-model review was available. Current-head checks pass and Macroscope approved the exact head.
Yash-Singh1(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed