fix(server): prepare restart continuations faster on shutdown #31807
main fromrefs/pull/31807/head·merged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHubProblem#
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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
d173bbdMacroscope'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).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
mainmeasurement shown below.Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Baseline:
47a89f2· PR result:d173bbd· Source CI: successScenario 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.
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.tsThe 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.shutdownspan.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.tsRuntime 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.shutdownspan.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
#30207changes how those continuations replay/compactand release queued runs. - pingdotgg/t3code#29429: This PR changes recovery reads during shutdown preparation, while
#29429bounds the provider-thread query in those reads.
Suggested reviewers:
juliusmarminge
Merge Risk:
Minimal · up tod173b-
No actionable merge-blocking issue was found in the shutdown changes; merge after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly describes the main shutdown performance change. Description check The 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 check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: t3/faster-quit-restart
- File: .coderabbit.config.ts
- Commit: d173bbd
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
1e2eb542-33f2-4f87-b625-aecce9b97068
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.tsapps/server/src/orchestration-v2/ProjectionStore.tsapps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.tsapps/server/src/orchestration-v2/ProviderSessionManager.test.tsapps/server/src/orchestration-v2/ProviderSessionManager.tsapps/server/src/orchestration-v2/RestartContinuation.test.tsapps/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.
-
-
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) approved these changes