Repository navigation
perf(daemon): send PTY output to main as raw bytes, not NDJSON - #27006
Conversation
The stream socket's hello can now negotiate binary-v1 framing: length-prefixed frames carrying PTY data as raw UTF-8 next to a small JSON header, so neither the daemon nor main escapes or parses the payload. Older daemons ignore the hello field and stay on NDJSON; older mains never ask. The hello reader now hands the stream reader the exact bytes that followed its line, which an event sharing the hello's read used to lose. ORCA_DAEMON_BINARY_STREAM=0 keeps NDJSON. Fixes #27003 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughDaemon stream sockets can negotiate Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The stream framing change is ready to merge after normal checks; no actionable compatibility or output-loss issue remains identified. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4c1ab0e6-46c4-4453-9f8b-7747d8dff7a0
📒 Files selected for processing (14)
src/main/daemon/client.tssrc/main/daemon/daemon-client-connections.tssrc/main/daemon/daemon-client-hello-handshake.tssrc/main/daemon/daemon-client-ndjson-readers.tssrc/main/daemon/daemon-hello-protocol.tssrc/main/daemon/daemon-stream-backpressure.test.tssrc/main/daemon/daemon-stream-backpressure.tssrc/main/daemon/daemon-stream-binary-framing.test.tssrc/main/daemon/daemon-stream-binary-framing.tssrc/main/daemon/daemon-stream-binary-negotiation.test.tssrc/main/daemon/daemon-stream-data-batcher.tssrc/main/daemon/daemon-stream-data-entry.tssrc/main/daemon/daemon-stream-data-split.tssrc/main/daemon/daemon-stream-held-refill.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
ELI5
Busy terminals spend less time encoding and decoding their output between Orca and its terminal daemon.
What Changed
Terminal data uses a length-prefixed byte stream only when both peers negotiate support. Older peers keep their existing JSON stream. The reader pauses during the hello handoff, installs the next reader with the exact remaining bytes, and resumes without dropping buffered output. Valid Unicode uses raw UTF-8; malformed UTF-16 uses the existing JSON event frame so the original string survives. Frame splitting preserves the existing sequence and size rules.
Why
This removes repeated escaping and parsing from the busiest path. Capability negotiation preserves independently updated peers. Existing event frames handle exceptional strings without another protocol feature, and normal writes encode metadata once.
Linked Issue
Fixes #27003
Visual Proof
N/A — backend performance changes; no layout or controls change.
Performance measurements
A codec microbenchmark compared NDJSON, the original PR (
80d2cc7), and the corrected implementation (b1442e4) on macOS arm64 with Node 24.20.0. Each iteration ran the actual writer directly into the actual reader, including NDJSON UTF-8 encoding and StringDecoder, and checked decoded character counts. Writes included sequence metadata.The table shows median elapsed time per write across nine interleaved rounds, with GC before each timed sample. Small cases used 50,000 writes per round; bulk used 128.
The corrected writer encodes fitting frames once and calculates splitting budgets only for oversized frames. A deterministic regression test verifies 100 small writes require 100 metadata serializations; the original path required 200.
The shared host was busy, so absolute timings varied. These measurements cover codec work, excluding real sockets, PTY production, batching delays, IPC, and rendering. They do not establish application throughput or interactive latency.
Testing
Final focused run: 114 tests across 10 files, including real socket negotiation, handoff, Unicode, byte limits, stream replacement, and backpressure. Wider compatibility tests cover older daemon versions. Independent fuzzing covered 1,200 payloads and 41,524 frames. Real Linux and native Windows sockets reproduce the original output loss and pass the correction. Node typecheck and changed-code quality pass; the combined branch also passes all typechecks, the production build, and focused tests.
AI Disclosure
Implemented with Claude Opus 5.5 via Claude Code: design, code, tests and measurements. A human (outof-place) directed the work.
Review
The review corrected output loss between readers, malformed Unicode replacement, quadratic hello buffering, and duplicate metadata encoding. Start with the hello handoff and binary frame writer.
Agent skill upstream boundary
Notes
No negative user-facing trade-off identified in the corrected code. Authentication and the 16 MiB bound remain. Remote hosts negotiate between their own daemon and client; consumer event shapes remain compatible. Full packaged cross-platform journeys still require CI.
ORCA_DAEMON_BINARY_STREAM=0preserves the older transport.Checklist