Repository navigation
fix(threads): keep live watches recovering after transport drops - #748
Merged
Merged
Conversation
Keep transport retry backoff separate from the thread projection repair budget. Detect a stalled applied cursor against overview heads and resume incrementally on desktop and mobile. Fixes: #673
nixuuu
added a commit
that referenced
this pull request
Nov 15, 2026
) ## Problem In the desktop app the open thread view could keep showing old state (a just-sent prompt missing, a finished turn still shown as working) while the sidebar and thread summary kept updating. Only a reload (Cmd+R) recovered it. The view stayed "live": no sync indicator, no error, composer enabled. Mobile never had this. The renderer console showed hundreds of `derived_inert` warnings. ## Root cause Retained thread views (`threadViews`, up to 12 threads) are created inside the thread screen's effect (`openThreadMemory` in a `$derived` on the page). `ThreadState`'s `$derived` fields (`running`, `ownTurns`, `ownEntries`, `queued`, `pending`, `steering`, …) belong to that effect. When the screen is destroyed (leaving for settings or the overview), Svelte 5 keeps returning their last value (`derived_inert`, `execute_derived` in svelte 5.57). After a return, the stream still applied updates and advanced the cursor, so no recovery fired, but everything read through those fields was frozen. Reproduced in isolation: a class `$derived` created in an effect stays at its old value after the effect is destroyed and the `$state` changes, while a getter returns the new value. **Fix:** the fields are now getters over `$state`, memoized on input identity (`lib/shared/last-result.ts`). They stay live in any reader regardless of where the view was created, and keep a stable result for unchanged inputs. `docs/client-performance.md` records the rule: retained state must not hold `$derived`. ## Also in this PR (recovery and transport hardening) - **Liveness never gives up** (`packages/domain/src/thread-watch-liveness.ts`). The overview-head self-check stopped for good after three repairs without progress, and never reloaded. Now it resumes from the applied cursor twice, then reloads a fresh window as a page reload would, backing off from 30 s up to 5 min while the evidence lasts. - **Second witness: overview thread status** (`history.svelte.ts`, thread page). If, for 10 s, the live overview reports `running` while the view has no running turn, or `idle`/`interrupted`/`failed` while the view still runs one, the same repair starts even when the cursor looks current. This is the signal the user saw. - **Pinned remote transport reuses the verified route** (`packages/transport/src/routed-pinned.ts`). Every RPC used to race fresh TLS probes to every address first: tens of thousands of aborted handshakes a day on the gateway, extra latency, and failures on a slow link while the session was fine. Now a verified route is reused (each new connection still checks the pin in `client.ts`). It is probed again after `Unavailable`, after a session closes under a call the caller did not abort, when routes change, and in the background at most every 30 s. Concurrent probes are shared. - **SSE transport loss is not a thread failure** (`sse.ts`, `gateway-errors.ts`). When the gateway connection breaks without `canopy-error-scope` (`canceled`, `unavailable`, `internal`, e.g. a gateway restart), the BFF closes the response, so the browser reconnects with backoff. Before, it sent `failure`, and three of those stopped the watch. - Docs: `ui-api.md`, `client-performance.md`, `mobile.md`, `desktop-remote-frontend.md`. Mobile shares the liveness class: it keeps resuming incrementally, with backoff and no cap. Related: #748, #777 ## Verification Ran locally: - `check:tmp` on `packages/domain/src/thread-watch-liveness.test.ts`. - `check:tmp` on the integration tests `desktop-clients` (new: route reuse without per-call probes, then replacement after the route dies), `thread-watch-failures` (new: SSE closes without `failure` when the gateway session ends), `thread-client-continuity`, `remote-threads`, `gateway-chatter`, `desktop-version-skew`, `mobile-network-port`, `desktop-updates`, `paired-app-updates`. - Typecheck of `packages/transport`, `packages/domain` and `apps/web` (svelte-check). - oxlint and oxfmt on the changed files. - After the root-cause fix: `apps/web` typecheck (svelte-check), oxlint and oxfmt on the changed files. There is no Svelte test harness for `.svelte.ts` state and web UI tests are out of policy; the mechanism was confirmed with a standalone compile of a minimal module against the repo's Svelte. No visual change. Not run: the full CI gate (left to CI) and a physical remote desktop session. The repair path will log `Thread watch resumed from applied cursor` / `Thread watch reloaded` in the renderer console. ## Copy audit (docs/copy.md §8) No UI text changes: only console diagnostics were added. Nothing to audit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remote prompts and even a desktop send could disappear from the desktop timeline while the overview kept updating. Three short native EventSource transport failures consumed the thread repair budget introduced in #673 and permanently stopped that watch; later online/focus events could not reopen it.
Transport loss now stays in the existing connection backoff (capped at 30 seconds), without exhausting the projection repair budget. Scoped gateway errors, invalid batches and premature stream completion retain their bounded repairs. Mobile applies the same distinction.
The visible thread is always included in overview head selection. Desktop and mobile compare that head with the view's own applied cursor, independently of the warmer's cache. After 10 seconds without progress, they resume incrementally from that cursor, preserving loaded history. Repairs are spaced by at least 30 seconds, capped at three per unchanged cursor, and recorded in Timeline recoveries with redacted numeric logs. No full snapshot is requested by this self-check.
Validation:
Fixes: #673