Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): stop each delegated child conversation once #18826

Mergedsaphid(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/18826/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

Problem

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.ts cases 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 on main to 3/4 in every case (base). All three descendants still end with interrupted runs and Stop receipts. 13 passed (log), rerun after rebasing on current main.
  • vp lint and apps/server typecheck: 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

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 37dba4a

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/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

      stopDelegatedTasks now 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.ts
      The 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: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Linked Issues checkWarningIssue [#20342] requires Stop to skip already-finished delegated tasks and visit each child thread once. The change satisfies the second requirement by tracking childThreadId values in `stoppedChildT…Update stopDelegatedTasks to exclude terminal delegated tasks, including completed, failed, and cancelled tasks, before dispatching thread.stop. Add a regression test with terminal tasks that reference distinct child threads and assert …
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Out of Scope Changes checkPassedThe pull request changes only stopDelegatedTasks and adds a focused regression test. The child-thread de-duplication and its traversal-count assertions directly support issue [#20342]. No unrelated …
      Title checkPassedThe title clearly and concisely describes the primary performance change: stopping each delegated child conversation only once.
      Description checkPassedThe 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 stopDelegatedTasks and 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 tracking childThreadId values in stoppedChildThreadIds. It does not inspect task.status, so a completed, failed, or cancelled task with a distinct child thread still triggers thread.stop and 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 stopDelegatedTasks to exclude terminal delegated tasks, including completed, failed, and cancelled tasks, before dispatching thread.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
      Comment `@coderabbitai help` to get the list of available commands.
    4. 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_cancel contract 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.

Sign in to join this conversation.