Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): restarts no longer stall on old subagent result deliveries #19631

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19631/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

After an "Update everything", one fleet host took 78 s to become ready. 70 s of that was delegated-task recovery at startup. Startup holds the effect worker until recovery ends, so agents could not resume during that time.

Recovery finalized every terminal run in a parent thread whose message had ever been a delegated delivery. Each call reloaded the thread's runs, messages, subagents, and turn-item positions, then returned without writing. Only the run that holds a cohort's current delivery message can settle anything. On that host, one parent had 190 past deliveries, which caused 188 serial reloads (about 66 s, no writes).

Recovery now reads only the thread's runs. It finalizes only terminal runs whose input is a cohort's current delivery message. finalizeDelegatedCompletionDelivery already ignored every other run, so delivery behavior does not change. Startup spans now also record the recovery candidate counts.

Proof

  • New test: a parent with 40 settled deliveries and 1 current one. The current delivery settles and a second recovery changes nothing. Before this change, recovery read the delivery message 41 times. Now it reads it once.
  • Local fixture with 190 past deliveries: recovery went from 320 ms and 1,347 SQL statements to 7 ms and 13 statements.
  • All 27 test files that use delegated recovery pass (847 tests).

Not in this PR: the time before the new process starts (likely the full DB backup on ext4, see #18633), and the slow restart continuations after ready, which wait on the SQLite connection behind background sweeps.

Reviewed with sol-loop: 1 round with GPT-6.1-Sol on high.

Created with Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

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

    2. juliusmarminge added labelsmacroscope-review

    3. 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: Team
      • Run ID: 0ea0100a-3425-4a80-8d8b-fcd0f7ecfd43
      📥 Commits

      Reviewing files that changed from the base of the PR and between 348f217a853dd4a23d7fa4834dedb05f545c2075 and edbfce1e04833dbe70e5372ca08abaed3d9275e1.

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

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

      📝 Walkthrough

      Recovery now matches terminal runs to current delegated-completion deliveries instead of scanning messages for historical delegated-completion payloads. Tests verify the query count and confirm a second recovery does not change run or subagent state.

      Changes: Delegated completion recovery

      Layer / File(s)Summary
      Current delivery matching and regression coverage
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
      Recovery records candidate thread counts, selects terminal runs whose userMessageId matches a current delegated-completion delivery, and refreshes runs after finalization. The regression test checks that recovery queries the delivery-message projection once and that a second recovery leaves runs and subagents unchanged.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~12 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to edbfc

      This change speeds up restart recovery by skipping old, already-settled subagent deliveries while still finalizing the current ones. No concrete merge-blocking risk was identified.

      Pre-merge checks: Passed 4
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: preventing startup stalls caused by old subagent result deliveries.
      Description checkPassedThe description clearly covers the problem, the implementation, the verification results, known limitations, and the tools used. It does not provide a separate scope-and-approval statement, but the fo…
      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.
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • 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. Approvability

      Verdict: Approved at edbfce1

      Macroscope's review found this PR approvable — This is a focused, well-tested server recovery fix that removes redundant historical thread reloads while preserving current delegated-delivery settlement. The only production impact is improved startup recovery performance; the companion changes are test-only.

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

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB4.9 KiB−23 B (−0.5%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB−23 B (−1.9%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.8 KiB−41 B (−0.2%)29.3 KiB✅
      CodexLive turn messages21−1 (−50.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−31 B (−0.6%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−31 B (−2.5%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB−41 B (−0.2%)29.3 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: 348f217 · PR result: edbfce1 · 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.

Sign in to join this conversation.