Repository navigation
fix(ws): apply the silent-socket watchdog to the mochi and crew-companion sockets - #22652
dodgeblaster wants to merge 1 commit into
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff only changes socket-reconnect timing and adds or changes no visible control, label or string, so the missing blind read leaves no gaps. [UX-REVIEWED] 12641c6 Description read[DESCRIPTION-READ] 4d8a52abdc76e86ec041df292153e2eb7764fbbb903fc138b19c6ce3f8506915 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. All three Notes
What this change shipsInventory (5 items) — 4 justifiedIntent: the Mochi panel and the Crew Companion recover on their own from an open-but-dead socket, with no reload. This is a FIX (#14225).
Coverage count: 3 non-test [FIRST-PRINCIPLES-REVIEWED] 12641c6 Description read[DESCRIPTION-READ] 698006dd237325f40fe393153a94adb6f6311da91135e0c4fa8d7d36b7918d85 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The design rests on the gateway sending its 5s [DESIGN-REVIEWED] 12641c6 Description read[DESCRIPTION-READ] f667d0cf14870273a84548524719b98680f368c2decc44ed2c2fc3687ef1c0d1 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 |
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 findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- website/src/apps/crew-companion/sessionWatch.ts:339 -- Reconnect preserves a predecessor’s stop flag for a new turn
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 is downgraded: the harm is low and the real fix costs more than it prevents. F1 — LOW. The failure needs four things to happen together:
The only consequence is that one "done" bubble doesn't appear. Nothing self-corrects it, but no data or state is lost, failures are never silenced, and the session's own UI still shows the turn finished. The real fix needs a new per-slot turn-identity map, compared at the reconnect check. The slots frame does carry False positive or not applicable? A repository writer can comment: |
ad1b8dc to
873422a
Compare
873422a to
a272250
Compare
|
a272250 to
dc1c020
Compare
|
|
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Requesting changes for one user-facing behaviour. The extraction itself looks right: the dashboard hook keeps its behaviour, and removing silence.markFrame() from the Crew Companion onmessage reddens keeps a socket that receives the 5s status frame.
On a watchdog replacement, do not report in-flight turns as failed. In sessionWatch.ts, onDead calls failInFlight(), which marks every started slot failed and runs finish() with silent: false, so the bubble ignores the notifications setting. In the case the watchdog targets (the socket died, the gateway did not), those turns are usually still running. The next slots frame re-adds them, so the person sees "failed" and then "done" for the same turn, and this PR makes that more frequent (any 20 s gap in the status push while the page is visible).
Please either skip failInFlight() on a watchdog replacement and let the new socket's chat_done close the turns, or defer the failure to the first slots frame after reconnect and fail only slots that are no longer running. Add a test asserting what onDone receives on a watchdog replacement (the current spec passes onDone: () => {}).
Docs follow-up: docs/system-specs/modules/learn-cron-dashboard.md still describes the silence watchdog as a useWebSocket feature only; it should name utils/socketSilenceWatchdog.ts and the two app sockets.
Minor: the consecutive-silent-replacement count now resets whenever the hook's watchdog effect re-runs; before, it lived in a ref and survived re-runs.
…nion sockets Both app 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. Closes #14225
dc1c020 to
12641c6
Compare
|
@buluoray thanks, all three points are addressed on head 12641c6 (rebased onto current main, still one commit). In-flight turns on a watchdog replacement. I went with your second option. New specs in
Putting Docs. Streak reset on effect re-run. Fixed. Local runs: the six silence/session-watch/ownership spec files plus every |
|
Hold: active change request. Reviewed head @buluoray's CHANGES_REQUESTED review (on dc1c020) is still active. The author's reply says all three points are addressed on this head, and the code agrees: a watchdog replacement no longer fails in-flight turns but lets the first AI findings judged non-blocking:
— crew-pr-reviewer (r141) |
|
@buluoray, could you take another look when you have a moment? Each point from your review looks addressed at 12641c6:
Your review is the remaining blocker. Thanks. |
|
[operator: bolichen97] Continuing this in #32931; thanks for the start. |
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>
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>
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>
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 right there — these two sockets just were not using it.Not a goal
onclose.What changed (motivation → approach → change)
The silence check lived inside the dashboard's
useWebSockethook as inline refs and an effect, so applying it to two more sockets by copy would fork its timing constants (WS_SILENCE_MS, the 5s check cadence, the 300s cap) and its hidden-time bookkeeping across three places. Instead the whole rule is extracted once into a framework-agnosticSilenceWatchdog(website/src/utils/socketSilenceWatchdog.ts): it owns the visible-time stamps, the hidden-tab skip, the thaw grace, and the window-doubling-to-a-cap, and the host supplies onlyisOpen(read this socket'sreadyState) andonDead(replace it). All three sockets now drive that one class — the dashboard hook (website/src/hooks/useWebSocket.ts, refactored to construct it, no behaviour change), the Mochi panel bridge, and the Crew Companion session watcher — so they cannot drift. The helper sits inutils/rather thanhooks/websocket/, which is the dashboard facade's private owner directory that nothing else may import from.The dashboard hook builds its one
SilenceWatchdogonce and keeps it for the hook's lifetime; its arming effect only re-points the host and re-arms the timer, so the consecutive-replacement count survives a re-run of that effect, as the inline refs did.On a watchdog replacement the Crew Companion does not fail its in-flight turns: the socket died, not the gateway, so those turns are usually still running, and failing them raised a never-silenced "failed" bubble followed by a "done" bubble for the same turn. The fresh socket's first
slotsframe settles them instead (settleOnSlotsinsessionWatch.ts): a slot it lists as running keeps its start and is closed by its ownchat_done, and a slot it does not list is reported as failed, as a dropped socket reports it. If the fresh socket closes before that frame,onclosefails them as before.docs/system-specs/modules/learn-cron-dashboard.mdnames the shared helper and the two app sockets.Backwards compatibility
Compatible: the dashboard socket's behaviour is byte-for-byte preserved (its ten existing watchdog specs pass unchanged against the refactor); the two app sockets only gain a replacement path for a state (open-but-silent) in which they previously did nothing.
Removes nothing: no path, record, validator or public function is removed or tightened; the change only adds a watchdog and extracts existing logic into a shared module that keeps re-exporting the same constants from
useWebSocket.Tests
website/src/test/socketSilenceWatchdog.test.ts— the shared helper in isolation: replaces a silent OPEN socket, keeps one that delivers frames, skips a non-OPEN socket, skips while hidden, doubles the window per silent replacement and caps it, and detaches onstop().website/src/apps/mochi/test/mochiSocketSilence.test.ts— the Mochi panel socket: a silent OPEN socket is replaced after the window, a socket receiving the 5s status frame is not, and a hidden page is left alone.website/src/test/CrewCompanionSocketSilence.test.ts— the Crew Companion socket: the same three behaviours, plus whatonDonereceives on a watchdog replacement: nothing at the replacement; one success fromchat_donefor a turn the firstslotsframe lists running; one failure for a turn it lists not running, with no second report from a later frame or a straychat_done; only the firstslotsframe settles; a close before that frame fails the turn. Restoring the immediate fail on replacement turns three of these red.website/src/test/socketSilenceWatchdog.test.tsalso pins that astop()+start()keeps the widened window, the property the dashboard hook's single instance relies on.website/src/test/useWebSocket.ownership.test.ts— updated so the facade effect-order ratchet matches the refactored watchdog effect (the effect re-pointssilenceHostRefin place of the former inlinesilenceWindowMs).test/test_ws_status_cadence_contract.py— the backend pin that cross-checks the frontend silence window against the gateway's_WS_STATUS_INTERVALnow reads the constants and thaw-grace fromsocketSilenceWatchdog.ts(their new home); the contract it enforces is unchanged.Determinism: every spec uses fake timers and an injected/mocked clock — no real sleeps. Each is bounded, and each asserts both directions (replaced when silent, not replaced while frames arrive). The per-socket and helper specs were proven to catch the bug: removing
markFrameturns the "keeps a socket receiving frames" case red, and skippingstart()turns the "replaces a silent socket" case red.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 socket-reconnect timing only; no component, layout, theme, or user-visible string renders differently.
Related Issues
Closes #14225
Pattern harvest
Rule candidate: review-prompt
Pattern: a per-connection liveness/silence watchdog copied inline into each socket instead of shared, so the timing constants drift between copies.