perf(server): stop decoding unrelated events during startup #12846
t3code/codex-turn-mapping fromrefs/pull/12846/head·merged by juliusmarminge View on GitHubAttachment cleanup replay read and decoded every event after its retry cursor during bootstrap, even though it only needs thread revert/delete metadata and the newest sequence. On a 1.25 GB snapshot of a real T3 database, that path decoded 4,954 events and 23.8 MB of JSON after an ordinary restart.
Query those cleanup rows directly, plus the newest event needed to advance the cursor. Cleanup ordering, deduplication, and retry behavior stay the same without making restart cost grow with unrelated event payloads.
Across three fresh copies of the same snapshot, the database-dependent phase from migrations complete through projection bootstrap fell from a 971 ms median to 512 ms (47.3%). The full launch remained noisy because provider startup runs in the same window, so this measurement isolates the repeated database work changed here.
| Projection bootstrap | Before | After | Change |
|---|---|---|---|
| Run 1 | 1,018 ms | 512 ms | 49.7% faster |
| Run 2 | 780 ms | 535 ms | 31.4% faster |
| Run 3 | 971 ms | 411 ms | 57.7% faster |
| Median | 971 ms | 512 ms | 47.3% faster |
Validation: all 34 legacy projection pipeline tests passed before retargeting. On the Orchestrator v2 base, server typecheck passes and targeted lint and formatting pass.
Model: GPT-5.6 Sol. Harness: Codex in T3 Code.
- 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:L
Understand this PR’s impact
Explore downstream dependencies and potential security impact with Blast Radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
8a6827ad-e505-4a26-b7f2-04309cd93c6a📥 Commits
Reviewing files that changed from the base of the PR and between 61b25b88d7922a480790066341867f3f8ae42fcb and b142e7d61443ba730d808eb3eb9f4fe808ae4d6f.
📒 Files selected for processing (1)
apps/server/src/orchestration/Layers/ProjectionPipeline.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The projection pipeline now loads bootstrap attachment cleanup state through a typed SQL replay query. It derives pending cleanup and the last event from the returned rows, maps query failures, and applies attachment side effects using only event sequence and type.
Changes#
Attachment cleanup replay
Layer / File(s) Summary Typed cleanup replay query
apps/server/src/orchestration/Layers/ProjectionPipeline.tsAdds AttachmentCleanupReplayRowand a SQL query that returns the latest event after the cleanup cursor plusthread.revertedandthread.deletedevents.Bootstrap cleanup application
apps/server/src/orchestration/Layers/ProjectionPipeline.tsBuilds pending cleanup from replay rows, maps decode and SQL failures, and invokes applyAttachmentSideEffectswith reduced event data.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Suggested reviewers:
t3dotggSequence Diagram(s)#
sequenceDiagram participant ProjectionPipeline participant listAttachmentCleanupReplayRows participant SQLDatabase participant applyAttachmentSideEffects ProjectionPipeline->>listAttachmentCleanupReplayRows: load rows after cleanup cursor listAttachmentCleanupReplayRows->>SQLDatabase: execute cleanup replay query SQLDatabase-->>listAttachmentCleanupReplayRows: return decoded rows listAttachmentCleanupReplayRows-->>ProjectionPipeline: return replay rows ProjectionPipeline->>applyAttachmentSideEffects: apply cleanup side effects🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1… Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly and concisely describes the main performance change: avoiding decoding unrelated events during server startup. Description check ✅ Passed The description clearly explains what changed, why it changed, the performance impact, scope, and validation results. It does not use the template headings or include the checklist, but the required i… ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge requested changes
Retarget against v2 pls
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Rebased onto
t3code/codex-turn-mappingat9d6feae1ff. The commit applied cleanly with no conflicts.One follow-up commit on top (
b027642515): addedapps/server/src/orchestration/Layers/ProjectionPipeline.test.ts(v2 has no pipeline test file yet; it uses the sameOrchestrationProjectionPipelineLive+ in-memory SQLite layer shape as main's) with a single focused case for the narrowed replay query:- the cleanup cursor advances to
MAX(sequence)when the latest event is a plainthread.archived, not a revert or delete; - two
thread.revertedevents for one thread collapse into one prune; - a
thread.deletedwhose cleanup cannot remove its files leaves the cursor where it was, and the next bootstrap after the files are fixable moves it forward.
The test also passes against the v2 baseline, so it pins behavior rather than the implementation.
Verified in
apps/server:vp test run src/orchestration/Layers/ProjectionPipeline.test.ts(1 passed) andvpr typecheck(clean).Nothing else changed; the production diff is as you wrote it.
Rebased and touched up by a maintainer's agent; a human will re-review.
- the cleanup cursor advances to
juliusmarminge merged thisdf6e170
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — The PR substantially reduces startup event decoding and adds focused coverage, but it also changes the production attachment-cleanup replay and retry-cursor path. A nontrivial SQL predicate now controls filesystem cleanup work, so the behavioral risk merits human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).