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

An imported session opens by reading its stored gzip line by line, not as one decoded string #18387

opened this

Merged 2h 31m ago, live in production

Opening an imported session now reads its stored gzip as lines instead of one decoded string. It still inflates the file once into a buffer. bun x tsc --noEmit is clean and the trace and import tests pass.

Notes

opened this

Opening an imported session now reads its stored gzip as lines instead of one decoded string. It still inflates the file once into a buffer. bun x tsc --noEmit is clean and the trace and import tests pass. I ran the dead-code and duplicate-import tests, and the gate's --fix and --explain modes. I did not run the first-view budget or process-wide-state tests, or the full check.

What changed

  • src/trace/lines.ts is new and holds the shared line-stream helper. asLines makes lines from a string, gzipLines/bytesLines walk the inflated bytes one line at a time, and own copies a short string out of its line.
  • claude_code.ts, codex.ts and session.ts take lines or a string, and isCodexFile looks at only the first 20 lines. Output is unchanged for the existing fixtures, and an invalid line still counts in skipped as before.
  • readImported became importedLines; imported_read.ts and touched_fill.ts call it.
  • ImportedParse no longer keeps the file's text, so the cache holds only traces. rawLinesOf now takes lines, and the step page passes it the stored file's lines. parseCount still hits: one parse serves the page and its steps.
  • The memory-bound note is gone from docs/features/traces.md.
  • No export lands without a caller and scripts/unused-exports-allow.json is untouched.

Memory

  • With zlib's sync API the inflate cannot be streamed, so the inflated bytes (about 30 MiB for this file) are held once, not also as a string and its pieces.
  • parseClaudeSession and parseCodexSession cut strings out of each line, and those strings kept the whole 4 KB line alive. Cutting them through own took the live set during a parse of the generated 30 MiB session from about 61 MiB to about 39 MiB.
  • True flat memory would need async streaming, which touches every caller of parseImported. I left that out.

Tests

  • test/trace-imported-open.test.ts opens a generated session of about 30 MiB. It checks that the open takes under 500 ms and that the live heap, sampled with a garbage collection every 500 lines, stays under file size plus 15 MiB. It also checks that the parse cache hits once and that an invalid line degrades to skipped.
  • The existing near-cap test in test/trace-imported-page.test.ts now asserts under 500 ms instead of 2000 ms.
  • I only ran the new memory test against the new code. The bound is below the 61 MiB live set the old way measured, so I expect it to fail there.
  • test/traces-import.test.ts now uses importedLines. That is the only test I changed other than the page test's time bound.

Try it: import a session at /traces, open it, then open a step's raw lines at /traces/<id>/steps/1.

[{"go":"/traces","look":"the imported session's row","expect":"it opens as before, with the same steps and totals"},{"go":"/traces/<id>/steps/1","look":"the raw lines","expect":"the same raw lines as before, read from the stored file"}]

Closes #18384

commented

Opening an imported session now reads its stored gzip as lines instead of one decoded string. It still inflates the file once into a buffer. bun x tsc --noEmit is clean and the trace and import tests pass. I ran the dead-code and duplicate-import tests, and the gate's --fix and --explain modes. I did not run the first-view budget or process-wide-state tests, or the full check.

What changed

  • src/trace/lines.ts is new and holds the shared line-stream helper. asLines makes lines from a string, gzipLines/bytesLines walk the inflated bytes one line at a time, and own copies a short string out of its line.
  • claude_code.ts, codex.ts and session.ts take lines or a string, and isCodexFile looks at only the first 20 lines. Output is unchanged for the existing fixtures, and an invalid line still counts in skipped as before.
  • readImported became importedLines; imported_read.ts and touched_fill.ts call it.
  • ImportedParse no longer keeps the file's text, so the cache holds only traces. rawLinesOf now takes lines, and the step page passes it the stored file's lines. parseCount still hits: one parse serves the page and its steps.
  • The memory-bound note is gone from docs/features/traces.md.
  • No export lands without a caller and scripts/unused-exports-allow.json is untouched.

Memory

  • With zlib's sync API the inflate cannot be streamed, so the inflated bytes (about 30 MiB for this file) are held once, not also as a string and its pieces.
  • parseClaudeSession and parseCodexSession cut strings out of each line, and those strings kept the whole 4 KB line alive. Cutting them through own took the live set during a parse of the generated 30 MiB session from about 61 MiB to about 39 MiB.
  • True flat memory would need async streaming, which touches every caller of parseImported. I left that out.

Tests

  • test/trace-imported-open.test.ts opens a generated session of about 30 MiB. It checks that the open takes under 500 ms and that the live heap, sampled with a garbage collection every 500 lines, stays under file size plus 15 MiB. It also checks that the parse cache hits once and that an invalid line degrades to skipped.
  • The existing near-cap test in test/trace-imported-page.test.ts now asserts under 500 ms instead of 2000 ms.
  • I only ran the new memory test against the new code. The bound is below the 61 MiB live set the old way measured, so I expect it to fail there.
  • test/traces-import.test.ts now uses importedLines. That is the only test I changed other than the page test's time bound.

Try it: import a session at /traces, open it, then open a step's raw lines at /traces/<id>/steps/1.

[{"go":"/traces","look":"the imported session's row","expect":"it opens as before, with the same steps and totals"},{"go":"/traces/<id>/steps/1","look":"the raw lines","expect":"the same raw lines as before, read from the stored file"}]
Sign in to join this conversation.

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

Keyboard shortcuts

Docs