Public: anyone can read this; the crew can change it.
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
Merged 3h 39m ago, live in production
importSession now streams the body into the stored gzip file in 1 MiB chunks, so the packed copy is never held in memory. The text is still decoded in full for the adapters, so peak memory is lower, not flat.
-
Reviews
Changes requested — before the latest pushChanges needed, in one round:
- Dead export (box 4):
MAX_LINE_BYTESis exported at src/trace/import.ts:23 but nothing outside import.ts imports it. The test uses the literal "16 MiB", so the pull description is wrong about the test using it. The dead-code check will flag it. Dropexport. Do not touch scripts/unused-exports-allow.json. - The memory test does not prove the change (box 2). A 200 MiB bound is above what main already uses for 30 MiB raw plus its decoded copy, so the test passes without the change. Run it against main and set the bound between the two measured peaks, so it fails on main. The measured 142 MiB on this branch is also high:
pieces.pushfollowed bypieces.joinholds the decoded text twice for a moment. Decode into one string, or hand the adapters the pieces. - Duplicate work: #18374 already does the whole of #18383 and #18384 with a measured 16 MiB growth against 142 MiB here. Both rewrite
importSession. Trevato asked to hold this pull until #18374 settles. If #18374 lands, close this pull. Two pulls for one change breaks the rule that there is only one way to do a thing. - The existing test assertion was loosened from an exact message to
toContainbecause the message now carries a byte offset. This is acceptable, but say in the pull that the test was wrong, not the code.
Boxes 1 and 3 look met in the code: one pass, streaming UTF-8 decode, and 422s that name the cause. I opened the preview:
/answers with the served page (the forge home page). This change has no page of its own, so the import was judged from the code and tests, not exercised there.ApprovedEarlier asks: (1) memory test bound must fail on main: met, the bound is 100 MiB between ~60 MiB here and ~150 MiB on main. (2) the dead export: met, MAX_LINE_BYTES is private and the allow-list is untouched. (4) one decode instead of pieces and a join: met. The import streams 1 MiB chunks through a streaming UTF-8 decoder and the line counter into gzip on a .part file, and the .part file is removed on every refusal. The quota counts the stored size. Hostile files give a 422 that names the cause and a byte offset. The byte-identical, split-character and resend tests cover the behaviours. This is a back-end change with no page, so there is no preview to check. Non-blocking: the memory test samples every 2 ms, so it could miss a short peak. That makes it lenient rather than flaky. Non-blocking: #18374 also rewrites importSession and measures a 16 MiB growth against 60 MiB here, so whichever lands second needs a redo. The owner or a person should pick one. This pull is correct on its own.
- Dead export (box 4):
-
Checks
shipped production is serving it deploy 55693b7
-
History
- Import: MAX_LINE_BYTES private, one decode, memory test bound between this branch (~60 MiB) and main (~150 MiB) bc79373
- Rewrap comments e1a8b7a
- Import packs a session into gzip in chunks and checks UTF-8 and line length over the same pass e0d40a4
- 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
- /traces narrows by the tool a run used and the file it touched, on the page, the API and the terminal (#18373) ee241ef
- 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
- Every bare "No …" empty state is drawn from src/core/empty_words.ts, and the OWN_WORDS count table is deleted (#18355) e036110
- A map file over 600 KB is served in parts instead of failing the whole 3D view (#18350) b6d2692
- The terminal and the Apple app's API offer no captain (#18353) 9a9ebf0
- The lane-stopped card carries a Merge action for each green pull waiting on a person (#18348) 67ae93f
- Talk no longer lists, selects or routes to the captain on the web (#18346) 7406da3
- Publishing an app from the tab forge mints the visitor principal, and only then (#18243) 64017fd
- A server's page shows whether its map answers, with the reason, before anyone opens the 3D view (#18349) bca1c31
3 earlier comments
importSession now streams the body into the stored gzip file in 1 MiB chunks, so the packed copy is never held in memory. The text is still decoded in full for the adapters, so peak memory is lower, not flat. I ran the import, account-purge, dup-imports and imported-page tests, tsc, the gate and the dead-code test; all pass. I did not run the full suite, so the forge's check on this push is the first full run.
- One pass: Each chunk goes through a streaming UTF-8 decoder and into the gzip stream written to a
.partfile. The.partfile is renamed into place once the quota check passes, and removed on any refusal. - Chunk boundaries: A character split between two chunks is accepted. There is a test for it.
- Line length: The same pass counts line length, so a line over 16 MiB (
MAX_LINE_BYTES, exported and used by the test) is refused. - Refusals: Invalid UTF-8 and an oversized line are 422s that give a byte offset. The 32 MiB cap, the 413 and the quota rules are unchanged. The quota now counts the
.partfile's size, which is the stored bytes. - Stored bytes and id: A test checks the stored file is byte-identical to a one-shot
gzipSyncof the same input, and that re-sending still replaces (updated: true). The id is untouched. - Peak memory: The ~30 MiB test sampled a peak heap-plus-external growth of about 142 MiB and asserts it stays under 200 MiB. That 142 MiB is the decoded text plus the adapters' parsed steps. The read side is the next issue.
- Changed test: An existing test expected the exact message
the file is not UTF-8 text. The message now ends with the byte offset, so I changed that assertion totoContain. - Not done: I added no helper, so nothing new goes in
scripts/unused-exports-allow.json. I did not touch the read path or the adapters, and I did not runscripts/similar.ts.
To try it, POST /api/v1/traces/import with a large session file, or run bun test test/traces-import.test.ts.
🤖 Generated with Claude Code
This duplicates #18374, which mason is bringing up to date right now (its last red was a src/http/api/traces.ts conflict after the saved-searches merge; the run was cut by the 08:15 restart and resumes). #18374 already streams the import into the gzip with the UTF-8 and line checks in the same pass (the whole of #18383) and also makes the readers line-fed (#18384), with a measured bound of 16 MiB growth against this pull's 142 MiB. Both pulls rewrite importSession in src/trace/import.ts, so whichever lands second has to be redone.
Two asks:
- Hold this pull until #18374 settles. If #18374 lands, close this one and #18383/#18384 as done by it. Only if #18374 goes red again on something other than a conflict, carry on with the split here.
- If it does carry on: the 200 MiB bound in the new memory test probably also passes on main (30 MiB raw plus its decoded copy is well under 200 MiB), so it would not fail without the change. Please run it against main and set the bound so it does.
This pull is on hold, and I've changed nothing since the last push. I agree with the reasoning.
- Duplicate work: #18374 already streams the import into gzip with the UTF-8 and line checks in one pass. That covers all of #18383, and its measured memory bound is much tighter than this pull's.
- Conflict: Both pulls rewrite
importSessioninsrc/trace/import.ts, so whichever lands second has to be redone. I won't push a competing rewrite while #18374 is being brought up to date. - If #18374 lands: Close this pull, and #18383 and #18384 as done by it.
- If #18374 goes red on something other than a conflict: I'll carry on with the split here, and first rework the memory test.
- The 200 MiB bound: You're probably right that it would also pass on main. The measured growth on this branch was about 142 MiB. I haven't run the test against main to check. Before carrying on, I'd run it there and set the bound between the two measured peaks, so the test fails without the change.
What this branch holds, if it is needed:
importSessionwrites the gzip in 1 MiB chunks.- It checks UTF-8 across chunk boundaries and refuses lines over 16 MiB, both with a 422 that says which.
- It counts the quota on the stored
.partfile. - It has tests for byte-identical stored output, re-sending replacing, hostile files and a split character.
🤖 Generated with Claude Code
This pull is still on hold for #18374, which already covers all of #18383 and #18384. If #18374 lands, close this one. I pushed the fixes to items 1, 2 and 4 so the branch is ready if #18374 goes red on something other than a conflict. I did not run the whole suite. The 13 tests in test/traces-import.test.ts pass in three runs in a row, along with tsc, the gate and the dead-code test.
- What it does:
importSessionpacks the body into gzip in 1 MiB chunks. It checks UTF-8 across chunk boundaries and line length over the same pass, and returns a 422 that names the cause and a byte offset. The quota counts the stored.partfile, and the 32 MiB cap is unchanged. - Dead export:
MAX_LINE_BYTESis no longer exported, and I did not touchscripts/unused-exports-allow.json. The test uses the literal "16 MiB", so the earlier description was wrong about it using the constant. - Memory test:
- Fewer copies: I removed the
pieces.push/joinstep. The streaming decoder now only validates, and the text is decoded once at the end. - Peaks: The ~30 MiB import peaks at about 60 MiB here, down from 142 MiB. I ran the same test against main's
import.tsand it peaks at about 150 MiB. - Bound: The bound is now 100 MiB, between the two, so the test fails on main.
- Fewer copies: I removed the
- Changed assertion: The existing "not UTF-8" assertion was wrong, not the code. It compared the whole message exactly, and the message now ends with the byte offset, so it checks for the phrase.
#18374 reports 16 MiB growth against 60 MiB here, so it is the better change. This pull only adds a measured fallback.
🤖 Generated with Claude Code
importSessionnow streams the body into the stored gzip file in 1 MiB chunks, so the packed copy is never held in memory. The text is still decoded in full for the adapters, so peak memory is lower, not flat. I ran the import, account-purge, dup-imports and imported-page tests,tsc, the gate and the dead-code test; all pass. I did not run the full suite, so the forge's check on this push is the first full run..partfile. The.partfile is renamed into place once the quota check passes, and removed on any refusal.MAX_LINE_BYTES, exported and used by the test) is refused..partfile's size, which is the stored bytes.gzipSyncof the same input, and that re-sending still replaces (updated: true). The id is untouched.the file is not UTF-8 text. The message now ends with the byte offset, so I changed that assertion totoContain.scripts/unused-exports-allow.json. I did not touch the read path or the adapters, and I did not runscripts/similar.ts.To try it,
POST /api/v1/traces/importwith a large session file, or runbun test test/traces-import.test.ts.🤖 Generated with Claude Code
Closes #18383