Public: anyone can read this; the crew can change it.

Traces 1c: GET /api/v1/traces/:id returns the thread, turns and steps as one tree #18128

opened this

Merged 7h 20m ago, live in production

GET /api/v1/traces/:id now returns a trace as one tree: the thread's figures, then its turns, then each turn's steps. It is pushed, bun x tsc --noEmit is clean, and the gate passes. I did not run the whole suite.

Notes

opened this

GET /api/v1/traces/:id now returns a trace as one tree: the thread's figures, then its turns, then each turn's steps. It is pushed, bun x tsc --noEmit is clean, and the gate passes. I did not run the whole suite.

What changed

  • Route: readTraceTree in src/http/api/traces.ts rebuilds the tree from the raw log with parseRunLog. A Talk turn's log is a run log, so both kinds take that one path and parseSession isn't needed.
  • Thread figures: model, account, tokens in/cached/out, cost, outcome, start and end come from the index row that GET /api/v1/traces lists, so the two answers agree. I added getTraceRow to src/trace/index_table.ts for that.
  • Steps: each has kind, name, line, start and end in ms, model, tokens and outcome. A run log holds no tokens per step, so those are 0.
  • Truncation: truncated is true when the log's start was cut (it is read from its last 512 KB) or it holds more than MAX_STEPS (20,000) steps. timed is false when the log kept no times.
  • Hidden vs unknown: a hidden id (a run whose log the caller can't read, someone else's Talk turn) and an unknown or malformed id both answer the same 404 not_found.
  • Contract and docs: getApiV1TracesId is in openapi.json, the generated lists are regenerated, and docs/features/traces.md has the how-to.

Tests (test/traces-api.test.ts, passing)

  • A run's tree has the same step count, errors, tokens and cost as the list row.
  • A Talk turn's tree is its log's, and only its person can read it.
  • A hidden id, another person's run and an unknown id give identical 404 responses, and no token gives 401.
  • A cut log reports truncated, and a 5,000-step run answers within the 100 ms budget.

I also ran the openapi, contract, doorless and boot-lazy tests; they pass.

What I left out

  • No paging of steps: the tree is answered whole. Server time is about 13 ms for 5,000 steps, and the 20,000-step cap bounds the largest answer.
  • The speed test uses server-reported time: the test client shares one event loop with the server, so wall time added about 100 ms of lag. It reads the app duration from Server-Timing instead.
  • Cost not gated by owner: cost is shown as the list shows it, not restricted to people who can see the owner's facts as the run page does. The list already exposes it to the same readers.
  • No new terminal screen: the commit says No door:, because the terminal already reads a run's trace through traceRows.
  • No Codex or Claude Code import: those sessions aren't in the index yet, so this route doesn't serve them.

Try it: GET /api/v1/traces on the preview with a bearer token, then GET /api/v1/traces/<id> of an item it lists.

🤖 Generated with Claude Code

Closes #18022

2 earlier comments
commented

GET /api/v1/traces/:id now returns a trace as one tree: the thread's figures, then its turns, then each turn's steps. It is pushed, bun x tsc --noEmit is clean, and the gate passes. I did not run the whole suite.

What changed

  • Route: readTraceTree in src/http/api/traces.ts rebuilds the tree from the raw log with parseRunLog. A Talk turn's log is a run log, so both kinds take that one path and parseSession isn't needed.
  • Thread figures: model, account, tokens in/cached/out, cost, outcome, start and end come from the index row that GET /api/v1/traces lists, so the two answers agree. I added getTraceRow to src/trace/index_table.ts for that.
  • Steps: each has kind, name, line, start and end in ms, model, tokens and outcome. A run log holds no tokens per step, so those are 0.
  • Truncation: truncated is true when the log's start was cut (it is read from its last 512 KB) or it holds more than MAX_STEPS (20,000) steps. timed is false when the log kept no times.
  • Hidden vs unknown: a hidden id (a run whose log the caller can't read, someone else's Talk turn) and an unknown or malformed id both answer the same 404 not_found.
  • Contract and docs: getApiV1TracesId is in openapi.json, the generated lists are regenerated, and docs/features/traces.md has the how-to.

Tests (test/traces-api.test.ts, passing)

  • A run's tree has the same step count, errors, tokens and cost as the list row.
  • A Talk turn's tree is its log's, and only its person can read it.
  • A hidden id, another person's run and an unknown id give identical 404 responses, and no token gives 401.
  • A cut log reports truncated, and a 5,000-step run answers within the 100 ms budget.

I also ran the openapi, contract, doorless and boot-lazy tests; they pass.

What I left out

  • No paging of steps: the tree is answered whole. Server time is about 13 ms for 5,000 steps, and the 20,000-step cap bounds the largest answer.
  • The speed test uses server-reported time: the test client shares one event loop with the server, so wall time added about 100 ms of lag. It reads the app duration from Server-Timing instead.
  • Cost not gated by owner: cost is shown as the list shows it, not restricted to people who can see the owner's facts as the run page does. The list already exposes it to the same readers.
  • No new terminal screen: the commit says No door:, because the terminal already reads a run's trace through traceRows.
  • No Codex or Claude Code import: those sessions aren't in the index yet, so this route doesn't serve them.

Try it: GET /api/v1/traces on the preview with a bearer token, then GET /api/v1/traces/<id> of an item it lists.

🤖 Generated with Claude Code

commented

GET /api/v1/traces/:id now returns the thread, turns and steps as one tree. This push fixes the failing check on pull #18128.

Cause: pages-budget requires every route with a :param that no fixture can fill to have a file under test/budgets/unfixtured/. The new /api/v1/traces/:id route had none, so the test failed.

Fix: I added test/budgets/unfixtured/api-v1-traces-id.json, saying that no fixture holds a trace id.

Checks: test/pages-budget.test.ts and test/page-budget-files.test.ts pass locally (10 tests). I did not run bun x tsc --noEmit or the rest of the suite; the forge runs the full check on this push.

Left out: I did not add a page-budget fixture for a trace id. The route is now listed as unfixtured, as other :id API routes are.

commented

GET /api/v1/traces/:id returns a trace's thread, turns and steps as one tree. This push fixes one of the six failures from the last check. I haven't touched the other five.

Fixed: "the patterns the seed cannot fill are exactly the ones named" failed because /api/v1/traces/:id was missing from the list of unfillable routes in test/security-floor-routes.test.ts. I added it there, saying the seed holds no trace id. That file now passes (17 tests).

Not fixed: the chaos "fill the temp disk" invariant, the two apps-rollout tests and the two changelog-regrouping tests.

  • None of them touches traces code.
  • I did not run them locally.
  • I suspect the chaos and rollout ones depend on disk or timing, but that is a guess.
  • If they fail again on the next check, send me the log and I'll look at them.

Left out: a seed fixture for a trace id. The route stays listed as unfillable, as the other :id API routes are.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs