Repository navigation
fix(ws): replace a silent mochi or crew-companion socket - #32931
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff only changes when the socket reconnects. No component, string or layout renders differently, so the missing screenshot leaves no evidence gap. [UX-REVIEWED] 11dc686 Description read[DESCRIPTION-READ] 5d93ab3f1278782f5b4163327f1f2df4fd35f13d0a86f5964cbe89998516b6cf That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the shared watchdog is the dashboard's existing silence check moved into one helper. It runs on the gateway's existing 5 s status frame, and the change can be cleanly reverted. Notes
[DESIGN-REVIEWED] 11dc686 Description read[DESCRIPTION-READ] 3e431b7e05a5abd74dfdce6d92ce175616400c90de072b665610cb4348a0069d That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix covers all three What this change shipsInventory (8 items) — 7 justifiedIntent: the Mochi panel and the Crew Companion reconnect on their own when their socket stays open but stops delivering, with no page reload needed. This is a FIX (Closes #14225).
[FIRST-PRINCIPLES-REVIEWED] 11dc686 Description read[DESCRIPTION-READ] d663f13f1b0148d7ecb2158ed1616e38eba1bc42162fdf171e77ef75c0668d8c That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
13ce59c to
bb776b6
Compare
[operator: bolichen97] AI-assisted, posted on behalf of bolichen97 |
The Mochi panel and Crew Companion sockets reconnected only from onclose, so a socket that stayed OPEN with its transport gone sat stale until a reload. The dashboard's silence rule is extracted into one framework-agnostic SilenceWatchdog (website/src/utils/ socketSilenceWatchdog.ts) that the dashboard hook, the Mochi panel bridge and the Crew Companion session watcher all drive. The dashboard hook keeps one watchdog instance for its lifetime, so the consecutive-replacement streak survives a re-run of its arming effect. On a watchdog replacement the Crew Companion leaves its in-flight turns to the fresh socket's first slots frame: a slot still running is closed by its own chat_done, a slot no longer running is reported as failed. A close before that frame fails them as any dropped socket does. Builds on #22652 by @dodgeblaster. Closes #14225 Co-authored-by: Gary Jennings <garysjennings@gmail.com>
bb776b6 to
11dc686
Compare
[operator: bolichen97] AI-assisted, posted on behalf of bolichen97 |
Problem / Motivation
Goal: The Mochi pet panel and the Crew Companion recover on their own when their
/api/wssocket goes quietly dead, instead of sitting stale until the page is reloaded.Both app sockets reconnect only from
onclose. A browser can keep a WebSocket whose transport is gone (a phone that changed networks, a tab the OS froze and resumed) with itsreadyStatestill OPEN andonclosenever firing. The socket then delivers nothing and nobody notices: the pet's chat stream silently stops, and the companion's "tell me when sessions are done" bubble never fires again. The dashboard's own socket got a silence watchdog in #14222; these two did not.Why it matters
A dead-but-open socket is invisible to the user: the UI looks connected while every live frame is lost, and the only fix is a manual reload. The gateway already pushes a
dashboardstatus frame on every socket every 5s, so the liveness signal to detect this is already there; these two sockets were not using it.Not a goal
onclose.What changed (motivation → approach → change)
The Mochi panel and the Crew Companion now replace their
/api/wssocket when it stays open but goes silent, the same way the dashboard does, so they come back without a reload.hooks/useWebSocket.ts)forceReconnect, as beforeapps/mochi/panel/panelBridge.ts)apps/crew-companion/sessionWatch.ts)slotsframeThe silence rule used to live inside the dashboard hook, so copying it into two more sockets would fork its timing and its hidden-tab bookkeeping three ways. It now lives once in
website/src/utils/socketSilenceWatchdog.ts(SilenceWatchdog), and all three sockets drive it; each supplies only how to read whether its socket is open and how to replace it. The dashboard hook keeps one instance for its lifetime, so the count of silent replacements in a row survives a re-run of its effect. The helper sits inutils/becausehooks/websocket/is the dashboard facade's private directory.On a watchdog replacement the Crew Companion does not report its running turns as failed: the socket died, not the gateway, so those turns usually still run. The fresh socket's first
slotsframe decides instead: a turn it lists as running finishes through its ownchat_done, and a turn it does not list is reported as failed, as a dropped socket reports it. When that frame lists the slot running under a differentturn_gen/turnthan the one the watcher recorded, the earlier turn ended unseen: it is reported as failed in the same way, and the new turn starts fresh with its own error and stop flags. When either identity is unknown (an older gateway), the running turn is kept. If the fresh socket closes before that frame, the turns fail as before.docs/system-specs/modules/learn-cron-dashboard.mdnames the helper and both app sockets, andtest/test_ws_status_cadence_contract.pyreads the timing constants from their new file.Builds on #22652 by @dodgeblaster, rebased onto current main.
Backwards compatibility
Compatible: the dashboard socket keeps its behaviour (its existing watchdog specs in
useWebSocket.silenceWatchdog.test.tsrun unchanged against the shared helper), and the two app sockets only gain a replacement path for a state, open but silent, in which they did nothing before.Removes nothing: no path, record, validator or public function is removed or tightened;
useWebSocketkeeps re-exportingWS_SILENCE_MS,WS_SILENCE_CHECK_MSandWS_SILENCE_MAX_MS, now from the shared helper.Tests
website/src/test/socketSilenceWatchdog.test.ts: the helper alone replaces a silent OPEN socket, keeps one that delivers frames, skips a socket that is not OPEN, skips while hidden, doubles the window per silent replacement up to the cap, keeps the widened window acrossstop()+start(), and detaches onstop().website/src/apps/mochi/test/mochiSocketSilence.test.ts: the Mochi socket is replaced after the window, is kept while it receives the 5 s status frame, and is left alone on a hidden page.website/src/apps/crew-companion/sessionWatch.socketSilence.test.ts: the same three for the Crew Companion socket, plus whatonDonereceives on a replacement: nothing at the replacement, one success for a turn the firstslotsframe lists running, one failure for a turn it does not list, a successor under a newturnorturn_geninherits neither the earlier turn's error nor its stop (and keeps its own stop from the settling frame), only the firstslotsframe settles, and a close before that frame fails the turn.website/src/test/useWebSocket.ownership.test.ts: the facade's effect-order pin names the watchdog effect by itssilenceHostRefwiring.test/test_ws_status_cadence_contract.py: the pin between the frontend silence window and the gateway's_WS_STATUS_INTERVALreads the constants and the thaw grace fromsocketSilenceWatchdog.ts; the contract is unchanged.With
sessionWatch.tsandpanelBridge.tsput back to main, six of the eleven per-socket specs fail; with this change all pass. Every spec uses fake timers and an injected or mocked clock, with no real sleeps.Proof: not provable -- frontend test (prove.py runs Python only)
Manual verification
N/A: unit coverage is sufficient. The behaviour is a timing rule over socket state, fully driven by fake timers and a mocked clock, with no rendered output to inspect.
Screenshots / video
Why no screenshot: this changes when an open but silent socket is replaced; no component, layout, theme or string renders differently.
Related Issues
Closes #14225
Sibling sweep
Swept: git grep -nE 'new WebSocket(' -- website/src
Sibling: website/src/hooks/useWebSocket.ts -- changed here
Sibling: website/src/hooks/useStreamingStt.ts:304 -- not affected -- /api/ws/stt carries no periodic status frame, so silence there is not a liveness signal
Sibling: website/src/apps/meetings/hooks/useMeetingTranscription.ts:629 -- not affected -- the same /api/ws/stt endpoint, no periodic status frame
Sibling: website/src/utils/terminalRegistry.ts:521 -- not affected -- a terminal socket is silent whenever the shell prints nothing
Pattern harvest
Rule candidate: review-prompt
Pattern: a per-connection liveness or silence watchdog copied inline into each socket instead of shared, so the timing constants drift between copies.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)