Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,36 @@ end to end:
dropped or reordered. Merged frames keep the latest frame's sequence and emit
time and carry `web.first`, their first piece's sequence. Deltas of different
blocks never merge past each other: that would break the sequence order.
- Tool snapshots (`event-stream-hub.ts`, session channel): omp sends the whole
accumulated output on every `tool_execution_update`, so the newest snapshot per
`toolCallId` is held **outside** the ordered message queue and written at most
once per `TOOL_UPDATE_FRAME_MIN_INTERVAL_MS` of that tool. A tool frame needs
no position among the deltas: the browser fences it by `max(lifecycleSequence,
toolsSnapshotSequence, toolSequences.get(tool))` and never by
`messageSequence` (`hooks/useAgentSession-sync.ts`). Three consequences, all
required: a message delta neither waits for a held snapshot nor releases one
(otherwise a bash tool printing during a streaming turn got one snapshot per
delta, i.e. no cap at all); a tool that has never been written has no window,
so its first snapshot is never delayed behind another tool's hold; and the
ordering guarantee is per domain, not globally by `web.sequence`. Message
deltas stay ordered and lossless among themselves, each tool's own frames stay
monotonic, and a boundary frame follows the frames emitted before it. Across
domains an older sequence may arrive later: another tool's newly written
snapshot can carry a lower sequence than a held one, and message@3 can precede
tool@2. That is safe because the consumer keeps separate floors; it is not a
replay or reordering defect. Where several held snapshots become releasable
together they are written in their own emission order.
The "at most once per second" holds only between consecutive
`tool_execution_update` frames of the same tool. Every other session frame —
the same or another tool's `tool_execution_start`/`end`, `btw_delta`,
`message_end`, … — is a boundary that merges every held snapshot into the
queue ahead of itself in emission order; the forced drain then writes the whole
queue regardless of backpressure, so the boundary never overtakes the output it
ends. A burst of boundary frames therefore releases snapshots at the
pre-throttle rate, bounded by how many boundary frames arrive; no snapshot is
dropped or reordered. The throttle is not an unconditional one-per-second cap.
A written snapshot is stamped with its write time, not the emit time: the
deliberate hold must not appear as network latency in Connection diagnostics.
- Browser (`lib/message-update-coalescer.ts`): applies each delta on arrival and
dispatches the whole message at display rate, so `useAgentSession` only ever
sees whole messages. A delta with no base is held and triggers a catch-up; the
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
- **Recovered prompts and attachment-backed drafts preserve their input mode.** Prompts remain model input even when their text starts with `!` or `!!`, including after navigation, session identity moves, rejection, and page reload. Drafts keep this provenance even when memory-only attachment payloads disappear on reload. Clearing the recovered content, including removing its final image from an otherwise empty composer, starts fresh input so a new shell command works normally. Empty recovery results never change newer input.
- **History prefills and unfinished uploads keep prompt intent.** History Edit, edit-and-resend Fork, and refused interrupt/reply prefills remain model input when their omitted attachments once prevented shell execution. Existing user drafts keep their own intent. Draft snapshots capture every live attachment before filtering unfinished upload payloads, so uploading or failed file chips cannot turn a prompt into a shell command after navigation or reload.
- **Side questions look different before you send.** Typing `/btw` tints the composer and shows **Send**, even during a run and when the usual submit action is Queue or Steer. Side questions are sent immediately, never queued.
- **Live tool output no longer floods a slow connection.** omp sends a tool's whole accumulated output with every progress report, so a chatty command forwarded megabytes many times a second to every open tab. ompweb now holds the newest snapshot of each running tool and sends at most one per second per tool, writing the final output immediately when the tool ends. The hold lives outside the message queue, so streaming text neither waits for a held snapshot nor releases one, and a tool that has not been written yet is never delayed behind another tool's hold. Concurrent tools keep their own snapshot, so a slow one never hides another's progress. The cap applies between progress reports of one tool: any other frame — another tool's start or end, a finished message, a side-question delta — flushes held output first, so an event burst can release snapshots as often as it arrives, but never drops or reorders them. Sequence domains stay separate: message deltas remain ordered and lossless among themselves and each tool's frames stay monotonic, while an older tool snapshot may arrive after newer message text. The delay is not reported as connection latency.
- **Finished background tool calls no longer show up as running.** A `bash` or `task` call that omp moved to the background kept reporting progress after it returned, and ompweb counted each report as a running tool. Opening the chat mid-run then listed those long-finished calls as empty running rows below the transcript until the next event, and an open chat could briefly show a finished call as running again. Calls that returned before an ompweb server restart can still show this once.
- **Background Sync retains permanent rejection states.** A rejected held message, including one from a changed installation scope, is saved as **Not sent** rather than left as **Sending**. It is not rebound to new credentials, and a late refusal cannot recreate an entry another sender already accepted.
- **Pending messages protect newer drafts and delivery intent.** A delayed storage acknowledgement does not clear newer input, even if an edit restores identical text. Same-time submissions keep durable enqueue order; duplicate browser IDs and unrelated successful HTTP responses cannot overwrite or acknowledge a held message. Delete confirmations distinguish removing tracking from cancelling work omp may already have received.
Expand Down
31 changes: 31 additions & 0 deletions hooks/useAgentSession-sync.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,37 @@ test("a snapshot no field takes still completes deltas that arrived without thei
assert.equal(pipe.shown.at(-1), "abcd");
});

test("a tool snapshot older than a newer message delta is accepted, not stale", () => {
// Tool frames are fenced per tool and by the lifecycle/tool-snapshot floors,
// never by messageSequence: the catch-up sequence domains are separate. A
// mutation that adds messageSequence to the tool floor rejects tool@2 here.
const catchUp = createSessionCatchUp({ sessionId: () => "s1", scope: () => "run", history() {}, subscribe: () => false, live() {} });
catchUp.observe({ type: "connected", web: { streamId: "s", sequence: 0 } });
assert.equal(
catchUp.observe({
type: "message_update", messageId: "m1", message: { role: "assistant" },
assistantMessageEvent: { type: "text_delta", contentIndex: 0, delta: "x" }, web: { streamId: "s", sequence: 3 },
}),
null,
"the message delta at 3 is applied",
);
assert.equal(
catchUp.observe({ type: "tool_execution_update", toolCallId: "t1", web: { streamId: "s", sequence: 2 } }),
null,
"tool@2 is accepted after message-delta@3: tool and message floors are separate",
);
assert.equal(
catchUp.observe({ type: "tool_execution_update", toolCallId: "t1", web: { streamId: "s", sequence: 1 } }),
"stale",
"per-tool monotonicity still rejects an older snapshot of the same tool",
);
assert.equal(
catchUp.observe({ type: "tool_execution_update", toolCallId: "t2", web: { streamId: "s", sequence: 1 } }),
null,
"another tool has its own floor",
);
});

// Base-less deltas through the coalescer into catch-up, reads failing at once, on a clock the test moves (performance.now and timers).
function missingBasePipeline(t) {
t.mock.timers.enable({ apis: ["setTimeout"] });
Expand Down
Loading
Loading