Repository navigation
feat(stream): delta-only message updates from omp to the browser - #361
andrebrait wants to merge 85 commits into
Conversation
Findings
|
| Layer / File(s) | Summary |
|---|---|
Host-link protocol and compatibility lib/hosts/link-protocol.ts, docs/specs/*, AGENTS.md, README.md, CHANGELOG.md, DESIGN.md |
The host-link protocol advances to v5, with v4 compatibility. Text and binary frames carry sequenced traffic, acknowledgements, multipart messages, and large results over one WebSocket. |
Daemon WebSocket transport lib/hosts/daemon.ts, lib/hosts/daemon.test.mjs |
The daemon sends and receives link traffic over a persistent socket. It tracks acknowledgements, replays unacknowledged messages after reconnect, and sends large results in binary pieces. |
Hub upgrades and socket lifecycle lib/hosts/hub.ts, app/api/hosts/link/*, server/app.ts, server/routes.ts, proxy.ts, lib/hosts/*test* |
The hub authenticates upgrades, processes socket frames, and handles replacement, shutdown, and reconnection. The HTTP blob route is removed; old link POSTs receive an outdated-link response. |
Browser transport
| Layer / File(s) | Summary |
|---|---|
Transport settings and event connections lib/web-settings.ts, app/api/web-settings/route.ts, components/SettingsConfig.tsx, lib/event-stream-protocol.ts, lib/event-stream-hub.ts |
Settings add SSE and four WebSocket modes, with pool-size limits. Event connections include transport state and can write through SSE or a supplied socket sink. |
Browser socket commands lib/browser-socket.ts, lib/agent-command.ts, app/api/events/ws/route.ts, app/api/agent/[id]/route.ts, lib/agent-client.ts |
The browser socket handles subscriptions and commands. HTTP and socket commands share command handling; socket requests include acknowledgements, replies, and deduplication. |
Worker transport and metrics public/event-stream-worker.js, lib/event-stream.ts, app/api/transport-metrics/route.ts, lib/transport-metrics.ts, scripts/transport-metrics.ts |
The worker assigns sockets, moves subscriptions, manages pool size and retries, and sends metric samples. The server stores bounded JSONL samples, and a CLI summarizes browser and host-link metrics. |
Settings, transport, and metrics support lib/i18n/locales/*, docs/specs/2026-10-31-browser-transport-experiment-design.md, docs/plans/2026-10-31-browser-transport-experiment.md, scripts/link-hol-probe.ts |
The changes add browser transport translations and design documentation, plus a CLI probe for host-link traffic. |
Delta message streaming
| Layer / File(s) | Summary |
|---|---|
Server delta negotiation and reconstruction lib/message-delta.ts, lib/rpc-manager.ts, lib/session-sync.ts |
Session wrappers request delta updates and rebuild assistant messages. When a base is missing or a delta cannot be applied, the wrapper falls back to full updates or recovers the message state. |
Browser delta coalescing and catch-up lib/message-update-coalescer.ts, hooks/useAgentSession-sync.ts, hooks/useAgentSession.ts, tests/fixtures/omp-delta-stream.ndjson |
The browser coalesces compatible deltas, seeds message bases from snapshots, requests catch-up when needed, and rejects stale or overlapping updates. |
Estimated code review effort: 5 (Critical) | ~120 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant HostDaemon
participant HostHub
HostDaemon->>HostHub: Upgrade authenticated WebSocket
HostDaemon->>HostHub: Send hello and sequenced frames
HostHub->>HostDaemon: Send welcome, frames, and acknowledgements
HostDaemon->>HostHub: Send binary result pieces
sequenceDiagram
participant BrowserWorker
participant BrowserSocket
participant AgentCommand
BrowserWorker->>BrowserSocket: Subscribe and send command
BrowserSocket->>AgentCommand: Run command
AgentCommand->>BrowserSocket: Return command response
BrowserSocket->>BrowserWorker: Send acknowledgement and reply
Merge Risk: 
Low · previous review 6f44a
-
The change is mergeable with owner awareness of bounded edge cases: streaming displays can temporarily differ, transport changes can reconnect subscriptions unnecessarily, and settings or metrics can become inaccurate. A narrow deduplication-capacity case can also dispatch a command twice. Address these findings or explicitly schedule follow-up fixes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 inconclusive Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 71.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 185 functions across 50 files. (20 skipped: 14 unsupported, 6 over the file limit.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
I’m a rabbit; I hop by the socket’s bright stream.
Small deltas join softly, then build a full scene.
Acks mark the messages that safely arrive.
New paths reconnect, and the metrics stay live.
I nibble one carrot and watch frames go by.
| case "toolcall_delta": | ||
| // The arguments are complete only at toolcall_end; until then keep the JSON so far (see withStreamedArguments). | ||
| if (block?.type !== "toolCall" || typeof update.delta !== "string") return null; | ||
| { |
There was a problem hiding this comment.
🔥 The Roast: A bare { block after the toolcall_delta guard — JavaScript's switch already has enough scope weirdness without voluntarily adding a naked block. It's harmless, but it makes me wonder what else is hiding in there like a body in a shallow grave.
🩹 The Fix: Drop the bare block — the const streamed and friends can live directly in the case arm.
📏 Severity: nitpick
There was a problem hiding this comment.
The block is there for the const declarations: a lexical declaration directly in a case arm is what ESLint's no-case-declarations rejects, and the guard before it has to stay outside so it can return null for a non-tool-call block. Keeping it.
| if (!live || !message) { | ||
| if (held.length === 0) heldFloor = floor; | ||
| held.push(event); | ||
| onMissingBase(); |
There was a problem hiding this comment.
🔥 The Roast: onMissingBase() fires every single time a delta finds no base, even when we're already waiting for a snapshot. It's like calling the fire department every time you smell smoke — technically correct, but by the fourth call in ten minutes you're just making noise. The caller's pending guard saves you from duplicate network requests, but the repeated invocations are still wasted work.
🩹 The Fix: Track whether a base request is already in flight (e.g. a baseRequested flag) and only call onMissingBase() when transitioning from not-waiting to waiting.
📏 Severity: suggestion
There was a problem hiding this comment.
Intentional: the caller already keeps one snapshot request in flight, so a repeated onMissingBase() is a cheap no-op there, and the coalescer stays free of request state (its only job is ordering frames against the base). A second flag here would duplicate that guard without changing behaviour.
Code Review Roast 🔥Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (2 files)
Previous Review Summaries (9 snapshots, latest commit bd36bb3)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit bd36bb3)Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (2 files)
Previous review (commit 6f24976)Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (10 files)
Fix these issues in Kilo Cloud Previous review (commit 6f44a81)Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (4 files)
Previous review (commit f4fe9e4)Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (4 files)
Previous review (commit 3fadd4c)Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (9 files)
Previous review (commit d3d4626)Verdict: No Issues Found | Recommendation: Merge Oh wait, this incremental slice is actually clean. I had my flamethrower warmed up for nothing. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (8 files)
Previous review (commit 968a3cd)Verdict: No Issues Found | Recommendation: Merge Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything. 📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. Files Reviewed (13 files)
Previous review (commit c930449)Verdict: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)
🏆 Best part: Oh wait, this PR is actually pretty clean. I need to sit down. I had my flamethrower warmed up and everything. The delta reducer in 💀 Worst part: The 📊 Overall: Like a first pancake — the shape is wrong but the ingredients are there. Actually, scratch that, this is more like a golden-brown pancake on the first try. Just flip the two minor things and ship it. Files Reviewed (5 files)
Fix these issues in Kilo Cloud Previous review (commit 58ab4f1)Verdict: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)
🏆 Best part: Oh wait, this PR is actually pretty clean. I need to sit down. I had my flamethrower warmed up and everything. The delta reducer in 💀 Worst part: The 📊 Overall: Like a first pancake — the shape is wrong but the ingredients are there. Actually, scratch that, this is more like a golden-brown pancake on the first try. Just flip the two minor things and ship it. Files Reviewed (18 files)
Reviewed by free · Input: 19.5K · Output: 1.3K · Cached: 86K |
c930449 to
968a3cd
Compare
…in handler throws
Lines over pieceBytes go as sequenced part messages and large results as several binary frames. Both sides queue per channel or request and send round-robin, numbering lines as they go out, so wire order stays seq order. The hub keeps its send/drain pacing; the daemon sends while the socket's bufferedAmount is under two pieces instead of one frame per ack. A v4 daemon still links and gets whole lines.
LinkSender clears its one-line-in-parts slot when a line goes whole to a v4 peer, marks part units and can drop unsent result bytes; PartJoiner caps a line at 512 parts; Outbox keeps seq order without re-sorting and returns what ack/drop removed; LINK_LIMITS.unackedBytes (1 MiB) bounds unacked data. The unused LinkSender.empty is gone.
Kernel and proxy buffers hid megabytes from bufferedAmount and Bun's send, so the one-piece wait did not hold. Each side now sends queued units only while less than unackedBytes is unacked: the hub counts outbox lines written, the daemon counts frames the hub has not answered (the hub now acks every v5 frame, binary ones too). The daemon acks applied downlink data within flushMs, with an ack-only frame if need be. Also: the daemon resends from one outbox snapshot per welcome (the resend was quadratic), batches text frames by UTF-8 bytes, answers a malformed joined req 400, and drops unsent result bytes on welcome. A v4 daemon taking over gets unacked parts back as whole lines, never a part. The hub returns a one-piece result without copying.
…nd paths A v4 daemon acks only inside its next uplink frame, so the hub's 1 MiB window could hold an abort for up to a ping interval: v4 links get none. The daemon frees its resend snapshot once consumed. New tests fail when text frames batch by UTF-16 length, failOp leaks the window, or the resend ignores a later ack or an overflow.
The netem probe at 2 Mbit measured small uplink messages behind a large one at p50 5.0 s (the 5 s get_state timeout): 1 MiB plus the unit that may start below it drains in ~5 s there. With 512 KiB at most 768 KiB is unacked in flight, ~3.1 s at 2 Mbit. The cost is throughput, about 512 KiB per round trip. The window tests now assert the 512 KiB bound; the resend tests widen the window to keep their 20,000-line scale.
3fadd4c to
f4fe9e4
Compare
… timeouts on slow links
…and make A and C after it On netlab B's ten-image prompt took 48 s to go idle on the LAN and 89 s at 10 Mbit (omp re-encodes the images for ~24 s, the model answered with tool calls, ~19 MB of echoes cross the uplink), past the 60 s wait. At 2 Mbit the setup outlasted the 2 min disconnected-idle cleanup, which disposed A and C before the first phase.
… parts before applying a frame
…e part joiner rollback
…ry; session creation is not aborted
… reset a pending result's pieces on a new socket
…not a same-process redial
…ates One pure reducer, shared by the server and the browser, applies omp's messageUpdates "delta" frames (omp >= 18.13.2) and refuses any update it cannot place, so callers recover a snapshot instead of rendering a guess. Streamed tool-call arguments read as omp's parseStreamingJson does. Tested against a recorded omp 18.14 stream and omp's own projection.
…ssage on the server Every session start (spawn, restart, adoption) sends set_event_filter with messageUpdates "delta"; an omp that rejects it or does not echo it keeps full updates. The wrapper rebuilds each streaming message from the deltas for the live snapshot and replays it whole to a tab that attaches mid-message. A delta with no message to apply to (adopted child, frames lost on the host link) is not forwarded: the session takes full updates until that message ends, then deltas again; an omp whose deltas do not fit a message it started stays on full updates.
… of keeping the latest A delta update is not a snapshot, so latest-wins would lose text. While a socket is behind, a session subscription now queues its message_update frames: consecutive deltas of one block concatenate, a whole message replaces the queued updates of that message, and nothing else is dropped or reordered. SSE and the WebSocket sinks share this.
The coalescer keeps the message deltas apply to, applies each one as it arrives and still dispatches one whole message per display frame, so the transcript code is unchanged. A delta without its message is held, never shown, and asks for the HTTP catch-up; the live snapshot (now with streamingMessageId) re-bases the coalescer when applied and otherwise completes held deltas newer than it.
A snapshot at sequence S holds delta S; when that frame arrived after the snapshot it passed the stale check and repeated its text. Also tests that a snapshot no field takes still completes held deltas.
…of it A frame merged under backpressure now names its first piece's sequence (web.first). The coalescer remembers the sequence its base holds; a merged frame that starts at or before it waits for the next snapshot instead of repeating text.
… switch keeps full updates A full update's tool calls carry no streamed JSON and its snapshot can be ahead of the deltas that follow, so a delta after one now takes the lose-base path. A set_event_filter that fails no longer leaves deltas dropped until message_end: the next lost delta asks again and the session stays on full updates. The unused echo flag is gone; the version comment names 18.4.5 (delta option) and 18.13.2 (block shells).
… ms; refuse far block indexes Parsing a 1 MB argument took 42 ms on every display frame. The last parse now carries over from block to block and is redone only once the JSON grew by 2 KB or 100 ms passed; toolcall_end still sets omp's final arguments. A contentIndex more than 32 past the last block is refused. Also tests that an end event's content replaces whatever the block streamed.
…quence fence and merged frames
…d delta is applied once A snapshot that cannot take a held delta asks for the next one, which holds everything the browser already received, so re-holding the remainder changed nothing. The base's sequence advances with each applied delta, so the same frame arriving again asks for a snapshot instead of repeating its text.
…a streamed __proto__ key
21e2932 to
62d606f
Compare
Summary
omp-web streamed every assistant
message_updateas the full message so far (several KB per frame, several frames per second). On slow links that overloads every transport. omp already supports delta-only updates (set_event_filterwithmessageUpdates: "delta", since omp 18.4.5); omp-web now uses them end to end.Measurements
Same prompt, real omp, headless Chromium over SSE: the session stream went from 232,157 to 84,078 bytes; the streaming-update frames from 178,461 bytes to 27,058 (about 2.5 KB to 375 bytes per frame).
Testing
npm run typecheck && npm run lint && npm test: 2241 pass, 0 fail.Summary by CodeRabbit
New Features
Improvements
Compatibility