perf(server): stop creating a SQLite temp file for every orchestration command #14403
main fromrefs/pull/14403/head·opened View on GitHubWhat Changed#
projectEventDeferred no longer opens its own transaction. It runs in the caller's, which is what its contract already says and what the engine, its only production caller, does. projectEvent has no caller transaction, so it now opens one around the deferred call and keeps its rollback behavior.
Why#
Every orchestration command created, wrote and deleted a SQLite temp file.
The engine appends an event and projects it inside one command transaction, so the projection's sql.withTransaction was nested, which makes it a savepoint. Effect SQL runs nothing when a nested transaction succeeds, so that savepoint stayed open until the command's COMMIT. SQLite journals every page first written under an open savepoint, and an ordinary command writes enough pages (activity row, thread row, cursors, receipt, and their indexes) to push that journal past the 64 KiB limit where SQLite moves it into a temp file.
On main, lsof on the server process during the benchmark shows a different 65,600-byte etilqs_* file in 8 of 40 samples. With this change it shows none in 40. Per-statement timing puts the command receipt insert, the statement that crosses the limit, at about 170 µs on main and 8 µs here.
A projector failure still fails the whole command: before, it rolled back to the savepoint and then the outer transaction rolled back as well.
Related to the performance audit in #9661. This is not one of its listed items; it sits on the same per-event write path as S10 (#9671).
Measurements#
CPU time per thread.activity.append command through the real OrchestrationEngine on an on-disk database. Each run is 500 warmup commands, then 5 rounds of 4,000 commands, taking the median round. Each side ran three times in alternating order, and the table shows the middle run.
| Activity payload | main | This PR | Change |
|---|---|---|---|
| 300 B | 813 µs | 650 µs | 20% less |
| 1.7 kB | 895 µs | 664 µs | 26% less |
| 8 kB | 1,052 µs | 720 µs | 32% less |
Kernel time per command roughly halves (406 µs to 209 µs at 1.7 kB). On a copy of a real 897 MB database the same 1.7 kB workload went from 947 to 1,240 µs down to 655 to 693 µs.
macOS on Apple silicon, Node 24.21.0, SQLite 3.53.4. The machine was not idle, so treat the absolute numbers as rough; the direction held in every pair. The packaged desktop runtime reports the same SQLite build options (TEMP_STORE=1). Linux, Windows and UI latency were not measured.
Verification#
- The new test counts
sql.transactionspans for a projection run inside a caller's transaction. It fails onmainwith 2 and passes here with 1. - 65 tests pass in
ProjectionPipeline.test.tsandOrchestrationEngine.test.ts, and 295 inserver.test.tsandProviderRuntimeIngestion.test.ts. vp test run src/orchestration src/persistencepasses 685 tests. The 37 failures are all inThreadSettlementReactor.test.tsand fail the same way on unmodifiedmainon my machine.- Server
tsc --noEmit, targeted lint and format check pass.
Checklist#
- This PR is small and focused
- I explained what changed and why
No UI changes.
Model: Claude Fable 5.1. Harness: Claude Code in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
6b0a781Macroscope's review found this PR approvable — This is a focused transaction-boundary performance fix: deferred projections reuse the caller’s existing transaction, while standalone projections retain atomicity through their own transaction. The change is isolated, tested, and introduces no product-default, schema, security, or static-analysis configuration changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thanks for working on this. We merged the orchestrator V2 rewrite in #2829, and we are closing this PR as part of that transition.
This change touches ProjectionPipeline.ts, ProjectionPipeline.ts, which the V2 merge removed. V2 persists and reads its own projections instead of the V1 read model.
Sorry for the extra work this creates. If the change is still needed on V2, please rebuild it on current main, verify it there, and open a new PR linking back here. We're closing the current implementation without assuming the underlying request is resolved.
juliusmarminge closed this
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
4528d498-bfe2-4c04-a172-8424da610d86📥 Commits
Reviewing files that changed from the base of the PR and between 6b0a78156922d5e96f7621a8c41543ec27e15e1f and 232f245fd4457b276404051c936386b795162eac.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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:
d310b6d8-028f-48fd-a4bc-cd739513b948📥 Commits
Reviewing files that changed from the base of the PR and between c18e5ea6ed741443a8ec4a5d22d4b6939b0ecd21 and 6b0a78156922d5e96f7621a8c41543ec27e15e1f.
📒 Files selected for processing (3)
apps/server/src/orchestration/Layers/ProjectionPipeline.test.tsapps/server/src/orchestration/Layers/ProjectionPipeline.tsapps/server/src/orchestration/Services/ProjectionPipeline.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
projectEventDeferredno longer opens its own transaction.projectEventwraps the deferred projection in a transaction. A test checks that deferred projection uses a caller-owned transaction.Changes#
Projection transactions
apps/server/src/orchestration/Services/ProjectionPipeline.ts,apps/server/src/orchestration/Layers/ProjectionPipeline.ts,apps/server/src/orchestration/Layers/ProjectionPipeline.test.tsprojectEventDeferredopens no transaction. The deferred method applies projectors and updates cursors without opening one, whileprojectEventwraps that call in a transaction. The test checks that the projected row is visible inside the caller’s transaction and that one transaction span occurs.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
t3dotggMerge Risk: ⚪ Minimal · up to
6b0a7Deferred projection now uses the caller’s transaction while standard projection retains atomicity. No actionable merge-blocking risk is established; merge after normal checks.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
6b0a7The production command path retains one transaction covering all database changes, and the standalone projection method still provides its own transaction. No introduced security issue was identified in the inspected paths. Deferred projection now depends explicitly on callers honoring its transaction requirement.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.