Skip to content

desk-web: a reconnect keeps the session view drawn and says nothing for 15 s; a latency readout (#57) - #61

Merged
SSFSKIM merged 11 commits into
masterfrom
desk-reconnect-web
Oct 18, 2026
Merged

SSFSKIM merged 11 commits into
masterfrom
desk-reconnect-web

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

The web half of #57 (the hub half is #58, merged). A reconnect no longer blanks or reloads the session view. That covers a reconnect of the browser's project socket, of a machine's stream to the hub, or of a hub object after a deploy. A gap under 15 s draws nothing at all. The PR also adds a latency readout that is cheap enough to leave on.

What the reader saw before

  • A browser socket drop, a gap, or a bridge discontinuity:
    • DeskTranscript.reset emptied the store key, so the pane went blank with "Reconnecting to the session…".
    • The fresh snapshot then reloaded it.
    • Deploys cause this too: code updates disconnect hibernated WebSockets.
  • A machine's stream replaced or closed:
    • The hub ended the subscription machine-offline. The pane drew "The machine is offline… Trying again in 1 s." and the header said "Unavailable".
    • The view resubscribed after 1 s, and the fresh snapshot replaced the held rows. Older pages the reader had loaded were lost.

What the reader sees now

  • Through any disruption, whether a socket drop, a gap in n, end {discontinuity}, or end {machine-offline} while the session stays reachable:
    • What was drawn stays drawn: rows, marks, the subagent tree, jobs, usage, and streaming blocks.
    • Requests that need the live subscription (an older page, the diff, an output) wait for the fresh snapshot.
  • The fresh snapshot is merged by uuid overlap. The result is the held rows before the snapshot, the snapshot, then any held row newer than its newest. more stays as held.
    • It falls back to a staged replace in three cases: the snapshot overlaps nothing held; its off-chain marks disagree with the held ones or vouch for nothing; or a row new to the browser hangs off a held row outside the snapshot (a fork in the gap).
    • The rebuild is staged, so rows keep their elements.
  • The streaming layer resumes over what was drawn. A block whose row was written during the gap stays drawn until that row lands. An older snapshot never truncates drawn text and never revives an ended request.
  • For 15 s nothing is said: no "Reconnecting…", no ended line, no header word.
    • 15 s is QUIET_MS, matching the hub's grace for a closed machine stream. In that grace a subscribe or an RPC waits for the next stream.
    • Past 15 s, the view says what is true now, over the kept rows.
    • These are said at once: a first open with no rows; a session known to be unreachable (the existing offline fallback is unchanged); an end for any other reason.
  • After end {machine-offline} while the session is reachable, the first retry is immediate. Later retries back off as before.
  • Still visible: the app's top-bar dot says "Reconnecting" during a browser socket drop. It follows the grid socket, and is outside this change.

The latency readout

To turn it on, set localStorage['desk.latency'] = '1', or add ?latency to the URL.

When on, it shows:

  • a small overlay with each path's n, p50, p95 and max;
  • one console.info('[desk latency] <path> <ms>') line per sample.

window.deskLatency() returns the numbers whether the readout is on or off. Samples are kept always, the last 200 per path in a ring buffer; nothing is drawn or logged while off.

Path Measured from Clock
owner message: sent → human-ack send to hub acknowledgement browser
owner message: sent → delivered send to the delivery outcome arriving back browser
owner message: sent → its row in the transcript send to the row's engine timestamp cross-clock: browser → Mac
a session's message or question its log ts → verified and drawn cross-clock: machine → browser
a raised permission prompt or question raised → drawn browser
a raised permission prompt or question its call's row → drawn cross-clock: Mac → browser
session view subscribe → snapshot → first rows drawn browser
streaming chunk the bridge's t stamp → drawn cross-clock: Mac → browser
live row engine timestamp → drawn cross-clock: Mac → browser
resume disruption → fresh snapshot merged browser

It also counts socket reconnects and subscription resumes. "Drawn" means the next animation frame after the store applied the change. The paths that cross clocks say so in their label.

Tests

  • Added: e2e/reconnect.spec.ts, against the fake machine, run mid-response for both a browser socket drop and a machine's stream replaced. Each case:
    • pages older rows in first;
    • watches every DOM change with a MutationObserver: rows never reach zero, and none of depth-reconnecting, depth-unavailable or a header word appear;
    • checks that every row in view before the drop is the same DOM element after it;
    • checks the older rows are still drawn, with no new rows request;
    • lets the answer stream to the end and checks it is drawn once;
    • checks a reload draws the same rows.
  • Added: e2e/depth.spec.ts: a disruption that outlasts the quiet window is said, using Playwright's clock.
  • Added: e2e/latency.spec.ts: with the readout on, every path the session exercises gets a sample, and window.deskLatency() is attached to the report.
  • Unit tests:
    • updated wherever they pinned the old blanking;
    • new tests for the merge and its fork guard, the streaming layer's resume, the keeper's quiet window, and the recorder.

Reviews

reviewer-medium, four rounds:

  • Round 1 (the first two milestones): 6 findings, all fixed.
  • Round 2 (the head with master merged in): 4 P2s, fixed in e27b0e7. They were:
    • a fork in the gap that the off-chain guard could certify;
    • a named block whose row was still in the live tail;
    • truncation by an older streaming cut;
    • an ended request revived.
  • Round 3: 2 P2s, fixed in a6581fa.
    • When a snapshot is older than what a request drew, it now changes nothing of that request.
    • A fork whose parent is outside the held window now replaces too.
  • Round 4: one P3. It is reachable only with a producer that sends a snapshot older than what it delivered, which the machine's plane never does. It is logged in docs/tech-debt-tracker.md, along with a hidden-tab latency sample.

Gates

static,unit,e2e:desk-web --class1a linux --evidence is green at the head a70ccf7: https://github.com/SSFSKIM/MAWS/actions/runs/39166149401. The tree includes master 074c0d2 with #58. Since then master gained only wrangler.jsonc's logs setting (#60) and P3 docs.

The web's share of each path

These numbers come from e2e/latency.spec.ts on the Linux runner, against the DX3 double and the fake machine. The double relays at once, so the numbers are the web's own processing and drawing. Each run's log line is [desk latency e2e]; these are from run 39165055192.

Path ms
session view: subscribe → snapshot in 18
session view: snapshot → first rows drawn 124
session view: subscribe → first rows drawn 142
owner message: sent → human-ack 15
owner message: sent → delivered outcome 57
owner message: sent → its row 57
session <message>: logged → drawn 36
raised question: in → drawn 23
streaming chunk: stamped → drawn 116

The chunk figure is n 33, but the replay applies its steps in one burst, so all 33 chunks were drawn in the same frame. It is the cost of a burst, not of a steady stream.

stream.row and request.row measure from the recording's own timestamps, so they show the recording's age instead of a latency.

…thing for 15 s (#57)

A socket drop, a gap in n, an end {discontinuity}, or an end {machine-offline} while the session stays
reachable no longer empties the transcript. The subscription listener's reset() is now interrupted():
what was delivered stays valid and a fresh snapshot follows. Held rows, their marks, the subagent tree,
jobs, usage and the streaming layer stay drawn; rows, diff and output wait until the new subscription
is served.

The fresh snapshot is merged by uuid into the held rows instead of replacing them: the held rows before
its oldest row, then its rows, then any held row newer than its newest. The reader's older pages stay
drawn. A marking producer whose offChain disagrees with the held marks on the overlap replaces the held
rows, as before. So does a snapshot that overlaps nothing. The rebuild stays staged. A block the snapshot
no longer streams stays drawn until the rows it brought have landed.

The keeper resubscribes at once after a machine-offline end while the session is reachable; later
retries back off. The views say nothing of a disruption of a transcript holding rows for QUIET_MS
(15 s, the hub's grace for a closed machine stream). They speak at once when no rows are held, when
the session goes unreachable, or on an end of another kind.

e2e: reconnect.spec.ts pins both disruptions mid-response against the fake machine with a
MutationObserver over the whole window. depth.spec.ts pins the outlasting case under a fast-forwarded
clock.
Every hop the web sees is timed into a 200-sample ring per path, always. The samples are drawn and
logged only when asked: localStorage['desk.latency'] = '1' or ?latency turns on a small fixed overlay
(n, p50, p95, max per path, plus the reconnect counts) and one console.info('[desk latency] <path>
<ms>') line per sample. window.deskLatency() returns the same numbers for a scripted read.

The paths:
- an owner message: send to human-ack, to its delivered outcome, and to its framed row's engine
  timestamp (cross-clock)
- a session's message or question: its logged ts to drawn, once verified (cross-clock)
- a raised request: its arrival to drawn, and its call row's timestamp to drawn (cross-clock)
- a session view's first rows: subscribe, then snapshot, then drawn
- a chunk's bridge stamp t, when present, to drawn; a live row's engine timestamp to drawn
- each subscription resume's gap
- the project socket's reconnect count
"Drawn" is the next animation frame after the store applied the change. The samples of a frame are
batched into one callback.

e2e: latency.spec.ts runs every exercised path against the fake machine with the readout on, attaches
window.deskLatency() to the report, and bounds only the same-host paths' p95 loosely (5 s).
The project socket's welcome clears every session's presence until the hub sends it again, so for a
moment after each reconnect the session read as unreachable. That ended the keeper's quiet window, and
the header flashed "Reconnecting…". The keeper now takes the session's reach in three states:
reachable, unreachable, or unknown. Only a known unreachable session ends the quiet early. Retries
still treat unknown as not live, as before.
…nd the latency instrument (#57)

- e2e/reconnect.spec.ts midAnswer: reads the last streaming row's text without waiting for one, so the
  loop steps the replay into the answer instead of waiting forever for a row that is not drawn yet.
- desk-transcript.ts merged: a marking producer's snapshot is merged only when the overlap also holds a
  row of a type the chain carries that both sides hold on the chain; an overlap of progress rows alone
  vouches for nothing, and the snapshot replaces the held rows.
- layer.ts resume: a block a block-row named before is dropped from a snapshot cut before that row,
  and its later chunks are ignored, so its partial text is never drawn beside its row.
- desk-transcript.ts RowsSource.live: the stream.row sample is taken once the row's events reach the
  store, so rows that draw nothing, or reach no store yet, give none.
- latency.ts drawn: nothing waits for a frame while the page is hidden, and at most 512 samples wait
  for any one frame.
… not a reconnect (#57)

A reconnect now keeps every row drawn before it. The fresh snapshot of the newest rows is merged in,
and nothing older is left to page in. A fresh load is what gives the case a view holding only the
newest rows.
…treaming layer's resume (#57)

A marked snapshot is no longer merged when a row it brings was written under a held row it does not hold: a fork
before its window can take older held rows off the chain while every row the window holds stays on (a second append
under a tool call leaves the first, the call's result staying), so agreeing marks could certify a stale one.

A block a block-row named before the disruption keeps waiting for its own row where the snapshot was merged, since that
row is held or still to come live; after a replace a row not held falls back to the snapshot's landing row, as it may
be older than the window. A snapshot older than what was drawn keeps each request's higher watermark and the drawn
text, and an ended request stays ended, its dropped blocks not drawn again and its replayed chunks not taken.
…mp and logs its numbers for the run's record (#57)
…, and a branch from outside the window replaces (#57)

A snapshot whose watermark for a request is below the drawn one keeps that request whole (its blocks, the blocks named,
its end, its watermark), and the live part after the snapshot's cut replays the rest; the partial watermark-max and
keep-text rules, which lost a block the older snapshot did not stream yet, are gone. Otherwise the snapshot's copy
replaces the drawn one as before, an ended request staying ended.

The fork check no longer needs the parent held: a row the browser did not hold whose parent is not among the snapshot's
own rows forks outside its window, which in paged history can be older than every held row.
… replace; a latency sample across a hidden tab)
@SSFSKIM
SSFSKIM merged commit 0e6c2d4 into master Oct 18, 2026
SSFSKIM added a commit that referenced this pull request Oct 18, 2026
…s grace (MAWS #57, #61's rule)

A project whose roster was current reads as current through a disruption -- a
dropped socket, its backlog read again after the reconnect, a live event still
being checked -- until it has lasted QUIET_MS (#61's 15 s, the hub's grace for
a closed machine stream); past it the project is named as reconnecting and its
rows are marked as last seen. A project never current is said as it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant