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

An imported session opens at /traces/<id> as the same tree and time strip a crew run has #18366

opened this

Merged 3h 40m ago, live in production

An imported session now opens at /traces/ as the same tree and strip a crew run has, for the person who imported it and no one else. I ran the new test and the trace tests that cover the change, plus unused-exports, dup-imports and page-budget. All pass, as do tsc, gate.ts --explain and the design lint.

Notes

opened this

An imported session now opens at /traces/<id> as the same tree and strip a crew run has, for the person who imported it and no one else. I ran the new test and the trace tests that cover the change, plus unused-exports, dup-imports and page-budget. All pass, as do tsc, gate.ts --explain and the design lint. I did not run the full suite.

What changed

  • Reader and page: src/trace/imported_read.ts reads the stored gzipped file with the existing parseSession. It caps steps at MAX_STEPS and counts times from the session's start. src/web/pages/trace_imported.ts renders the page. It has the strip and #step-N permalinks, and each step's raw lines load on demand at /traces/<id>/steps/<n>.
  • Escaping: step lines go through the html template, so the test's <script> and <b> in prompts come out escaped. Raw lines are served as text/plain and capped at 40 lines of 8,000 characters each.
  • Not recorded: where the file has no tokens or cost, the page says "not recorded in this file" instead of showing zero. An imported session never has a cost, so that line always says it.
  • Access: tracePage and traceStep in src/web/pages/trace.ts try the crew-run path first, then the imported one. Another user, a signed-out visitor and an unknown id all get the same 404, and the API route gives the same 404 to everyone but the owner.
  • Shared tree code: I pulled the tree-building loop out of the run page's body() into treeRows so the imported page reuses it.
  • API change you didn't ask for: getTraceRow returned kind review for an imported row, which hid it from the reader. It now says imported, as the list already did. traceTree therefore also answers GET /api/v1/traces/<id> for an imported id, through treeOf.
  • Docs and tests: docs/features/traces.md loses "a page for an imported trace" from its Not yet. test/trace-imported-page.test.ts imports a fixture and covers the owner's tree, the escaping, the raw lines and the 404s.

Choices and gaps

  • Raw lines per step: the importers keep no per-step line spans, so a step's raw lines are the file's lines that contain its id. A Codex message step has a made-up id, so it shows "No raw line of the file names this step."
  • No terminal side: the terminal's trace screens are keyed by repository and run id, and an imported session has no repository. A commit line says No door: …, and forge trace <file> still reads a session file there.
  • No cache: a 32 MiB session is parsed on every page view and step open. I did not measure it. Say if you want a small cache keyed on the stored file.
  • Not done: deleting an imported trace stays in Not yet.

To try it: import a session with POST /api/v1/traces/import (the curl in docs/features/traces.md). Take its id from GET /api/v1/traces?kind=imported, then open /traces/<id> signed in as the importer.

🤖 Generated with Claude Code

Closes #18357

4 earlier comments
commented

An imported session now opens at /traces/<id> as the same tree and strip a crew run has, for the person who imported it and no one else. I ran the new test and the trace tests that cover the change, plus unused-exports, dup-imports and page-budget. All pass, as do tsc, gate.ts --explain and the design lint. I did not run the full suite.

What changed

  • Reader and page: src/trace/imported_read.ts reads the stored gzipped file with the existing parseSession. It caps steps at MAX_STEPS and counts times from the session's start. src/web/pages/trace_imported.ts renders the page. It has the strip and #step-N permalinks, and each step's raw lines load on demand at /traces/<id>/steps/<n>.
  • Escaping: step lines go through the html template, so the test's <script> and <b> in prompts come out escaped. Raw lines are served as text/plain and capped at 40 lines of 8,000 characters each.
  • Not recorded: where the file has no tokens or cost, the page says "not recorded in this file" instead of showing zero. An imported session never has a cost, so that line always says it.
  • Access: tracePage and traceStep in src/web/pages/trace.ts try the crew-run path first, then the imported one. Another user, a signed-out visitor and an unknown id all get the same 404, and the API route gives the same 404 to everyone but the owner.
  • Shared tree code: I pulled the tree-building loop out of the run page's body() into treeRows so the imported page reuses it.
  • API change you didn't ask for: getTraceRow returned kind review for an imported row, which hid it from the reader. It now says imported, as the list already did. traceTree therefore also answers GET /api/v1/traces/<id> for an imported id, through treeOf.
  • Docs and tests: docs/features/traces.md loses "a page for an imported trace" from its Not yet. test/trace-imported-page.test.ts imports a fixture and covers the owner's tree, the escaping, the raw lines and the 404s.

Choices and gaps

  • Raw lines per step: the importers keep no per-step line spans, so a step's raw lines are the file's lines that contain its id. A Codex message step has a made-up id, so it shows "No raw line of the file names this step."
  • No terminal side: the terminal's trace screens are keyed by repository and run id, and an imported session has no repository. A commit line says No door: …, and forge trace <file> still reads a session file there.
  • No cache: a 32 MiB session is parsed on every page view and step open. I did not measure it. Say if you want a small cache keyed on the stored file.
  • Not done: deleting an imported trace stays in Not yet.

To try it: import a session with POST /api/v1/traces/import (the curl in docs/features/traces.md). Take its id from GET /api/v1/traces?kind=imported, then open /traces/<id> signed in as the importer.

🤖 Generated with Claude Code

commented

<!-- look-pages fc0817378e99 --> Look pages for fc08173, from the gate:

  • look pages (none): this pull changes src/web/pages/trace.ts, src/web/pages/trace_imported.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 28 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

Review note on the one risk #18357 named and this pull leaves unmeasured: "parsing a 32 MiB session on a request … stay under the serving thread's budget".

Access and escaping look right: getTraceRow now says imported only where owner <> '' (Talk rows are written with owner ''), seeing() checks the owner, and on main an imported row read as review was already refused, so nothing leaked before either.

The cost is the gap. Every page view and every step expand runs readImported (gunzip) + parseSession + text.split("\n") over the whole file, on the serving thread; TRACE_JS fetches /steps/<n> on each expand, so opening ten steps of a big session is ten full parses. Before landing, please measure one parse of a near-cap session (generate a ~32 MiB Claude Code JSONL in the test helper, time parseImported). If it is well under the budget, say the number in the pull and leave it. If not, the smallest fix is one cached parse per process keyed by id + stored file size (drop on re-import, which replaces the file), so the page and its step opens share one parse; a test can count parseSession calls across a page view and two step opens (1, not 3).

commented

An imported session is now parsed once per stored file. A page view and its step opens share that parse, so a page plus two step opens does one parse where it did three.

Measured cost. One cold parse of a 31 MiB Claude Code session (gunzip, parseSession and the step cap) took about 165 ms here. The importer's own cap is 32 MiB, so that is close to the worst case. It is over the 50 ms budget, so I took your smaller fix instead of leaving it.

What changed

  • parseImported in src/trace/imported_read.ts keeps the last two parses. The key is the data dir, the id and the file's size and mtime, so a re-import, which replaces the file, is read afresh.
  • Two entries keep memory bounded, since each entry holds a whole file.
  • stampOf in src/trace/import.ts returns the file's size and mtime.
  • parseCount is exported so a test can count parses.
  • Tests in test/trace-imported-page.test.ts:
    • A page view plus two step opens count 1 parse.
    • After a re-import with changed text, the page shows the new text and the count goes to 2.
    • A generated 31 MiB session parses in under 2 s. I used 31 MiB because the importer refused a 32 MiB body.

Checks. tsc is clean. The imported-page test, dup-imports and web-import-cost all pass. I did not run the "first-view budget" or "every column that names a user" tests by name. This change touches neither pages' markup nor any table, so I don't expect them to move.

Gate. I committed the comment rewrap. For the gate's rules I put these lines on the last commit's message:

  • Replaces: nothing
  • No door: the change is a cache behind the page, and what the page shows is unchanged
  • No look: the same reason

I did not change the terminal side or docs/features/.

Not done. The cache is per process and in memory only. Concurrent cold requests for the same id can still each parse once, which is rare and harmless.

🤖 Generated with Claude Code

commented

The check failed because the parse cache was a module-level Map, which test/module-state.test.ts refuses. I changed it to a WeakMap keyed by the app, which is the pattern that test asks for, and pushed.

bun x tsc --noEmit is clean. module-state and trace-imported-page pass: 8 tests, 0 failures. I did not re-run the full suite. The gate is clean apart from the over-100-column comment in src/trace/index_table.ts, which it leaves to the nightly rewrap.

Behaviour is as before. A page view and its step opens share one parse, and a re-import is read afresh because the file's size and mtime are in the key. The cache is now per forge, so two forges in one process no longer see each other's parses.

The commit message carries Replaces:, No door: and No look: lines for the gate.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs