Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): prepare restart continuations faster on shutdown #31807

MergedYash-Singh1(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/31807/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

Problem

Shutdown scanned every runtime thread and loaded full request history for attached threads before checking which records still needed cleanup. On populated databases, those reads slowed restart preparation and provider-session release.

Change

Discover restart candidates from provider-session and run projections, filter by project continuation settings, and prepare eligible threads with concurrency limited to two. During session release, load pending requests first, then fetch only their nodes and turn items. Preserve the existing shutdown phases and durable write ordering.

Scope and approval

This focused server performance fix narrows database reads used by existing shutdown and restart behavior. It adds no user-facing setting or workflow.

Verification

Focused tests and affected-package typechecks passed. vp run check:changed passed.

On isolated populated fixtures, median request-cleanup time fell from 361 ms to 78 ms across three runs. With 625 restart candidates, preparation fell from 595 ms to 24 ms and read 4 conversations instead of 625. Total cleanup in that stress fixture remained about 3.87 seconds because final reconciliation dominated. Full desktop quit and process-exit latency were not measured.

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

    2. Approvability

      Verdict: Approved at d173bbd

      Macroscope's review found this PR approvable — Shutdown preparation reads fewer records and processes eligible restart continuations with bounded concurrency. Existing continuation settings, eligibility safeguards, and shutdown ordering remain unchanged, with no obvious material risk requiring human review.

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

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.

      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 decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (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.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Baseline: 47a89f2 · PR result: d173bbd · 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. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Shutdown recovery now selects restart-continuation candidates by project settings and prepares eligible threads with concurrency two. Runtime request release reads nodes and turn items for pending requests, using request IDs to filter turn items.

      Changes: Shutdown recovery and request release

      Layer / File(s)Summary
      Select and prepare restart continuations
      apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts, apps/server/src/orchestration-v2/ProjectionRecovery.test.ts, apps/server/src/orchestration-v2/RestartContinuation.test.ts, apps/server/src/serverRuntimeStartup.ts
      The projection store adds restart-continuation recovery candidates and optional project include and exclude filters. Shutdown preparation applies project settings, retains per-thread setting checks, and runs preparation with concurrency two. Tests cover candidate selection, concurrent durable writes, and disabled continuation. The shutdown finalizer adds a server.shutdown span.
      Load records for pending requests
      apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProviderSessionManager.ts, apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
      Runtime request release first reads pending requests, then fetches matching nodes and turn items when requests exist. Turn items can be filtered by request ID. Tests check that a resolved historical request is not included in release. The shutdown effect adds a ProviderSessionManager.shutdown span.

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

      Change: Refactor

      Possibly related issues

      • pingdotgg/t3code#24503: The issue concerns a missing restart continuation for a cancelled Codex command. This change updates restart-candidate selection and preparation; notification ownership remains separate.

      Possibly related PRs

      • pingdotgg/t3code#30207: This PR prepares restart-continuation effects, while #30207 changes how those continuations replay /compact and release queued runs.
      • pingdotgg/t3code#29429: This PR changes recovery reads during shutdown preparation, while #29429 bounds the provider-thread query in those reads.

      Suggested reviewers: juliusmarminge

      Merge Risk: Minimal · up to d173b

      No actionable merge-blocking issue was found in the shutdown changes; merge after normal checks.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly describes the main shutdown performance change.
      Description checkPassedThe description covers the problem, change, scope, and verification. It could identify the focused tests and explain why the fix qualifies without prior approval.
      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
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 1a4585885c74bf89728d0939c534ef4b2a42d147 and d173bbd0ab8e8416389c0cea3d7e8baa7ce5db80.

      Files selected for processing: 7

      • apps/server/src/orchestration-v2/ProjectionRecovery.test.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts
      • apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts
      • apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
      • apps/server/src/orchestration-v2/ProviderSessionManager.ts
      • apps/server/src/orchestration-v2/RestartContinuation.test.ts
      • apps/server/src/serverRuntimeStartup.ts

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

Sign in to join this conversation.