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

Traces 5a: compare two traces of one issue side by side, with the cost and time difference #18164

opened this

Merged 5h 12m ago, live in production

This adds GET /api/v1/traces/compare?a=ID&b=ID, the JSON version of the compare page that already exists on main. Pull #18017 had already shipped src/trace/compare.ts, the compare page at /traces/ /compare/ , the terminal c key, the MCP compare action and the docs section. The API route was the missing piece.

Notes

opened this

This adds GET /api/v1/traces/compare?a=ID&b=ID, the JSON version of the compare page that already exists on main. Pull #18017 had already shipped src/trace/compare.ts, the compare page at /traces/<id>/compare/<other>, the terminal c key, the MCP compare action and the docs section. The API route was the missing piece.

What it does

  • Each run is read through readTrace, the same gate as the run's log. A run the caller can't read, or an unknown id, is the same 404.
  • Two readable runs that aren't two different runs of one issue get a 422 not_one_issue. A missing or malformed id, or an unknown parameter, is also a 422.
  • The response has a and b (id, title, outcome), the rows the page shows, timeDiffMs and costDiffUsd (both B − A, or null when a side lacks the figure). Cost shows only to those who may see the owner's spend.
  • It is registered in src/http/api/traces.ts and src/http/lazy_lists.ts, with an OpenAPI route in src/contract/openapi/routes/getApiV1TracesCompare.ts. The existing /api/v1/traces mark already covers it, so src/http/api.ts is untouched. docs/features/traces.md names the route.
  • test/traces-api.test.ts compares two runs of one issue and asserts +30 s and +$0.75, and the step row. It also covers a pair from two issues as a 422, the same run twice as a 422, a bad id as a 422, a hidden run as a 404 identical to an unknown id, and no token as a 401.

Not done: no new page work, since the compare view and the link from the trace page were already there. "Both doors" is covered by the existing terminal c key, stated in the commit as No door: ….

Checks: bun x tsc --noEmit is clean, and the traces-api, security-floor, route-marks and page-budget tests pass (54). The gate's only remaining note is that my test helper issueIn resembles one in test/assigned-etag.test.ts; I left it. I did not run the full suite; the forge's check does.

Reused: compareViews, sameIssue and readTrace; no new comparison logic.

Try it: on the preview, call GET /api/v1/traces/compare?a=<run id>&b=<run id> with a bearer token, using two runs of one issue.

🤖 Generated with Claude Code

Closes #18083

commented

GET /api/v1/traces/compare was never wrongly declared. The failing test only called it with no query string, so it only ever saw the 422, never the 404 the route declares. I fixed the test, not the route.

test/openapi-errors.test.ts now has a small PROBE_QUERY table. For this route the test adds a second call with two unknown run ids, which gets the 404. It keeps the call with no ids, which gets the 422.

test/openapi-errors.test.ts passes locally (5 of 5) and tsc --noEmit is clean. I ran scripts/gate.ts --fix but didn't read its output. The pushed commit changes only the test, and the route and its refuses: [401, 404, 422] are unchanged. The forge's full check will run on the push.

To try it, run bun test test/openapi-errors.test.ts.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs