Skip to content

perf(mobile): share one overview stream and stop settings reloads - #456

Merged
nixuuu merged 1 commit into
devfrom
perf/fetch-1-mobile-overview
Nov 9, 2026
Merged

nixuuu merged 1 commit into
devfrom
perf/fetch-1-mobile-overview

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Part 1 of 5 of the shared-reads stack. It follows a read-only audit of redundant client fetching. The rule throughout: projects, workers, models and similar data change only on known events or the user's own actions. Read them once, keep them in shared memory, update them from the stream or the mutation response, and never ask again for unchanged values.

What changes

  • One overview stream per paired phone. state/overview-bus.tsx owns the only WatchOverview; overview, appearance and shared reads listen to it. Before, AppearanceProvider opened a second full-snapshot stream, so the gateway also opened two remote subscriptions per linked home.
  • Settings in the snapshot (additive proto). New MobileOverviewSnapshot.settings = 3 carries settings read after the subscription began, so a reconnect needs no extra GetSettings. Older gateways leave it unset, and the phone then reads GetSettings once after the snapshot. Settings versions only grow: an older read never replaces a newer event.
  • No reloads on settings navigation. Switching sections no longer reads GetSettings + GetOverview + ListThreads. A settings mutation reads only its own resource; projects, workers and threads come from the stream.
  • One bot list per pairing. Sidebar, alerts, bot settings and connector access share one ListBots read with one request in flight. Alerts keep their baseline semantics: the first list read after each connection, so nothing is replayed.
  • Move progress is a read. It polls GetMoves only, no longer through the mutation wrapper that also ran PreviewMove + GetOverview + ListThreads on every tick.
  • QueryCache in @canopy/domain/shared-query. Keyed shared reads with in-flight dedupe, invalidation coalesced over 40 ms with one trailing read, reads dropped as older after set, fencing after forget/dispose (unpair, new pairing), failures that keep the last value, and a bounded LRU. Unit tests cover dedupe, empty-but-loaded, coalescing, fencing, error retention and eviction.

The unary GetOverview/ListThreads bootstrap stays. mobile.md says it is intentional for first-render latency, and the single stream removes the duplicate without adding a wait.

Measurements (mobile request sequence replayed against two linked gateways)

Per phone session: cold start, 5 settings sections, 30 s foreground before after
WatchOverview streams at the gateway 2 1
Remote WatchOverview subscriptions opened on the linked home 2 1
Snapshot bytes received 8 114 (2 × 4 057) 4 098 (+41 B settings)
GetSettings 7 1
GetOverview 6 1
ListThreads 6 1
ListBots (sidebar + alerts, 10 s each) 8 4 (one shared poll; PR 3 makes it 1)
RPCs per move-progress tick 4 (GetMoves, PreviewMove, GetOverview, ListThreads) 1 (GetMoves)
Time to first overview + settings (local, ms; noisy cold JIT) 46 / 23 20 / 19

Runtime fingerprint ([email protected] fingerprint:generate --build-profile production) matches dev: iOS 6ddec9ef559ee0095ac33e94ff9418a942053b17, Android 5f6eae3ab278f1cd543e9ed763f923a319b65ec9. The change ships over the air.

Tests: packages/domain/src/shared-query.test.ts, tests/integration/settings-expansion.test.ts (the snapshot carries the owner's settings, never another owner's, and later changes arrive as events).

How it was measured

  • Web (real browser, own stack). scripts/bench/client-stack.ts on private ports (dev BFF, server role, synthetic worker), base = dev at a423af85, after = top of this stack. Resource Timing counted /api/* requests per path in a visible tab. Scenarios: S1 sidebar idle 127 s; S2 Settings → Connectors open 126 s; S3 Settings → Workers open 127 s; S4 nine in-app Settings navigations in 27 s. The BFF routes are pass-throughs, so gateway call counts equal these.
  • Gateway and linked home. Two real desktop-role gateways linked over mTLS (tests/integration/support/linked-timeouts.ts), counting RPCs served by the linked home and linked reads started here.
  • Mobile. No device run: the phone's request sequence before and after was replayed from source against the linked test gateways. On-device profiling is still open (see the stack summary).
  • The stack is cumulative; each table lists only the methods this PR changes. Values for the top build apply to this PR because no later PR touches those methods.

Copy audit (docs/copy.md §8)

No UI text was added or changed. Existing messages ("Could not load bots.", "Could not load connectors.", "Could not load settings. Check the connection and retry.") moved to shared stores unchanged.

One WatchOverview per pairing: overview, appearance and shared reads listen
to one bus, so the gateway opens one remote subscription per linked home
instead of two. The mobile snapshot now carries settings read after the
subscription began (additive MobileOverviewSnapshot.settings); a reconnect
needs no extra GetSettings, and older gateways fall back to one read.

Settings navigation no longer reloads settings, overview and threads, and a
mutation reads only its own resource. Sidebar, alerts, bot settings and
connector access share one bot list with one request in flight. Move
progress polls GetMoves only.

Adds QueryCache in @canopy/domain: keyed shared reads with in-flight
dedupe, coalesced invalidation, fencing after set/forget/dispose and a
bounded LRU.
@nixuuu
nixuuu added this pull request to stack #461 November 9, 2026 21:00
@nixuuu
nixuuu marked this pull request as ready for review November 9, 2026 21:01
@nixuuu
nixuuu merged commit 1432acd into dev Nov 9, 2026
11 checks passed
@nixuuu
nixuuu deleted the perf/fetch-1-mobile-overview branch November 9, 2026 21:45
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