Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): server traces keep more history by skipping low-value spans #18106

Closedbompus(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/18106/headopened View on GitHub

Each 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.

Each streamed event now writes 2 trace spans, was 9. Trace spans per event write: 9 to 2, 78% fewer (4.5×); Trace bytes per event write: 4,855 B to 828 B, 83% fewer (5.9×).

Chart data as text
MetricBeforeAfterChange
Trace spans per event write9278% fewer (4.5×)
Trace bytes per event write4,855 B828 B83% 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.transaction span plus about five sqlite statement spans. Those statement spans were 24% of the bytes.
  • The effect worker carried server.mode, server.port, server.host and startup.phase on every span it made for the life of the server, because annotateSpans wrapped a startup phase that forks it. That was 3% more.
  • ProjectEnrichmentService.peek, request and requestLane (cache reads and a queue offer) were 12,869 spans, 4.5% of the bytes, next to getAvailable's own span.

All three fill the same trace file with spans nobody reads, so this is one problem. The commits are separable.

Change

  1. perf(server): event writes no longer trace every SQL statement: the body of EventSink.commitThenPublish's transaction runs with the tracer off. sql.transaction still times each write. The docs list the exception.
  2. fix(server): startup attributes stay on their own spans: attributes go to withSpan instead of annotateSpans.
  3. perf(server): project lookups trace one span instead of three: the three helpers use Effect.fnUntraced. getAvailable still 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 writeBeforeAfter
Spans92
Trace bytes4,855828

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

    2. 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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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_status to false in 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.ts
      • apps/server/src/orchestration-v2/FoundationPersistence.test.ts
      • apps/server/src/project/ProjectEnrichmentService.test.ts
      • apps/server/src/project/ProjectEnrichmentService.ts
      • apps/server/src/serverRuntimeStartup.ts
      • docs/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.md
      Event writes disable tracing within the transaction while retaining the sql.transaction span. A test checks that the write emits no individual sqlite span. The documentation describes this instrumentation.
      Project enrichment tracing
      apps/server/src/project/ProjectEnrichmentService.ts, apps/server/src/project/ProjectEnrichmentService.test.ts
      peek and request use untraced wrappers; getAvailable remains traced. A test checks that getAvailable emits one span with its method name.
      Startup span attributes
      apps/server/src/serverRuntimeStartup.ts
      Startup 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: Passed 3 · Failed 1
      Failed Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Description checkWarningThe 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 Passed checks (3 passed)
      Check nameStatusExplanation
      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.
      Title checkPassedThe 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. bompus(GitHub profile, opens in a new tab) changed the title

    5. Note

      Grok responding on behalf of Julius.

      Superseded by #19430, which combines and finishes this work. Closing in favor of that PR.

    6. juliusmarminge closed this

Sign in to join this conversation.