Repository navigation
perf(codex): stream large CLI session JSONL scans - #115997
vincentkoc merged 9 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 2:31 PM ET / 18:31 UTC. ClawSweeper reviewWhat this changesThe branch adds chunked JSONL scanning to Codex CLI session discovery, tests large records and fail-soft read failures, and renames a Codex native-hook matcher constant. Merge readinessKeep this PR open for normal maintainer review. The supplied evidence shows a focused, real runtime memory improvement with output-parity checks, but the evidence ledger is bound to Priority: P3 Review scores
Verification
How this fits togetherThe bundled Codex plugin reads Codex history and rollout JSONL files from the local Codex home directory to produce session summaries for the flowchart LR
A[Codex history JSONL] --> C[Session JSONL reader]
B[Rollout JSONL files] --> C
C --> D[Session summary extraction]
D --> E[Session discovery and sorting]
E --> F[Node-host session list response]
F --> G[CLI resume and display flows]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +96, Tests +159. Total +255 across 4 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the bounded streaming reader if current-head focused validation confirms that existing Codex session discovery returns the same summaries and remains fail-soft for unreadable or malformed JSONL files. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug report: the PR provides a concrete production-command benchmark and parity scenario rather than a report of failing existing behavior. Is this the best way to solve the issue? Unclear pending current-head validation. Extracting a shared streaming JSONL reader is a maintainable boundary, but the final merge result should demonstrate parity because this replaces the read path for existing session data. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 97d374b357eb. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
…o pr-115997-merge-proof * refs/remotes/origin/pr-115997-head: refactor(codex): isolate JSONL line scanning test(codex): prove streamed rollout recovery perf(codex): avoid rescanning long rollout records perf(codex): keep small JSONL reads fast perf(codex): scan JSONL in bounded chunks fix(codex): stream CLI session JSONL scans
Dependency graph guard clearedThis PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh
|
|
Maintainer validation complete on exact head
The ClawSweeper current-head proof move is addressed. The extra constant rename fixes the unrelated red env-var ratchet without raising its budget. |
|
Merged via squash.
|
[AI-assisted]
What Problem This Solves
The production
codex.cli.sessions.listnode-host command read Codex history and every discovered rollout JSONL withfs.readFile(..., "utf8")and then split the complete string into lines. A large rollout therefore required whole-file UTF-8 storage plus the split-line projection before a session list could be returned, and history-backed sessions could trigger another whole-file read just to inspect the first line.Why This Change Was Made
JSONL files above 4 MiB now use 1 MiB reads, streaming UTF-8 decoding, fragment-based LF/CRLF framing, and 64 KiB chunks for first-record hydration. Fragments are joined once when a physical record ends, preventing repeated rescans when a record spans many chunks. First-record hydration still reads and materializes the complete first physical record before parsing it. Files at or below 4 MiB retain the whole-file parsing path. Stat, open, read, malformed-line, empty-file, and filename-fallback behavior remains fail-soft.
User Impact
Large Codex history and multi-record rollout files no longer require one complete decoded file plus a split-line array. Through the registered production command, a deterministic 5,184,166-byte history plus matching 134,597,716-byte rollout produced byte-identical Base and Head output while median external maximum RSS fell from 1,652,629,504 to 921,903,104 bytes (44.2%). Streaming memory is still proportional to the largest physical JSONL record because that record must be materialized once for
JSON.parse. Session sorting, filtering, limits, previews, cwd hydration, history precedence, and resume behavior are unchanged.Evidence
Codex review:
gpt-5.6-sol(xhighreasoning) returned clean with 97% overall confidence on exact heada6a828d83c105b03f3b26a9e8289a979c5ff6d00.At detached clean exact head
a6a828d83c105b03f3b26a9e8289a979c5ff6d00, 9/9 focused tests and all 22 extension gates passed. An npm-built and isolatedly installed Codex artifact ran the registered command over a 5,252,808-byte rollout. Base/Head output remained identical over the 139.78 MB high-water fixture while median maximum RSS fell 44.2%.Inspect exact-head proof ledger
Provenance
d7864458a7e0d128013bd15e46d92a7c6410d96da6a828d83c105b03f3b26a9e8289a979c5ff6d00Direct behavior
External three-path maximum-RSS comparison command
/usr/bin/timemaximum RSS was 1,652,629,504 bytes on Base and 921,903,104 bytes on Head, a 44.2% reduction. Result: all six retained runs passed the source-identity and boundary-value assertions and returned the same 1-session, 66,088-byte output; median external maximum RSS fell by 730,726,400 bytes (44.2%). Proves the change preserves output, split UTF-8 decoding, and CRLF framing while exercising the large history scan, matching large-rollout first-record hydration, and full large-rollout summary scan at the registered command boundary. Preserves production plugin registration, filesystem ownership, JSON response identity, and node-host command behavior.Redacted exact-head production transcript
Automated verification
Codex CLI session reader
node scripts/run-vitest.mjs extensions/codex/src/node-cli-sessions.test.ts— [TEST] 1 test file passed with 9/9 tests, 0 failures, and 0 skips in a detached clean exact-head worktree; raw sanitized stdout/stderr is retained at the immutable artifact commit. Proves history-absent rollout metadata survives a single 5 MiB physical record spanning chunks; a later EIO discards the partial summary and closes the handle; a rejected close remains fail-soft after a complete summary. Preserves history precedence, cwd hydration, UTF-16-safe previews, malformed payload handling, history-absent discovery, and failure recovery.Exact-head extension gate
OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1 node scripts/check-changed.mjs --base d7864458a7e0d128013bd15e46d92a7c6410d96d --head a6a828d83c105b03f3b26a9e8289a979c5ff6d00 --timed— [STATIC] all 22 selected checks passed, including extension production and test typechecks, changed-file lint and format, plugin SDK API and boundary checks, dead exports, package policy guards, and runtime import cycles. Proves the exact three-file change satisfies the repository's extension production and test static gates at the reviewed head. Preserves plugin SDK boundaries, dependency policy, formatting, type safety, lint invariants, and runtime-cycle constraints.Packaged Codex runtime
node scripts/lib/plugin-npm-runtime-build.mjs extensions/codex && node scripts/lib/plugin-npm-package-manifest.mjs --run extensions/codex -- npm pack --json --ignore-scripts --pack-destination "$PACK_ROOT"— [BUILD] the exact-head package build emitted 45 JavaScript runtime files, npm pack produced one 453,161-byte@openclaw/codextarball, and the manifest advertised./dist/index.jsas the runtime entry. Proves the new streaming JSONL module is included in the shipped plugin build rather than existing only in TypeScript source. Preserves publishable Codex package metadata, runtime dependencies, and host plugin-SDK externalization.node "$PROOF_RUN/package-installed-smoke.mjs" "$IMMUTABLE_HEAD_CHECKOUT" "$INSTALL_ROOT" "$CODEX_PLUGIN_TARBALL" "$HEAD_SHA"— [BUILD] an isolated npm installation loadeddist/index.js, found the bundled streaming runtime, registeredcodex.cli.sessions.list, and returned the expected session id, cwd, message count, and last message from an 82-record, 5,252,808-byte rollout; no affected owner was mocked. Proves the package-installed production command crosses the 4 MiB streaming threshold and is loadable and behaviorally correct from the npm artifact. Preserves plugin registration, packaged runtime resolution, filesystem ownership, and command response semantics.Preserved boundaries
Proof gap
A multi-hundred-megabyte genuine default-store rollout, isolated small-file benchmark, Windows filesystem run, and provider-backed turn were not run. The external high-water proof uses a deterministic 5,184,166-byte history plus matching 134,597,716-byte rollout through the real registered command; the separate genuine default store contains a 5.28 MB rollout above the threshold. Streaming memory remains proportional to the largest physical JSONL record because
JSON.parsematerializes that record once, including the complete first record during hydration. No constant-memory-per-record, small-file performance, giant-rollout OOM-rate, provider-turn latency, or Windows-specific claim is made.Artifacts
Validated exact PR head
9ff87aea598b08ca26dda87f585b9322f59a0856against base97d374b357ebe2d389a9d512d70e689fd1af85cbon July 29, 2026. GitHub reports the intended four-file diff (285 additions, 30 deletions).node-cli-sessions.test.ts9/9 andnative-hook-relay.test.ts15/15 passed. The Codex package build emitted 45 runtime files; the packed artifact containeddist/index.jsand the session-catalog runtime chunk. Run: https://github.com/openclaw/openclaw/actions/runs/30480051596a05bcda3dbd68729caa2f11027b7f43974fda298: history is line-delimited JSON incodex-rs/message-history/src/lib.rs, and rollout discovery is line-oriented and fail-soft incodex-rs/rollout/src/list.rsandcodex-rs/rollout/src/recorder.rs.ClawSweeper rank-up move addressed: current-head focused session-reader and packaged-command/runtime evidence is refreshed on the actual merge head.