Repository navigation
perf(remote): stop re-sending an unchanged catalog on a timer - #841
Merged
Merged
Conversation
An idle foreground phone received the full session list (15 KB) and
workspace list (2 KB) every 20s even when the directory had not changed:
73.5 MB/day per phone, on top of a 20 MB/day presence heartbeat. The
snapshots are change-driven now, and the heartbeat carries the revision
that replaces the timer.
- The presence heartbeat advertises `catalogVersion` {epoch, sessions,
workspaces}, read O(1) from the revision cache without touching the
store. A client whose applied revision is older pulls the catalogue
itself, so a snapshot dropped on the at-most-once lane heals within one
heartbeat instead of 20s — strictly faster than the timer it replaces.
- Presence cadence 1s -> 3s. Liveness only has to beat inside the client's
15s receipt window (5x margin). The catalog change-detection tick stays
at 1s, so a session created by the TUI, the CLI or loop still reaches
the phone as fast as it did before.
- `secure::publish` now reports whether the payload actually left. Sealing
yields nothing while the channel has no established key — before the
client's handshake, and again after a credential refresh cleared it —
and the payload was dropped silently while still returning Ok. A
change-driven publisher has to see that to retry; the periodic one this
replaces never noticed, which is exactly how the old self-heal masked
the drop. Snapshots now advance their signature only once sent.
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.
Problem
An idle foreground phone received the full session list (~15 KB) and workspace list (~2 KB) every 20 seconds even when the directory had not changed, on top of a 1 Hz presence heartbeat:
presencestate.sessionsstate.workspacesThat is idle traffic — more than a heavy run's entire coalesced live lane. The 20s re-send existed as the only self-heal for a snapshot dropped on NATS core (at-most-once), because the phone does not poll the catalogue on a healthy link.
Approach
Replace the timer with a revision advertised on the presence heartbeat.
catalogVersion{epoch, sessions, workspaces}, read O(1) from the revision cache without touching the store.list_sessions/list_workspaces).futureCLI or loop still reaches the phone as fast as before.The revision only advances when the snapshot's visible content changes, and it is recomputed from the store on every catalog tick rather than accumulated in a dirty flag — so a stale advertised revision (which would wedge a client permanently) is not reachable.
A real bug this uncovered
secure::publishdropped the payload silently while returningOk(())whenevertransport.seal()yieldedNone— i.e. while the secure channel has no established key. That window occurs twice: before the client's handshake completes, and again after a credential refresh cleared the channel.A periodic publisher never notices (the next tick carries the same content), which is exactly how the old 20s self-heal masked it. A change-driven publisher loses that change permanently. This surfaced immediately as a failing
start_runs_the_full_bridge_and_stop_winds_it_down, and the fix is what the change depends on:publishnow reports whether the payload actually left the endpoint.Compatibility
No wire-format change and no new capability bit. An older desktop keeps publishing
presencewithoutcatalogVersion; the client ignores an absent revision. An older client ignores the new field and keeps its existing request/arrival fencing, unchanged.get_presencestill returns the full snapshot, so a fresh subscribe is never left waiting on a heartbeat.Verification
remotemodule: 252 passed / 0 failed. Mobile: 128 suites / 2042 tests pass.cargo fmt --check,cargo clippy --all-targets -D warnings,tsc --noEmit,eslintclean.idle_catalog_advertises_a_revision_instead_of_resendingpins both halves of the contract, and asserts the heartbeat stays under 512 B (measured 242 B) so a regression that ships the directory inside it fails here instead of as a silent cost.docs/internals/desktop/CONNECTION.mdupdated, along with the comments that still described the removed 20s behaviour.Not verified
Payload sizes and broker-side behaviour are measured; a real phone against a real NATS broker over a full day is not. That remains a follow-up.
Follow-ups (deliberately out of scope)
Trimming history/live payload content (reasoning text, tool arguments, per-entry field trimming) is more invasive than it looked and is not in this PR:
entry.roleis read directly by the mobile projector, so removing it would break an older client and requires a per-client capability-gated rewrite layer in the desktop's history relay, which is currently pure pass-through.