Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a delegated result whose steer never landed wakes the parent after it settles #14732

Openjuliusmarmingewants to merge 11 commits intomain fromrefs/pull/14732/headopened View on GitHub

juliusmarmingecommented

A delegated result can remain reserved after its provider rejects a steer and the receiving run settles. That strands the unread result, or leaves an empty reservation blocking later siblings after the result was read.

Extend the existing delivery finalizer to reconcile delegated steers as well as initial delivery messages. Unread reservations are offered again; empty ones release pending siblings, including settled-only results when a queued user message starts. Recovery checks the current receiving run and open reservation under the thread lock, including persisted steers found during startup. A rolled-back receiver releases its reservation without waking work; unread results return to pending and acknowledged results stay acknowledged. A late continuation tied to a rolled-back originating or receiving run gets an accepted no-op receipt. Stop retains its existing stopped/disposed behavior.

Rebuilt from @juliusmarminge's original #14732, preserving its commits and merging current main. Removed the one-off 544-line test file and custom replay-harness changes. The final diff changes only the orchestrator and its existing delivery suite; notification acceptance, contracts, clients, and provider adapters are unchanged.

Verification on the rebuilt head:

  • Before: the existing suite passed 20 tests. The six focused regressions produced five assertion failures (three missing wakes, two rollback revivals); Stop already passed.
  • After: all 28 delivery tests pass, plus 122 adjacent tests across nine files in total, covering continuation delivery, run-completion reads, Stop, rollback, queue order, steering completion, bounded control reads, and command policy. The review follow-up reproduced a missing startup wake and a stale rollback reservation before fixing them.
  • Server typecheck, targeted lint, formatting, and diff checks pass. Lint retains two warnings in unchanged code.
  • Before/after behavior proof records the assertion failures and final passing run on 2fae83e2007592e39bfe8a096c8cef92824e1b62. The regressions start from persisted rejected-steer state and exercise the real event sink, run-update subscriber, continuation queue, acknowledgment, Stop, and message dispatch. They synchronize on persisted work rather than sleeps. They do not exercise actual provider retry timing.

Screenshots are not applicable to this server-only change. No live provider CLI or packaged macOS, Windows, Electron, iOS, or Android verification is claimed. The visible behavior is shared by all clients through the server. Human review of the asynchronous recovery and rollback semantics remains required before merging.

Two independent full-diff review rounds (Claude Opus 5.5 and GPT-6-Sol) found and verified fixes for startup recovery missing steers and rolled-back receivers retaining reservations. Round two found no blocking code issues. After merging main at 9f52dc28a9, the reviewed diff remained byte-for-byte identical and all 150 focused tests passed again.

Rollback intentionally offers no immediate wake, including for a never-seen pending sibling. If no sibling finishes later, pending results remain available through explicit task_status. This avoids starting a turn immediately after rollback and needs maintainer acceptance alongside the recovery/rollback semantics.

Implementation: GPT-6.1-Sol in the Codex harness through T3 Code. Tests: GPT-6-Astra. Independent reviews: Claude Opus 5.5 and GPT-6-Sol.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 9f52dc2 · PR result: 2fae83e · Source CI: success

      Scenario 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.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

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

      🟠 High orchestration-v2/Orchestrator.ts:8915

      A rollback that occurs before this handler acquires the lock does not stop the stale terminal event from re-offering its delegated delivery, so a discarded turn can start a continuation. The guard checks only the old settledRun.status; check the current projected run status and return when it is rolled_back.

             const projection = yield* projectionStore.getThreadRecords(threadId, ["runs", "subagents"]);
      +      const currentSettledRun = projection.runs.find((run) => run.id === settledRun.id);
      +      if (currentSettledRun?.status === "rolled_back") return;
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/orchestration-v2/Orchestrator.ts around line 8915:
      
      A rollback that occurs before this handler acquires the lock does not stop the stale terminal event from re-offering its delegated delivery, so a discarded turn can start a continuation. The guard checks only the old `settledRun.status`; check the current projected run status and return when it is `rolled_back`.
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This production patch changes delegated-completion wakeups, reservation state, rollback handling, and startup recovery across asynchronous orchestration paths. The focused tests improve coverage, but the scheduling and recovery semantics are sufficiently nontrivial to merit human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. juliusmarmingecommented

      Fixed in 3075a2a2aa. Recovery now rereads the settled run under the thread lock and returns if it is rolled_back. Per-cohort parent rollbacks were already skipped.

    7. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Note

      Reviews paused

      It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

      • Last reviewed commit: 2fae83e2007592e39bfe8a096c8cef92824e1b62

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to trigger a single review.

      Use the checkboxes below for quick actions:

      • ▶️ Resume reviews
      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 52400e94-1675-4205-b56d-bf6acb8ae879
      📥 Commits

      Reviewing files that changed from the base of the PR and between 2e1becd8e0042e18468d532a4aea28469d192f73 and 2fae83e2007592e39bfe8a096c8cef92824e1b62.

      📒 Files selected for processing: 2
      • apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
      • apps/server/src/orchestration-v2/Orchestrator.ts

      Limit details: You’ve used all 10 included reviews currently available.

      📝 Walkthrough

      The orchestrator now handles delegated-completion messages and deliveries across rollback, receiving-run settlement, and recovery. Integration tests cover delivery outcomes, queued messages, stale wakes, rollback, and restart recovery.

      Changes: Delegated completion settlement

      Layer / File(s)Summary
      Handle delegated messages after rollback
      apps/server/src/orchestration-v2/Orchestrator.ts
      When the referenced parent run or receiving run was rolled back, dispatchMessage updates thread metadata without waking work.
      Settle and recover delegated deliveries
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
      Settlement examines delegated-completion messages on the receiving run, updates claimed tasks, and offers eligible deliveries. Recovery identifies terminal receiving runs through messages on open reservations. Tests cover settlement, rollback, queued messages, stale wakes, and restart recovery.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 2fae8

      This change ensures that a delegated result whose steer never landed is offered again, or that its reservation is released, after the receiving run settles. No concrete defect remains at the current head. Because the rollback and recovery semantics are intricate, owners should still confirm that they match the intended behavior.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title clearly identifies the server fix for delegated results whose steers never land and the resulting parent wake.
      Description checkPassedThe description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the behavior, implementation, test coverage, limitations, and review context in substa…
      Full details: Description check

      Explanation

      The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the behavior, implementation, test coverage, limitations, and review context in substantial detail.

      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Autopilot is currently an internal CodeRabbit preview.

      Comment `@coderabbitai help` to get the list of available commands.
    8. juliusmarminge assignedjuliusmarminge

    9. Taking over this one for batch composer-chat-18. I will reduce the regression coverage, rebuild against current main, and run independent adversarial reviews. No merge is planned.

    10. tanstack-source added labelsbug

    11. Thanks for working on the delegated-completion recovery path. I've reproduced a related failure involving a live parent run, without a rejected steer.

      When a delegated child completes, its completion wake is queued behind an active parent run (queue_after_active). If that parent calls task_status before settling, the acknowledgement can clear the pending delivery and cancel the wake. The parent then settles without receiving the queued continuation.

      I also reproduced the inverse problem: if the parent already observed and answered the completion in its active turn, promoting another wake can cause a duplicate response.

      I've added five regression cases in DelegatedCompletionDelivery.test.ts, including repeated observations and recovery. Against upstream f52fba48d9, they produce 5 failures and 63 passes; with the proposed fix, all 68 pass, plus 89 adjacent tests.

      The changes concern the completion acknowledgement and queued-run promotion paths, so I believe this is adjacent to the rejected-steer scenario addressed here.

      Would you prefer that I contribute the regression tests to this PR, prepare a separate focused fix, or hold off while your implementation is evolving?

      AI disclosure: DeepSeek V4.1 Flash via Mistral Vibe, using T3 Code's acpRegistry harness.

Sign in to join this conversation.