t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Server runs inside one never-ended span, so every request and background tick joins a single trace that grows forever

Open bhadraagada opened this issue 6 days ago • 0 comments

What happened

t3 serve exports all of its spans into one trace for the life of the process. That trace has no exported root and never ends. On our server (up since 17 Nov), Tempo saw the trace pass its 50 MB per-trace limit about 20 hours after start. It now holds more than 260 MB and grows by about 20,000 spans per hour. Tempo rejects every new span in it. Opening the trace made two Tempo query pods run out of memory, so our observability team now drops all t3code-server spans.

Diagnosis

Long-lived fibers inherit a span that never ends, so nothing becomes a root.

  • cli/server.ts: runServerCommand is Effect.fn("server.runServerCommand") and runs the whole server inside it. Its span ends only at shutdown, so it is never exported.
  • HTTP: Effect's HttpMiddleware.tracer uses the traceparent header as parent, else the fiber's current span. MCP clients (claude-code, codex-mcp-client) send none, so GET/POST /mcp and GET /api/preview/tunnel become children of that span.
  • scheduling/Scheduler.ts: register is Effect.fn("Scheduler.register"), captures Effect.context() once, and runs every tick with it. Each source keeps one parent span forever.
  • serverActivation.ts: forkParkedFiber is Effect.fn and forks inside its own span.
  • ClaudeAdapterV2.ts: runForkWith(yield* Effect.context()) is captured at layer build. trackDescendants polls once a second per Claude session on Linux, all under the server span.
  • T3 does not read OTEL_TRACES_SAMPLER, so parentbased_traceidratio does not cut the volume.

Suggested: start a root span per HTTP request and per background tick (root: true), or drop the span from runServerCommand, Scheduler.register and forkParkedFiber. Main at 387d1c17 has the same code.

Steps to reproduce

  1. Start t3 serve. An OTLP endpoint is optional, the local trace file shows it.
  2. Open a Claude thread, and connect an MCP client.
  3. After a few minutes, count spans per traceId in logs/server.trace.ndjson. Most spans share one trace ID.
  4. The common parentSpanId of GET, POST and ClaudeAgentSdkQueryRunner.trackDescendants spans is never written to the file.
  5. ScheduledTaskService.runDueTasks has the same parentSpanId on every tick, also never written.

Version

0.1.10 (server process, from the runtime versions dir). Triage CLI is also 0.1.10.

Environment

  • Linux x64 (kernel 6.18), Node 26.13.1, Effect 4.1.3
  • t3 serve --tailscale-serve started with setsid nohup, not a service
  • OTLP over http/protobuf to a local Grafana Alloy, then Tempo
  • Clients: desktop app on Windows and mobile, over Tailscale. Claude and Codex threads.

Evidence

Tempo: trace 4762b219cc9927eec4eab47fbf4ae16e, no root span. Most spans hang off 18d3efa42a6f8ff0, which is never exported.

Local `server.trace.ndjson`, 11 files, 07:55 to 13:12 UTC on 26 Nov:
- 133,837 of 229,707 spans are in that trace
- 18d3efa42a6f8ff0 is never written. It has 15,653 direct children: 13,656 `ClaudeAgentSdkQueryRunner.trackDescendants`, 504 `tailscale.readTailscaleServeRootHolder`, 483 `GET`, 78 `POST`, 253 `ProcessGroupMetrics.sample`
- `ScheduledTaskService.runDueTasks`, `dispatchPendingWebhooks` and `UsageLimitRecoveryWorker.sweep`: 3,029 spans each, each with one fixed parent (37a3acc095be257f, d66454e1d365d2bd, 124d0ce220dd8f5c) that is never written

Related issues

  • #36863 gave each websocket RPC its own trace. This is the same problem for HTTP and background work.
  • #40710 bounds the OTLP export backlog
  • #28196 trace log volume
  • #37582, #43212 fixed the Claude descendant poll on macOS only

Fix applied or workaround

Set OTEL_TRACES_EXPORTER=none on the t3 serve process and restart. This stops trace export only. A restart alone starts a new trace that hits the limit again in about 20 hours.

Filed by

Claude Opus 5.5 (claude-opus-5-5) in Claude Code, through t3 triage.

bhadraagada avatar Nov 26 '26 13:11 bhadraagada