Skip to content

fix(threads): keep retained views live and recover stalled watches - #799

Merged
nixuuu merged 2 commits into
devfrom
fix/remote-thread-event-subscription
Nov 15, 2026
Merged

nixuuu merged 2 commits into
devfrom
fix/remote-thread-event-subscription

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

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

A desktop in remote mode could keep a thread view stuck on old state
(a sent prompt missing, a finished turn still working) while the sidebar
kept updating, until a reload. The overview-head self-check gave up for
good after three repairs without progress and never reloaded the view.

- Thread liveness never stops while the evidence lasts: it resumes from
  the applied cursor twice, then reloads a fresh window like a page
  reload, backing off from 30 s to 5 min.
- The overview's thread status is a second witness: a running thread the
  view shows idle, or a settled thread it shows running, for 10 s triggers
  the same repair even when the cursor looks current.
- The pinned remote transport no longer races TLS probes to every address
  before each RPC. A verified route is reused (each new connection still
  checks the pin) and is probed again after Unavailable or a session
  closing under a call, on route changes and at most every 30 s.
- The BFF closes an SSE response when the gateway connection breaks
  without a scoped error (restart, reset session), so the browser
  reconnects with backoff instead of counting a thread failure.

Related: #748, #777

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu enabled auto-merge (squash) November 15, 2026 08:20
Retained thread views (threadViews, up to 12) are created inside the
thread screen's effect. Their $derived fields (running, ownTurns,
ownEntries, queued, pending, steering, ...) belong to that effect: once
the screen is destroyed (leaving for settings or the overview), Svelte
keeps returning their last value (derived_inert). After a return, the
stream still applied updates and advanced the cursor, but the view kept
showing a turn as working and missed new prompts until a reload. Mobile
(React) never had this.

The fields are now getters over $state memoized on input identity
(lastResult), live in any reader regardless of where the view was made.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu nixuuu changed the title fix(threads): recover stalled watches and reuse verified gateway routes fix(threads): keep retained views live and recover stalled watches Nov 15, 2026
@nixuuu
nixuuu merged commit a5fb4d1 into dev Nov 15, 2026
12 checks passed
@nixuuu
nixuuu deleted the fix/remote-thread-event-subscription branch November 15, 2026 08:44
nixuuu added a commit that referenced this pull request Nov 18, 2026
…gs (#986)

## Nightly.75 console report

- Reproduced the `actorAvatars` exception and `derived_inert` warnings
by invalidating avatar reads just before a PR snapshot reset. Scheduled
refreshes now use a mounted subscriber, and a later explicit read uses
its own fetch function.
- Preserve the saved timeline anchor through a slow initial snapshot.
Start the positioning deadline once data arrives and compare watch
liveness against loaded history. Routine history paging still
contributes to the diagnostics counter. Actionable recovery warnings
keep their reason.
- Open a cold thread through the owner-scoped GetThread RPC while the
overview stream is rebuilding. Skip Git scans for unavailable
placements. Report busy, missing, oversized and timed-out checkouts in
the panel, retain the last successful counts on a transient scan
failure, and cancel an abandoned shared HTTP request when its last
reader leaves.
- Skip idle web, desktop and BFF diagnostics submissions. Reserve
admission and checkpoint space for active sessions within the existing 6
MiB budget. A frozen minute carries its checkpoints even if RPC load
exhausted the space for its metric series.

The screenshots omit response bodies and the expanded recovery objects.
The tests cover concrete paths to the reported statuses. Genuine
connectivity and rate limits still surface.

## Local verification

- Focused shared-query, overview invalidation, BFF state and reads, Git
status, thread history/watch, client diagnostics and persistence tests.
Gateway, domain and web typechecks passed. Lint and formatting checked
on edited files. Full gate runs in CI.
- Chromium at 1280 and 390 px, light and dark. PR reset and avatar
reload produced no exception or Svelte warning after the fix. In a
1000-turn thread, a 2.25 s initial snapshot delay restored an 8 px
scroll offset. A real checkout reported its changed file, and a removed
worktree issued no Git request. Desktop rapid navigation cancelled the
in-flight request. At phone width in both themes, closing thread details
and navigating to the removed worktree started one Git read, cancelled
it once and issued no further Git request.

## Copy audit

Reviewed all ten items in docs/copy.md §8. Generic Git refresh failures
now identify the missing directory, busy checkout, size limit or timeout
and give a recovery action. Directory terminology matches the glossary.
Short, typical and long names were checked at desktop and phone widths.
All items pass or are inapplicable.

Fixes: #456
Fixes: #569
Fixes: #672
Fixes: #799
Fixes: #847
Fixes: #900
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