Codex direct transcripts repeatedly materialize entire large rollout before paging
Correction after checking the contribution target
The released main/preview path still has the whole-file behavior described below, but current dev already contains the streaming byte-offset implementation from commits 4ef62ac3b369 and 78d9fcae7e9d. My initial statement that dev still called materializeCodexDirectTranscriptItems was incorrect; I had inspected the pinned preview and main before fetching the contribution target. Sorry for the noise.
I am now benchmarking the existing dev stream-vector implementation against the real 239 MiB rollout before proposing any code. If it resolves the repeated whole-file work, this issue should track promotion/release validation rather than a duplicate persistent index.
Problem in released main/preview
Codex direct-session transcript.page and transcript.readAfter in released main/preview call materializeCodexDirectTranscriptItems, which reads every matching rollout with readFile(..., "utf8"), splits and parses every JSONL line, materializes every direct item, sorts the complete result, and only then applies maxItems / maxBytes.
Observed with a real Codex thread whose rollout is approximately:
- 239 MiB
- 100,750 JSONL lines
- 40,176 materialized direct transcript items
Requesting the latest 30 items on that released path still parses and materializes the complete rollout. Loading an older page and readAfter repeat the same complete work. The daemon process reached roughly 711 MiB RSS during the test session; that number includes other daemon state and is not claimed as transcript-only memory.
Existing dev implementation to validate
Current dev deletes materializeCodexDirectTranscriptItems from this path and introduces:
- bounded backward paging through
jsonlBackwardPager - append-only forward reads through
jsonlForwardReader - stream-vector cursors with rollout boundary fingerprints
- reset/truncation detection for replaced or rewritten files
- bounded child-thread discovery
This is architecturally preferable to adding a second persistent index unless measurement reveals a remaining repeated-scan bottleneck.
Validation being run
- latest 30 from the 239 MiB rollout
- second older page
readAfterat tail and after append- memory/time comparison with the pinned preview
- transcript parity around tool/subagent boundaries
AI assistance disclosure
The investigation is assisted by OpenAI Codex. I reproduced the issue locally, corrected the branch comparison above after fetching dev, and will report exact commands and measurements.
Validation result: current dev already resolves the whole-file paging problem. Against the real 239 MiB / 100,750-line rollout, the core pageCodexTranscript call returned the latest 30 items in about 35 ms with bounded byte-offset paging. I am therefore not proposing a duplicate persistent SQLite/materialized cache.
During validation I found a separate correctness gap in the existing bounded child-discovery path (late SubAgent spawns beyond 1 MiB / 512 entries). That is tracked in #324 with draft fix #325. This issue can be closed or retained as release/promotion tracking for getting the existing stream-vector implementation from dev into preview/stable.
Closing as already implemented on dev; see the validation above. The remaining late-child bug is split into #324 / #325.
A separate, reproducible no-progress condition affects large Direct transcript records in stable 0.2.16.
A synthetic JSONL fixture containing one response item with a nine-MiB placeholder tool result reproduces this without any private session data. Requesting a backward page with a smaller byte budget returns zero parsed items, reports that the start was not reached, and leaves the next end offset unchanged. The higher-level Direct pager can therefore keep reporting more history with the same cursor.
The backward reader permits an oversized first line only up to its configured oversize ceiling. Once that ceiling is reached without a complete line, its fallback offset remains the original end offset. The importer can repeatedly request that same page until its page budget is exhausted instead of reporting the oversized record.
Synthetic reproduction
- Create a disposable JSONL fixture with a single response item containing a placeholder tool result larger than the default oversize-line allowance.
- Request a backward page with a smaller byte budget and repeat using the returned offset or cursor.
- Check that the result remains empty and the offset does not advance, while more history is still indicated.
Expected behavior
Every successful continuation must consume source data or explicitly report why it cannot. A record that cannot fit within the permitted bounded read should produce an actionable oversized-record result, rather than an unmarked paging loop. A full-history import must not silently skip or truncate the record.
Verified recovery
A bounded larger read consumes the synthetic record intact. A local importer can detect unchanged continuation cursors and increase its bounded allowance or stop explicitly. Separately, increasing the read buffer size while retaining the same byte and item budgets produced identical native pages in comparison checks and reduced repeated buffer-copy overhead. The installed CLI was not modified.
This is distinct from the older whole-file materialization problem in this issue. No actual conversation text, logs, screenshots, identifiers, project details or file paths are included.
Thanks @RogueKostas — your 9 MiB reproduction confirmed a separate gap from the whole-file materialization issue originally fixed here.
Both bounded JSONL readers could exhaust their first-record allowance and return an empty page with an unchanged cursor. Full import then repeated that continuation until its page budget expired.
2f3bf27b61 corrects this at the shared reader boundary: exhaustion now fails explicitly. Existing allowances, cursor formats, incomplete-EOF handling, and intact reads with a larger allowance are preserved. Advisory title scans log the boundary without hiding the session.
Regression tests and a direct API reproduction pass. This is corrected in development source; released stable availability has not been verified. Once the correction reaches stage:stable, please retry the synthetic case and confirm it reports the read-allowance error instead of looping.
Posted on behalf of @leeroybrun.