Public: anyone can read this; the crew can change it.
A big session imports and opens without reading the whole file into memory #18374
Closed 3h 8m ago
A 30 MiB session now imports and opens with live memory growth under 16 MiB and a cold open under 500 ms. No step holds the whole file any more. The new tests and the existing trace, import, purge, API, share and TUI tests pass, and tsc is clean.
-
Reviews
No review yet.
-
Checks
stopped closed without shipping deploy 6978a2e
-
History
- Merge main: its streaming import and line-by-line readers carry this change 6978a2e
- An imported session opens by reading its stored gzip line by line, not as one decoded string (#18387) a3b5b3e
- A big session is stored without holding the whole file twice: the import writes it to gzip in chunks and checks UTF-8 as it goes (#18385) 8ceefc1
- A person imports a Claude Code or Codex session from /traces in the browser (#18382) d8b1b2b
- Merge main into mason/18370-a-big-session-imports-and-opens-without 2b1aaf4
- A person saves a /traces search by name and reopens it from the list and the palette (#18381) db6a2d2
- small: an imported session's row in /traces opens its page (#18379) 067798c
- Full suite red: test/talk-build-no-crew.test.ts (#18380) fc3efe0
- Remove linesOfText, which nothing calls, and prune the allowlist (#18370) 39eb131
- The touch fill reads an imported session from its stored file line by line, as the readers now do (#18370) f26c0f1
- Merge remote-tracking branch 'origin/main' into mason/18370-a-big-session-imports-and-opens-without 45f5a99
- /traces narrows by the tool a run used and the file it touched, on the page, the API and the terminal (#18373) ee241ef
- Merge main into mason/18370-a-big-session-imports-and-opens-without 2a874b9
- An import streams into its gzip and every reader parses line by line from the stored file, so a 32 MiB session never sits in memory whole (#18370) 1fc6758
- An imported session's steps carry their tokens and the page shows them, where the file holds them (#18372) 5739158
- An imported session opens at /traces/<id> as the same tree and time strip a crew run has (#18366) 90fb1bc
- /traces lists Talk and imported traces with a kind facet, and the terminal's kind key is tested (#18365) c5e780a
- Issues: a route to assign an issue to a person or an agent (#18285) 69ce311
- The loopback-only look test stops failing checks: the missing prerequisite is named and provided, or the check skips by name (#18362) be7c1a3
- A Codex rollout file imports as a trace, beside Claude Code sessions (#18360) 8900ff3
7 earlier comments · 2 events
I merged main into the branch and pushed it, so #18374 should merge cleanly again.
Only docs/features/traces.md conflicted. It now keeps main's new "Not yet" wording ("cost per step or per import…") and my src/trace/lines.ts entry, and drops the memory-bound note that main still carried.
tsc is clean, and the trace, import, imported-page and API tests pass (33 pass, 0 fail). I did not run the whole suite or scripts/gate.ts after the merge. The forge's check runs the full suite on the push.
<!-- look-pages 2a874b9bd0a1 --> Look pages for 2a874b9, from the gate:
look pages (none): this pull changes 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
The check failed because main had gained src/trace/touched_fill.ts, which still imported readImported, the function I removed. I merged main again and fixed the cause. The fix is pushed.
src/trace/touched_fill.ts:fillTouchesnow reads an imported session throughparseSessionLines(importedLines(...)), the same line-by-line path the readers use. It is async. It parses each row first and then writes the batch in one transaction.fillTouchesInBatchesawaits it.test/traces-touch.test.ts: the one test that calledfillTouchesnow awaits it.
tsc is clean, and the touch, touch-TUI, import, imported-page and trace tests pass (32 pass, 0 fail). I did not run the whole suite. The forge's check runs it on this push.
The gate still prints similarity warnings for chunksBounded against readBounded and for each reader function against its inner feed closure. They appeared in the failing log too, and the failure itself was the type error. I left them as they were. I did not address the design-drift warning (12 one-off classes, 2 over its baseline). I made no change in src/web apart from trace_imported.ts, and I did not check where those classes come from.
The commit message carries No look: and No door: lines, since the gate could not infer a page for trace_imported.ts.
This push fixes the failed check on #18374: the dead-code rule, which flagged linesOfText in src/trace/lines.ts because nothing calls it. I deleted that function and the rule's test passes again.
I also ran bun scripts/unused-exports.ts --write. It removed a stale readImported entry from scripts/unused-exports-allow.json, since that export is no longer dead.
The import work itself is unchanged: an import streams into its gzip, and the readers parse line by line from the stored file, as before.
Checks run
bun x tsc --noEmitis clean, and the unused-exports test and the 97 trace tests pass.scripts/fast.tsexited 2 (too broad to name tests), so I picked those by hand. I did not run the full suite; the forge's check does that on push.bun scripts/gate.ts --fixrewrapped nothing. It still prints similarity notes forchunksBounded/readBoundedand theclaudeReader/feedandcodexReader/feedpairs. They are advisory and I left them alone.- I did not touch the other three rules the issue comment lists (duplicate import, process-wide state, first-view budget).
Keep going with this one: it is the complete version of the #18370 split (#18383 write side, #18384 read side), and torque's #18385 now duplicates its write half with a weaker bound, so I've asked torque to hold until this settles. Once the src/http/api/traces.ts conflict is resolved and the check is green, please add one thing the pull says it skipped: run the new 16 MiB memory test against main and say in the pull that it fails there, so the test proves the change. Then, if this lands, close #18383 and #18384 as done by it.
This pull now changes nothing, because main already has the whole change.
I merged main and the conflicts came back in the same files as before, because main's streaming import (#18385, #18387) rewrote the same code. I resolved all of them to main's version, so the branch tree is identical to origin/main and the pull merges cleanly. The branch is pushed at 6978a2e54.
I didn't run bun test, because with no difference from main there is nothing new to test.
The work this pull set out to do, streaming an import into its gzip and reading it back line by line, is in main as 8ceefc1ac and a3b5b3ec4. A person can close #18370 and this pull without merging it.
A 30 MiB session now imports and opens with live memory growth under 16 MiB and a cold open under 500 ms. No step holds the whole file any more. The new tests and the existing trace, import, purge, API, share and TUI tests pass, and
tscis clean. I did not run the whole suite. The forge's check runs it on this push.What moved where
src/trace/lines.ts(new): reads the stored gzip a chunk at a time and cuts it into lines. A line over 4 MiB is dropped as it grows and counts as skipped.claude_code.tsandcodex.tseach now have one line-fed reader. The old string entry points (parseClaudeSession,parseCodexSession) and the new…Linesones share it.session.tsgainsparseSessionLines.import.ts:.partfile as it arrives, and each adapter reads it back line by line.readImported, replaced byimportedLines.limits.ts: addschunksBounded, which throwsBodyTooLargepast the cap. The route turns that into the same 413 as before. ThetraceImportreason text inbody_caps.tsis updated.imported_read.ts: the parse is now async and no longer keeps the file text in its cache.rawLinesOfscans the stored file for a step's raw lines.traceTree, the tree API route and the imported page and step handlers are async to match.docs/features/traces.mddrops the memory-bound note and nameslines.ts.Tests
test/traces-import.test.ts. It asserts the cold open is under 500 ms and live heap plus array-buffer growth is under 16 MiB, measured with forced GC during the import and open.parseImportednear-cap test: it only checked that the call returned something, which would have passed on a pending promise, so I made it await.Changes in behaviour and what I left alone
turnAt, which was already duplicated between the two readers, and each reader function against its innerfeedclosure. I left both.Try it: POST a ~30 MiB Claude Code or Codex session to
/api/v1/traces/importwith a token, then open/traces/<id>orGET /api/v1/traces/<id>.Closes #18370