Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): trace logs keep hours of history instead of minutes #5780

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromt3code/trace-log-churnopened View on GitHub

Problem

The local trace file (server.trace.ndjson) burned through its entire 100 MB rotation window in 10-36 minutes on a busy host. Incident audits were impossible: spans from 20 minutes ago were already rotated away.

Measured breakdown (113 MB / 260k spans):

  • ~40% terminal subprocess polling: pgrep + up to three ps spawns per session per second, each enumerating the full process table, all emitting empty always-success spans. Also 50-75 process spawns/sec on a host with 25 running terminals, independent of tracing.
  • ~28% sql.execute (~76/s, constant attributes on every span).

Solution

Write less:

  • One shared ps -eo pid=,ppid=,comm= (or one PowerShell call) snapshot per poll tick serves every running terminal; per-session inspection is a pure lookup over it. Cuts process spawns by ~25x on busy hosts.
  • The poll tick runs with tracing suppressed; an explicit terminal.subprocessActivityChanged span fires only on an actual state flip.
  • Tail policy in the local file tracer: failures, interruptions, spans with events, and slow spans (>=25ms) always persist; fast successes are rate-limited to 50 per name per 30s. The OTLP delegate still receives every span. T3CODE_TRACE_KEEP_ALL_SPANS=true restores full fidelity.
  • Removed constant db.name/service.name attributes from every sql.execute span.

Keep more:

  • Rotated backups are gzipped (measured 10.6x on real span data) and T3CODE_TRACE_MAX_FILES defaults to 30. Same disk budget, hours of history, still zgrep-able.
  • TraceDiagnostics now reads backups one file at a time instead of loading every rotation into memory at once, and transparently gunzips .gz backups. Plain backups from before the change age along the rotation chain unchanged.

Behavior notes:

  • POSIX child-command labels now come from the snapshot's comm column; the rare ps -o args= fallback for an empty comm is gone (label degrades to none, the running indicator is unaffected).
  • Diagnostics span counts are sampled for hot always-success span names; failure and slow-span counts remain exact.

Tests: new coverage for gzip rotation (including legacy plain backups aging along the chain), tail-policy keep/drop behavior, gz-backup reads in TraceDiagnostics, and snapshot-based subprocess inspection.


Written by Claude Fable 5 via Claude Code, reviewed by Theo.

🤖 Generated with Claude Code


Note

Medium Risk Touches terminal subprocess detection, trace persistence semantics, and diagnostics file formats; behavior changes (sampling, gzip rotation, single snapshot polling) could affect incident debugging and port discovery if process tables truncate or labels regress.

Overview Local trace files were rotating in minutes under load. This PR writes less and keeps more on disk.

Less noise in traces and subprocess churn: TerminalManager now captures one OS process table per poll tick and derives every terminal’s subprocess tree from that snapshot (replacing per-session pgrep/ps storms). Poll ticks run with tracing suppressed; only real subprocess activity changes emit terminal.subprocessActivityChanged. The local file tracer gets an optional tail policy (failures, slow spans, and spans with events always kept; fast successes rate-limited per span name). OTLP export is unchanged. New config traceKeepAllSpans / env T3CODE_TRACE_KEEP_ALL_SPANS disables tail filtering. Constant attributes were removed from every sql.execute span.

Longer on-disk history: RotatingFileSink can gzip rotated backups (compressBackups enabled for server traces). Default traceMaxFiles rises from 10 → 30. TraceDiagnostics gunzips .N.gz backups, skips duplicate plain+gz crash leftovers, and aggregates one file at a time to cap memory.

Operational notes: Truncated process-table output fails the tick (sessions keep prior state). POSIX child labels use snapshot comm only (no args fallback). Hot success span counts in diagnostics are sampled when tail policy is on.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ffd43b41ec7386adc1190579e3ab59935e570f16. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Compress local trace backups and apply tail sampling to reduce trace history volume

  • Local trace files now rotate with gzip compression (compressBackups: true), keeping .N.gz backups; the default max rotated files increases from 10 to 30, extending history from minutes to hours.
  • A tail sampling policy (makeTraceTailFilter) is applied to the local file tracer by default, rate-limiting fast-success spans while always keeping failures and slow spans. OTLP export still receives every sampled span. Controlled by the new T3CODE_TRACE_KEEP_ALL_SPANS env var.
  • Terminal subprocess polling is refactored to capture one process table snapshot per tick (via ps on POSIX or PowerShell on Windows) and infer all sessions' states from it, reducing spawned processes and steady-state trace noise.
  • TraceDiagnostics now reads .gz-compressed rotated backups, deduplicates plain/compressed overlaps, and reduces peak memory by aggregating files incrementally.
  • Behavioral Change: SQLite spans no longer include constant db.name and service.name attributes; steady-state polling ticks suppress tracing by default.
Macroscope summarized ffd43b4.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 45aae989-08d3-4758-aa03-0cf998ae0844

      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

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. One finding on Effect error-modeling conventions in apps/server/src/terminal/Manager.ts. The rest of the touched Effect code (subpath namespace imports, TraceDiagnostics service/make/layer shape, Schema.TaggedErrorClass usage with structural attributes, Effect.catchTags, absence of new ManagedRuntime/runPromise/fake DI) looks consistent with the conventions.

      Posted via Macroscope — Effect Service Conventions
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/3cc7cf3c837ae41d6abfb1995b603902cb65f726/packages/shared/src/observability.ts#L582

      makeLocalFileTracer drops options.compressBackups when constructing the default makeTraceSink, so callers passing compressBackups: true still get uncompressed rotated backups. The field flows through TraceSinkOptions into LocalFileTracerOptions but is never forwarded.

      No longer relevant as of 04ae0412efb19fb9fef48e2153dcb2dea344f6c1

    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire11.3 KiB11.3 KiB+20 B (+0.2%)15.1 KiB✅
      CodexThread snapshot wire5.5 KiB5.5 KiB−4 B (−0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire5.9 KiB5.9 KiB+24 B (+0.4%)7.8 KiB✅
      CodexLive turn WebSocket decoded49.7 KiB49.7 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages16160 (0.0%)21✅
      ClaudeTotal thread wire11.3 KiB11.3 KiB−2 B (−0.0%)15.1 KiB✅
      ClaudeThread snapshot wire5.5 KiB5.5 KiB−6 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire5.9 KiB5.9 KiB+4 B (+0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded50.6 KiB50.6 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages16160 (0.0%)21✅

      Baseline: 05eb051 · PR result: ffd43b4 · Source CI: success

      Scenario 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: 94.6 KiB
      • Claude decoded thread snapshot: 95.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces multiple new features (gzip backup compression, tail sampling policy) and significantly refactors subprocess inspection. The tail policy changes which spans get persisted to trace files, and the default max files increases from 10 to 30. The scope of behavioral and architectural changes warrants human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. Note

      🤖 Fable 5 responding on behalf of Theo

      Fixed in 04ae0412e — makeLocalFileTracer now forwards compressBackups when it constructs the default sink. Correct catch: the server happened to be unaffected because Observability.ts passes an explicit sink, but any caller relying on the default sink would have silently gotten uncompressed backups.

    8. One finding on the terminal error declarations. Everything else in the diff (the new TerminalProcessTableCaptureError, subpath namespace imports including effect/References, Effect.catch over a fully-handled channel, dependency acquisition via yield* ProcessRunner.ProcessRunner, and the injected inspector kept as a test-only seam) matches the conventions.

      Posted via Macroscope — Effect Service Conventions
    9. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 04ae0412efb19fb9fef48e2153dcb2dea344f6c1. Configure [here](https://www.cursor.com/dashboard/bugbot).

Sign in to join this conversation.