Repository navigation
Replace patched JSON parser with stream-json - #25202
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change replaces Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No merge-blocking issue is established. The change is ready for normal CI validation. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 5 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 10 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Dependency swap — drops the patched
@streamparser/[email protected](and itsignoreBOMpatch) for exact-pinned[email protected]/[email protected], bundled into the desktop main process and the esbuild relay. - Shared token reader — new
createJsonTokenReaderdrives the library parser synchronously in bounded code-unit batches, preserving caller-owned UTF-8 decoding and surfacing parser failures asSyntaxErrorwhile letting consumer errors through. - Dense ripgrep parser — reimplemented as a manual frame stack over packed tokens, retaining projections, duplicate-key/field caps, depth and per-element token budgets, and full-record validation past the result cap.
- Streamed session parser — reimplemented on
FlexAssemblercustom rules with a discard fallback, preserving the root-array fold, object-field projection/precreate, duplicate-array reset, consumer-failure precedence, and non-object-rootnullresult. - Tests — contract, Unicode/BOM, malformed-input, prototype-key, source-cleanup, and exact budget-boundary coverage added or extended.
All automated checks I ran pass locally: focused parser tests (50), the full src/main/ai-vault/ suite (1057), the text-search suites (95), pnpm tc:cli, pnpm tc:node, and the changed-code quality gate. I also confirmed require('stream-json/core/parser.js') resolves under Node 24, which is what the CLI's Node20 module setting relies on.
ℹ️ Deep subpath imports couple the build to library internals
src/shared/json-token-reader.ts imports stream-json/core/parser.js, stream-chain/exec.js, and stream-chain/defs.js, and src/main/ai-vault/session-document-stream.ts imports stream-json/core/utils/flex-assembler.js. These paths resolve only through each package's blanket "./*": "./src/*" export map — stream-json's package index re-exports only the stream parser, so FlexAssembler's custom-rule API and the synchronous exec/none chain primitives have no public entry point. The exact pins make this correct today, but a patch or minor bump could reshape an internal module with no major-version signal.
Technical details
# Internal subpath coupling
## Affected sites
- `src/shared/json-token-reader.ts:1-3` — `stream-json/core/parser.js`, `stream-chain/exec.js`, `stream-chain/defs.js`
- `src/main/ai-vault/session-document-stream.ts:2` — `stream-json/core/utils/flex-assembler.js`
## Context
- `stream-json/src/index.js` exports only `{ parserStream, parser }`; `stream-json/assembler` exports the plain `Assembler`, not `FlexAssembler`, so the custom `objectRules`/`arrayRules` API is reachable only via `core/utils`.
- Both packages are pinned exactly and bundled (desktop via `BUNDLED_MAIN_DEPENDENCIES`, relay via esbuild), so the coupling is contained to the build rather than resolved at a user's runtime.
## Open questions for the human
- Worth a one-line comment at each import noting the pinned-version coupling, so a future dependency bump reviews these call sites?deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
72683e2 to
85e1fda
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Isolated the historical Bun build's dependencies — the persistent Linux job now installs the pinned Bun commit's own lockfile (
pnpm --dir "$RUNNER_TEMP/bun-orcad-source" install --frozen-lockfile --ignore-scripts) instead of symlinking$GITHUB_WORKSPACE/node_modules. That checkout no longer contains@streamparser/json, which the Bun commit's lockfile still requires, so the isolation is what keeps the cross-runtime build resolvable. - Updated the workflow contract test —
node-server-change-scope.test.mjsasserts the isolated install runs and that the old$GITHUB_WORKSPACE/node_modulessymlink is gone.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

ELI5
Replace our locally patched JSON parser with
stream-json. Search filenames and session text keep their Unicode characters without maintaining a dependency patch, and large search/session records parse faster.What Changed
Both consumers use one synchronous token reader with bounded input batches. Dense ripgrep records retain only the requested ranges while validating the complete record; streamed session documents use the library's configurable assembler to discard unused fields and fold messages as they arrive. The ordinary
JSON.parsesearch path is unchanged.Install the historical Bun-server compatibility fixture from its own frozen lockfile, so removing a current dependency cannot break the old-source test build.
Remove
@streamparser/jsonand its patch; pinstream-json3.7.0 andstream-chain4.2.6. Bundle both for desktop and remote relays. The CLI still emits CommonJS; its TypeScript module model now reflects the synchronous ESM loading supported by our existing Node 24 runtime.Why
The previous library silently removed U+FEFF inside JSON strings without our patch. This replacement passes the literal/escaped Unicode regressions without modification and improves both real consumer shapes. Staying on the patch avoids a migration but retains maintenance work; older CommonJS versions of
stream-jsonlack the newer prototype-key handling.There is a measured tradeoff: dense-search peak RSS increases by roughly 5–19 MiB. Smaller 8 Ki-code-unit batches reduce the large-record candidate peak from about 299 to 249 MiB without losing the speedup. Sessions keep 64 Ki batches, which measured better there. Memory still scales with the largest individual string/record and selected metadata; this is not a constant-memory guarantee.
Linked Issue
Follow-up to #25156; no separate issue.
Visual Proof
N/A — internal parsing and dependency changes, with no UI or interaction change.
Testing
orca --helpon macOS arm64.Measurements
Patched baseline at
f62bd7dc2098versus final migration, serial runs with three warmups followed by 12 counterbalanced pairs per fixture. Peak RSS is the mean of two fresh-process peaks per arm, with fixture generation outside those processes. Search timing excludes file loading; session timing includes streaming file reads, decoding, and cooperative yields. Both exclude process startup/imports. P95 is descriptive, not a statistical confidence bound.Dense parsing is 48–56% faster, streamed sessions 22–58% faster, and the ordinary search fast path is unchanged. The 51 MiB stress record remains synchronous (about 0.6 seconds versus 1.3 seconds); this migration does not introduce asynchronous search ingestion. Candidate session fresh-process maximum event-loop gaps stayed below 4.3 ms in these fixtures. Retained-heap deltas after forced GC stayed below 1.2 MiB except the ordinary fast-path fixture, which intentionally returns its 4 MiB text in full.
Reproduce
Use each revision's installed lockfile dependencies. At the baseline revision, bundle the two consumers into a persistent temporary directory:
At this PR revision, bundle the same entry points as
candidate-rg.mjsandcandidate-session.mjsinto that directory, then run:The checked-in harness generates valid synthetic ripgrep records and session fixtures, checks parity, reports raw samples and memory measurements, and removes its generated files. Keep other tests/builds idle while measuring.
Review
Independent adversarial reviews covered both consumers, the shared reader, malformed input, prototype keys, cancellation, resource limits, ESM/CommonJS compatibility, and benchmark validity. Initial benchmark fixture and measurement issues were corrected; final reviews are clean. Rebased on current main before opening; range-diff confirms the reviewed patch is unchanged.
Full dependency audit follow-up
Cloned both dependency repositories and reviewed all 129 runtime modules and 129 paired declarations, plus benchmark/build configuration. Upstream suites passed 1,206 tests and 2,575 assertions; both TypeScript/checkJs checks passed. Additional probes passed 64,000 JSON parser/verifier comparisons, 80 JSONC comparisons, and 20,000 path-matcher comparisons.
The libraries as a whole are not clean: confirmed issues include cancellation/handle cleanup, generic adapter allocation, file short writes, array-index paths, reviver/filter semantics, and declaration mismatches. None is reached by this integration: it uses the synchronous flattened executor, decoded strings, predicate-based projection without numeric array indices, and caller-owned I/O. No dependency patches were added. The chosen executor also measured faster than the two supported synchronous alternatives (44.7 vs 48.6/52.7 ms for token-only dense input); these are an additional microbenchmark, not replacements for the complete-consumer measurements above. A 100,002-token allocation probe created zero per-token promises.
Parser code and the before/after numbers are unchanged. The audit caught the Linux compatibility-build failure from linking historical source to current node_modules; it now installs that historical revision's frozen dependencies independently with scripts disabled. The actual old server build succeeded locally (Bun 1.4.2), 69 workflow contract tests passed, and an independent review found no remaining CI-fix issue. Both previously failing Linux persistence checks now pass on the updated head; remaining CI is running without failures at the audit close.
Agent skill upstream boundary
Checklist