Repository navigation
perf: avoid rescanning partial notebook output frames - #23138
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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe notebook frame reader now uses the shared incremental NDJSON parser and processes completed records immediately. It warns about unreadable records and passes valid parsed values through frame validation. The shared framer skips UTF-8 byte measurement when the line limit is unbounded. Tests cover chunk boundaries, buffering, malformed and unsupported records, large display data, scan limits, and consumer exception propagation. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The notebook frame reader appears mergeable after normal checks; no specific behavior change requiring a fix was identified. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new reader preserves frame validation and does not appear to expose a new entrypoint. It does, however, parse and hold every complete record in an incoming chunk before delivering the first frame, which could increase memory use when notebook output is unusually dense. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 — the notebook kernel reader's output framing was rewritten to reuse the shared incremental NDJSON parser instead of re-splitting a growing buffer on every chunk.
- Shared parser replaces hand-rolled framing:
createFrameReadernow feeds chunks throughcreateNdjsonParser, which keeps the pending partial record in segments and only revisits the new chunk — removing the quadratic rescan that dominated large image outputs. parseFramede-parses: parsing moved into the shared parser, soparseFramenow takes an already-parsedunknownand only validates/normalizes the record shape.- Unrestricted size preserved:
maxLineBytes: Number.POSITIVE_INFINITYis passed so the shared parser's 16 MiB transport cap does not start dropping existing notebook display frames. - New focused suite:
notebook-frame-reader.test.tsadds 8 cases covering the delimiter-work budget, split-boundary Unicode, malformed/unsupported/CRLF lines, >16 MiB records, incomplete suffixes, consumer exceptions and reentrancy.
I read the shared framer in full and confirmed frame parity with the previous reader: same \n-only framing, whitespace-only lines skipped, malformed JSON swallowed, non-record JSON dropped, CRLF tolerated by JSON.parse, ordering preserved, and the partial suffix retained before delivery. The framer's pause/pendingInput machinery stays inert without a shouldPause, so records are delivered synchronously within the same feed, matching the old semantics. Both test files pass locally (9 passed / 2 skipped) and pnpm tc:node is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The reader buffered every record of a chunk before delivering the first one, and asked the framer for byte accounting it can never use. An unbounded line limit cannot reject, so the per-segment `Buffer.byteLength` and the rejection-prefix retention were pure overhead for the notebook and Codex readers; both are now skipped once, behind a hoisted check. Frames are handed to the consumer as each line completes, so the first output of a chunk paints without waiting for the last. The dropped buffer only ever preserved a trailing partial record across a consumer throw, which cannot help: that throw leaves the stdout 'data' listener and takes main down with it. Rejections are no longer discarded either — the bridge keeps fd 1 to itself, so an unreadable line means the frame channel is damaged and now says so. Tests move into notebook-kernel.test.ts beside the reader's existing coverage, and add the never-terminated record and a guard that no record bytes are measured when no limit applies. Co-authored-by: Claude <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the notebook frame reader was simplified to stream bridge records directly through the shared parser, and the shared framer picked up an unbounded-limit fast path.
- Direct streaming replaces the pending buffer:
createFrameReadernow handschild.stdoutchunks straight tocreateNdjsonParser;parseFramestill validates/normalizes each parsed value. The intermediatependingarray (and its reentrancy-dependent semantics) is gone. - Unreadable records now warn:
onErrormaps toconsole.warn('[notebook-kernel] …'), so malformed bridge lines are surfaced instead of silently dropped; non-record JSON shapes remain silent. - Unbounded fast path in the shared framer: when
maxLineBytes === Infinity, segment byte measurement and rejection-prefix retention are skipped, since no line can exceed the limit. This also activates for the codex reader, which likewise passesInfinity. - Test consolidation: the standalone
notebook-frame-reader.test.tswas folded intonotebook-kernel.test.ts.
I read the shared framer in full and traced the unbounded path: with maxLineBytes = Infinity, the derived maxPendingInputBytes/queue caps are Infinity too, so the skipped rememberPrefix and line-length rejection are statically unreachable, and the unterminated-record suffix is still retained in lineSegments. The parseFrame value-shape matrix, \n-only framing, CRLF tolerance, ordering, and skip-on-malformed parity are unchanged from the prior review. Consumer throws still escape onRecord (it sits outside the parse try), and non-EPIPE/EIO uncaught exceptions are fatal in main, so the removed tail-preservation guard has no production reach. Ran the notebook and daemon framing suites: 30 passed / 2 skipped.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Large notebook outputs, such as images, arrive in pieces. Orca repeatedly reread all earlier pieces while waiting for the last one. Keep the pieces and assemble the record once, using the existing shared parser.
What Changed
The notebook reader now passes incoming text through the shared incremental JSON parser, collects completed records for this incoming chunk, then applies the same notebook frame validation and delivers them. The partial tail is preserved before a consumer can throw or feed another chunk. It preserves incomplete records, malformed-line recovery, Unicode, output ordering and the current unrestricted notebook record size. Kernel startup, execution and shutdown are unchanged.
Timing uses seven sequential local Node runs per shape; input creation and output assertions are outside the timer. These are parser measurements, not Python execution or UI frame-latency measurements.
Why
The shared parser already collects segments until a delimiter, avoiding repeated work on the pending prefix. Reusing it avoids another framing implementation. Its normal transport limit is explicitly disabled for notebooks so existing large image outputs are not silently dropped.
Linked Issue
Fixes #23137
Visual Proof
N/A
No rendered-content or layout change; this changes how the same notebook output frames are assembled before delivery.
Testing
44 related cases in five suites pass; two opt-in real-Python cases remain skipped. Eight new cases cover the delimiter-work budget, every Unicode split boundary, malformed/unsupported/CRLF lines, outputs larger than 16 MiB, incomplete suffixes and consumer exceptions, suffix retention after an exception and recursive input. The original fails the work budget and passes the other seven. Node typecheck, focused lint, formatting and the changed-code gate across 149 working files pass.
Tests run on macOS in Node with optional interpreter variables blank. No kernel, package install, native window, process termination or live SSH operation ran.
Review
Independent review approved the exact source/test hashes. Eleven additional probes pass on both the original and revised code, covering the actual kernel with fake child streams, callback-error continuation, recursive input, lifecycle behavior and batch delivery. Merge risk: low to moderate; the notebook framing algorithm changes to an existing parser, with frame-parity and work-budget regressions. Shared parser code is unchanged from the base commit.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Negative user-facing trade-off: Tiny output records incur extra parser bookkeeping. The measured batch of 10,000 ready records took about 0.76 ms longer; the 8 KiB input about 5.7 microseconds longer. The wrapper also parses all complete records in a chunk before delivering its first callback (1 → 10,000 parses in the measured 10,000-record chunk), holding a temporary decoded-record array. This can delay the first output in a large batch. First-output latency, real user latency and heap costs are unmeasured. This performance trade-off is isolated in its own PR.
The existing unlimited frame size remains unlimited; this does not bound a stream that never ends a record. Existing startup deadlines, process ownership and output backpressure are outside scope. Local folder/worktree notebooks use the same path. The existing UI rejects remote cell execution; no process-host boundary, wire format, Git command, platform path or keyboard behavior changes.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Focused checks above passed. Full build/lint and native platform validation remain CI coverage.