perf(server): server traces keep more history by skipping low-value spans #18106
main fromrefs/pull/18106/head·opened View on GitHubEach streamed event now writes 2 trace spans, was 9 (828 bytes, was 4,855). A replay of a real 111 MB trace shows about 30% fewer bytes, so the same trace files cover more history.
Chart data as text
| Metric | Before | After | Change |
|---|---|---|---|
| Trace spans per event write | 9 | 2 | 78% fewer (4.5×) |
| Trace bytes per event write | 4,855 B | 828 B | 83% fewer (5.9×) |
Problem#
The server trace keeps 10 files of 10 MiB. On a desktop install with about seven agents streaming they rotated every 1.5 to 3 minutes, so the whole window covered about 20 minutes (related: #8764, #16202).
In a 21-minute sample (212,821 spans, 111 MB):
- Each streamed agent event is one event-sink write: a
sql.transactionspan plus about fivesqlitestatement spans. Those statement spans were 24% of the bytes. - The effect worker carried
server.mode,server.port,server.hostandstartup.phaseon every span it made for the life of the server, becauseannotateSpanswrapped a startup phase that forks it. That was 3% more. ProjectEnrichmentService.peek,requestandrequestLane(cache reads and a queue offer) were 12,869 spans, 4.5% of the bytes, next togetAvailable's own span.
All three fill the same trace file with spans nobody reads, so this is one problem. The commits are separable.
Change#
perf(server): event writes no longer trace every SQL statement: the body ofEventSink.commitThenPublish's transaction runs with the tracer off.sql.transactionstill times each write. The docs list the exception.fix(server): startup attributes stay on their own spans: attributes go towithSpaninstead ofannotateSpans.perf(server): project lookups trace one span instead of three: the three helpers useEffect.fnUntraced.getAvailablestill records each lookup.
Cost: per-statement timing inside an event write is gone. A slow commit still shows in the transaction's duration, but not which statement was slow (the fsync stall in #15707 would show as a long transaction).
Scope and approval#
Tracking issue: #18917.
A performance change to what the server traces; no new feature. Open issue #8764 reports the same trace volume. There is no maintainer approval of the direction yet. Commit 1 drops per-statement timing, which is an intentional change to what the trace records, so I'm asking for that view on #18917 (#8764 reports the same trace volume). If you want the commits as separate PRs, I'll split them.
Verification#
Benchmark for commit 1: 3,000 turn-item.updated writes through the real EventSink on in-memory SQLite with the real file trace sink, 3 runs after a warm-up pass.
| Per event write | Before | After |
|---|---|---|
| Spans | 9 | 2 |
| Trace bytes | 4,855 | 828 |
Replaying the 111 MB sample with the removed spans taken out gives about 30% fewer bytes in total (24% + 3% + 4.5%). Tracing CPU on the event-write path was about 0.1 ms per write before, around 0.05% of a core at 3.7 writes/s, so the gain is disk and history length, not CPU. Wall times varied by about ±15% between runs and are not a claim.
Tests: commits 1 and 3 each add one that fails without the change (a captured-span check). FoundationPersistence, ProjectEnrichmentService, serverRuntimeStartup and serverRuntimeStartup.autoPull pass, 61 of 61. Commit 2 has no test of its own; the replay above is its only evidence. Not checked: a live dev server under agent load.
Still large after this and not touched here: PR polling git calls (see #17063) and StorageCleanup.sweep.
Claude Sonnet 5.5, in Claude Code.
Closes #18917
- 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:M
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bc45bd10-2b90-4dad-8e87-9b108a4839f5
📥 Commits
-
Reviewing files that changed from the base of the PR and between 699aed64b810f54fd64ca1af6a0fa99524fb7182 and d3927e849bdd088e3f985ad507256bcdac78d60e.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ee2a5437-585c-4443-b70d-a83bb5a05c8a
📥 Commits
-
Reviewing files that changed from the base of the PR and between b4542c5418e727db5c5b578e3dc2b39e915fd0bc and 699aed64b810f54fd64ca1af6a0fa99524fb7182.
📒 Files selected for processing (6)
-
apps/server/src/orchestration-v2/EventSink.tsapps/server/src/orchestration-v2/FoundationPersistence.test.tsapps/server/src/project/ProjectEnrichmentService.test.tsapps/server/src/project/ProjectEnrichmentService.tsapps/server/src/serverRuntimeStartup.tsdocs/operations/observability.md
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
-
📝 Walkthrough
-
Walkthrough#
The changes adjust tracing for event writes and project enrichment. Startup spans now set phase and server metadata directly as span attributes. Tests verify event-write and project-enrichment span output, and the observability documentation describes event-write transaction spans.
Changes#
Server Tracing
Layer / File(s) Summary Event-write transaction tracing
apps/server/src/orchestration-v2/EventSink.ts,apps/server/src/orchestration-v2/FoundationPersistence.test.ts,docs/operations/observability.mdEvent writes disable tracing within the transaction while retaining the sql.transactionspan. A test checks that the write emits no individualsqlitespan. The documentation describes this instrumentation.Project enrichment tracing
apps/server/src/project/ProjectEnrichmentService.ts,apps/server/src/project/ProjectEnrichmentService.test.tspeekandrequestuse untraced wrappers;getAvailableremains traced. A test checks thatgetAvailableemits one span with its method name.Startup span attributes
apps/server/src/serverRuntimeStartup.tsStartup phase, heartbeat, and root startup spans set their phase or server metadata directly as span attributes. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Other
Suggested reviewers:
juliusmarminge
-
Merge Risk: ⚪ Minimal · up to
699ae-
Event-write tracing retains transaction timing, enrichment behavior remains intact, and startup metadata stays on its corresponding spans. No actionable merge-blocking risk was found.
Pre-merge checks:
3 · 1-
Failed checks (1 warning)Check name Status Explanation Resolution Description check The description explains the problem, changes, trade-offs, measurements, tests, and unchecked scenarios. However, the required scope approval is not complete because it states that maintainer approval… Add a link to the relevant discussion or issue comment containing explicit maintainer approval for the direction and scope, or explain why this focused change qualifies for the approval exemption. Passed checks (3 passed)-
Check name Status Explanation 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. Title check The title clearly summarizes the main change: reducing low-value server trace spans to retain more trace history.
Full details: Description check
-
Explanation
The description explains the problem, changes, trade-offs, measurements, tests, and unchecked scenarios. However, the required scope approval is not complete because it states that maintainer approval is still pending for the intentional tracing behavior change.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
bompus(GitHub profile, opens in a new tab) changed the title
Note
Grok responding on behalf of Julius.
Superseded by #19430, which combines and finishes this work. Closing in favor of that PR.
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR materially changes production trace behavior across event persistence, project enrichment, and startup by suppressing spans and reducing diagnostic detail on existing paths. The accompanying tests validate the intended trace reductions, but the observability tradeoff and cross-cutting runtime impact merit human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).