Public: anyone can read this; the crew can change it.
Traces 4: a Claude Code session file imports as a trace and is listed beside the others #18129
Merged 6h 13m ago, live in production
POST /api/v1/traces/import now takes a Claude Code session JSONL and keeps it as a private trace of kind imported. tsc and the import, route-contract, migration, body-cap, route-mark and unused-export tests pass, and the gate is clean.
-
Reviews
Changes requested — before the latest pushThe import works and reads well: body is capped by bytes actually read (readBounded), rw scope gates it, rows are owner-scoped in both the SQL filter and
seeing(), and the tests cover the happy path, duplicate, refusal and cap. Changes needed, all in one round:- HIGH (private data outlives its owner): the account purge deletes the
trace_indexrow but leavestraces/imported/<id>.jsonl.gz. A full private Claude Code session (prompts, file contents, paths) stays on disk after the person is purged, unreachable and undeletable. Delete the owner's files in the purge (list their ids fromtrace_index WHERE owner = ?before deleting the rows) and add a test in account-purge that fails without it. - MEDIUM (denial of service): any member can import unlimited distinct sessions of up to 32 MiB each, with no quota, so disk fills and the forge can go dark, which is a Never. The 32 MiB file is also decoded, parsed and gzipped in one go on the request path (
parseClaudeSessionis synchronous), which can stall the event loop. Add a per-account cap, for example a total byte count of stored imports checked before writing, with a plain 413 or 422 and a test. Say in the docs what the cap is; the docs currently list the quota as 'not yet'. - MEDIUM (both doors): the page-and-terminal rule is not met. The commit says 'No door', but a person who can list imported traces on the web (
kind=importedin the API) has no terminal screen for it. Either add thesrc/tui/listing path for imported traces, or show that the existing terminal traces screen already lists them (with a test). Otherwise state in the commit why a terminal door is unnecessary. - LOW (fragile storage): imported rows are written with kind 'review' and read back as 'imported' via
owner <> ''. Any future reader ofkind='review'will leak private rows to everyone. Keep it if the migration rule forces it, but add a test that a query with no kind filter never returns an imported row to a non-owner throughlistTraceIndexconsumers other than the API, and a comment atputTraceRow. - LOW: two concurrent imports of the same session in one process share the
<file>.<pid>.partname, so they can interleave. Use a unique part name (random suffix). Alsotraces.tsimports../limits.tsand../../trace/import.tsout of the existing order.
Boxes: 1 is met in code but the quota/DoS finding stands; 2 to 6 are met. Re-review after the fix.
ApprovedEarlier asks are met. Purge now removes a person's stored session files after the rows commit, and a test checks that another account's file stays. A per-account 256 MiB quota gives a 413
quota_exceeded, and a re-send counts only the new copy. Part files carry a UUID, with a concurrent-import test. Thekind=reviewleak is documented atputTraceRowand tested. The terminal listing is aNo door:commit line, which the rule allows. Everything else in the diff since my last review is the merge of main.Non-blocking:
GET /api/v1/traces/:idgoes throughgetTraceRow, which returns the stored kindreviewfor an imported row, so the owner gets a 404 for their own import. Nothing leaks, becauseseeingrefusesreview. Mapowner <> ''toimportedthere when the imported-trace page lands.- The quota check and the write are not atomic, so two parallel imports of different sessions can overshoot the quota slightly. The overshoot is bounded and does no harm.
- HIGH (private data outlives its owner): the account purge deletes the
-
Checks
shipped production is serving it deploy a338207
-
History
- Merge main into the traces import branch fbc3a47
- AWS writes for mail setup are a named allowlist beside the read rule, and nothing else (#18142) 93c7c3d
- Traces 1c: GET /api/v1/traces/:id returns the thread, turns and steps as one tree (#18128) 077bab0
- A box's TPS and tick time show live on its games pane, from spark's health report or `/spark tps` at check-in (#18143) f7e559b
- Access 4c: the grants view as an MCP tool and a terminal screen (#18130) 89afadf
- Traces 4: purge an account's imported files, cap what an account keeps, unique part names 7ce70fd
- small: the Absorb findings say they are ready for the owner to send to Ben (#18132) d41ec43
- Games survival step 2a: BlueMap behind login at /games/<box>/<server>/map, no published box port (#18100) 1132c91
- A Mac can take a repository's checks and report them on the pull (#17915) 4c72a1d
- Merge main into the traces import branch 3f61d17
- Access 4: one view of every grant, and a page that says who may do what (#18062) 5ba07c8
- Access 2: one `may(principal, action, resource)`, with the repository checks behind it first (#18065) 7d48ce1
- Apps without a login 2: a tiny model in the browser fills the app's spec, and the compiler catches every failure (#18117) 4147a37
- Traces 4: list the import door in DOORS and cover trace_index.owner in the account purge 643a69c
- Games: a new pin for the forge's proxy plugin replaces the old jar, in PLUGINS and on disk, and the page says which one loaded (#18111) da9e15f
- Healer: a server still starting, its log moving, is not started again (#18053) d918642
- Game box: refuse a wake or a mod install the box has no memory for (#18057) 7fe508f
- Games survival step 1: a survival performance set (lithium, scalablelux, noisium, chunky) planned as one locked install (#18099) b838dce
- Games survival step 2b: read FabricExporter Prometheus metrics at check-in so TPS and tick time show on the games page (#18116) 0d92810
- Full suite red: 2 files in check run 01m8zwjzbrpcdryvgey8kqdeak (#18124) 643723c
4 earlier comments
POST /api/v1/traces/import now takes a Claude Code session JSONL and keeps it as a private trace of kind imported. tsc and the import, route-contract, migration, body-cap, route-mark and unused-export tests pass, and the gate is clean. I did not run the full suite, and the route-timing walk did not exercise the new route because it only walks GET routes. The forge's check runs everything.
- Route: the body is read through the cap (a new
traceImportrow inBODY_CAPS, 32 MiB) and a plain 413 comes back past it. Needs anrwtoken. A browser session that sends the request cross-origin gets a 403. It answers 201 for a new session and 200 when the same session is sent again. - Stored: the raw file goes gzipped to
traces/imported/<id>.jsonl.gzunder the data directory. The id is a hash of the account plus the session id, so re-importing replaces the trace instead of duplicating it. Another account importing the same session gets its own trace. - Listing:
GET /api/v1/traces?kind=importedlists the row for its sender and for nobody else. The row carries the first prompt as its title, the first model, steps, errors, tokens, and start and end times. - Reader and adapters:
src/trace/claude_code.tsis reused as the only parser. The adapter interface issrc/trace/import_adapter.ts, withimport_claude_code.tsas its one source. Codex is a new file plus one line inADAPTERS. - Refusals: a 422 (
invalid_session) says why when the file is not UTF-8, is empty, has no session records, or has no usablesessionId. - Docs:
docs/features/traces.mdhas the one-linecurlfor a Mac, andgetApiV1Traces.tsnow listsimportedamong the kinds. The test istest/traces-import.test.ts.
Chosen deviations:
- Migration: the
kindcheck ontrace_indexcan't be widened by a migration that only adds, which the gate requires. So the migration adds anownercolumn, an imported row is stored with kindreview(which nothing else writes), andlistTraceIndexreads it back asimportedand filters on that.kind=reviewstill returns only real review rows. - Dead-code allowlist:
readImportedhas no caller insrc/yet (the test uses it), so I added it to the dead-code allowlist for a later page to read. - Commit line: the commit says
No door:for the terminal, since the import is acurland the list already shows the row.
Left out:
- Codex files, a page for an imported trace, deleting an import, and a per-account quota.
Content-Encoding: gzipon the upload.- Streaming to disk. The body is held in memory up to 32 MiB, which is why the cap is not larger.
Try it: curl -X POST -H "authorization: Bearer $FORGE_TOKEN" -H "content-type: application/x-ndjson" --data-binary @session.jsonl $FORGE_URL/api/v1/traces/import, then GET /api/v1/traces?kind=imported.
🤖 Generated with Claude Code
I fixed two of the three check failures and pushed. I didn't change anything for the third, a first-view budget failure, which I couldn't reproduce.
DOORSlist:POST /api/v1/traces/importis now inDOORSintest/private-by-default.test.ts, markednoRepositorybecause it makes a trace, not a repository. I placed it in sorted order, since the test also checks the order.- Account purge:
trace_index.owneris now inCOVEREDinsrc/core/account_purge.tsasDELETE. An imported session belongs to the person who imported it, so its index row goes when their account is purged. The compressed session file undertraces/imported/is not removed by this change. - First-view budget:
test/attention.test.tspasses here, and the check log says it is green on main. It first showed up in the log as a 64 ms failure on a shard that was running slowly, so I'm treating it as timing noise.
test/private-by-default.test.ts and test/account-purge.test.ts pass. bun x tsc --noEmit is clean. gate.ts --fix left nothing to commit; it only noted one comment line over 100 columns in src/trace/index_table.ts.
I merged main into the branch and pushed it. scripts/unused-exports-allow.json was the only conflict.
I kept lockfileDependencies, which main still lists, and src/trace/import.ts readImported, which this branch adds. I dropped src/core/grants_view.ts everyGrant. That line came from this side, and main's version of the file no longer has it, so I took that to mean main now uses everyGrant. I didn't check that everyGrant is now used.
bun x tsc --noEmit is clean. The trace tests plus private-by-default and account-purge pass, 72 in all. I didn't run the full suite. scripts/fast.ts said the diff was too broad to name tests, so the forge's check on this push will run the rest.
scripts/unused-exports.ts prints 182 lines on this branch against 181 on main. The extra line is readImported, the entry I added to the allow list. I didn't confirm that the script's output is a list of unlisted exports, so I can't say it passes.
Pushed as 7ce70fd. The import tests, the account-purge and trace-index tests, tsc, and the OpenAPI, module-state, unused-exports and doors tests pass. I did not run the full suite; the forge runs it on the push.
What changed
- Purge (finding 1):
purgeAccounttakesdataDir. It lists the person's imported ids fromtrace_index WHERE owner = ?before the transaction and deletes theirtraces/imported/<id>.jsonl.gzfiles once it commits. A new account-purge test fails without this and also checks that another account's file stays. - Quota (finding 2): each account may keep 256 MiB of compressed imports (
IMPORT_QUOTA_BYTESinsrc/trace/import.ts). It is checked after gzip and before writing, and re-sending a session counts only the new copy. A session over the quota gets a 413 withquota_exceeded, and a test covers it. The docs and the OpenAPI route now state the cap, and the "no quota" line is gone from the docs' "not yet" list. - Part files (finding 5): the
.partname now carries a random UUID, and a test runs two imports of one session at once. Intraces.tsthetrace/import.tsimport now sits beside the othertrace/import, and thelimits.tsimport now followscontext.ts. - Review kind (finding 4):
putTraceRowhas a comment saying imported rows are stored asreviewand told apart byowner <> ''. A new test checks that nokindfilter, including none, returns an owned row as areview.
What I left out
- Terminal listing (finding 3): I did not add one. The terminal Traces screen lists crew runs through
trace/list.ts, and imports are an API-only door (GET /api/v1/traces?kind=imported). The commit saysNo door:with that reason. I'd take a terminal screen for imports as a later issue. - Request-path cost: the decode, parse and gzip of a 32 MiB file still happen on the request path. Gzip is async, but
parseClaudeSessionis synchronous. The quota bounds disk, not CPU.
gate.ts still notes that importedIdsOf looks like ownedRepos; the two query different tables, so I left both.
Merged main into the branch and pushed; I didn't run the full suite, only the six trace test files, and those pass (45 tests) with tsc clean.
The merge conflicted in three places: docs/features/traces.md, src/http/api/traces.ts and src/http/lazy_lists.ts. Both sides stayed in each: POST /api/v1/traces/import from this branch and GET /api/v1/traces/:id (the trace tree) from main. In src/http/api/traces.ts the two imports from index_table.ts became one, and traceRoutes registers both routes.
I ran bun scripts/fast.ts and it said the diff was too broad to name tests, so I picked the trace files myself. The forge's check will run the full suite on this push.
The gate flagged two things I left alone:
- Duplicate-code note: it reports
importedIdsOfinsrc/trace/import.tsas identical toownedReposinsrc/core/account_purge.tsand asks whether they should share one implementation. - Long comment lines: two files have comment lines over 100 columns, which the nightly rewrap handles on
main.
Pull description: POST /api/v1/traces/import takes a Claude Code session JSONL (up to 32 MiB) and stores it gzipped. It is indexed as an imported trace, private to the caller. Re-sending a session replaces its trace. An account keeps at most 256 MiB of imported files, and they are deleted with the account. Not done: Codex files, a page for an imported trace, deleting a single one. Try it with the curl line in docs/features/traces.md.
POST /api/v1/traces/importnow takes a Claude Code session JSONL and keeps it as a private trace of kindimported.tscand the import, route-contract, migration, body-cap, route-mark and unused-export tests pass, and the gate is clean. I did not run the full suite, and the route-timing walk did not exercise the new route because it only walks GET routes. The forge's check runs everything.traceImportrow inBODY_CAPS, 32 MiB) and a plain 413 comes back past it. Needs anrwtoken. A browser session that sends the request cross-origin gets a 403. It answers 201 for a new session and 200 when the same session is sent again.traces/imported/<id>.jsonl.gzunder the data directory. The id is a hash of the account plus the session id, so re-importing replaces the trace instead of duplicating it. Another account importing the same session gets its own trace.GET /api/v1/traces?kind=importedlists the row for its sender and for nobody else. The row carries the first prompt as its title, the first model, steps, errors, tokens, and start and end times.src/trace/claude_code.tsis reused as the only parser. The adapter interface issrc/trace/import_adapter.ts, withimport_claude_code.tsas its one source. Codex is a new file plus one line inADAPTERS.invalid_session) says why when the file is not UTF-8, is empty, has no session records, or has no usablesessionId.docs/features/traces.mdhas the one-linecurlfor a Mac, andgetApiV1Traces.tsnow listsimportedamong the kinds. The test istest/traces-import.test.ts.Chosen deviations:
kindcheck ontrace_indexcan't be widened by a migration that only adds, which the gate requires. So the migration adds anownercolumn, an imported row is stored with kindreview(which nothing else writes), andlistTraceIndexreads it back asimportedand filters on that.kind=reviewstill returns only real review rows.readImportedhas no caller insrc/yet (the test uses it), so I added it to the dead-code allowlist for a later page to read.No door:for the terminal, since the import is acurland the list already shows the row.Left out:
Content-Encoding: gzipon the upload.Try it:
curl -X POST -H "authorization: Bearer $FORGE_TOKEN" -H "content-type: application/x-ndjson" --data-binary @session.jsonl $FORGE_URL/api/v1/traces/import, thenGET /api/v1/traces?kind=imported.🤖 Generated with Claude Code
Closes #18071