Repository navigation
feat(remote): a desktop can pair out to another desktop, and both platforms merge sessions across machines - #955
Merged
Merged
Conversation
…te client
A desktop can now act as the *client* half of Remote v2: paste a
`futureos://remote/pair` link from another machine and read that machine's
sessions, exactly as the phone does. This is the spine — pairing,
authentication, and encrypted request/reply. It is deliberately not the
whole feature.
Two roles now coexist and stay apart:
remote / remote_host host: phones pair *into* this machine
remote_peer client: this machine pairs *out*
They keep separate credentials (`remote_pairing.json` vs a new
`remote_peers.json`), separate lifecycles, and separate Tauri command
namespaces, because they answer different questions — "who is connected to
me" versus "who am I connected to" — and reading one status where the other
was meant is exactly the bug a shared namespace invites.
The remote host's sessions are never written to the local store and never
read from the local agent: the remote agent is the only authority for its
own transcript, and a local row would be a second copy of it. The book is a
*list* because a desktop may be paired with several hosts; each entry is
independent, and re-pairing one host must not disturb the others.
Testing is end-to-end rather than fixture-based: the tests stand up the real
host bridge on the fake broker, mint the host's own invitation (so the PSK
and Noise keys are real), and drive the client through claim -> handshake ->
list_sessions. That is the only shape that catches a handshake which works
only against a hand-written fixture, a subject that drifts from the host's
routing, or a reply context that does not match what the host seals.
Also in this change (host contract, needed by both clients):
- `state.sessions` carries `lastMessageAt`, the same coalesce the store's
own ordering uses, so a client merging several desktops can rank rows
across machines without inventing a different rule.
Not in this change, and not claimed: no reconnecting supervisor (no retry
budget, credential-refresh timer, sleep/wake handling, or event fan-out),
no desktop UI yet, no mobile multi-desktop work, and no icon picker. A
dropped socket surfaces as an error and the next request reconnects; a
client that silently stops delivering events would be worse than one that
is visibly disconnected, so the background half is left out rather than
half-implemented.
A connection could answer commands but could not be *watched*: a session view
needs the host's pushes, not just its replies. This subscribes to
`p.{pair}.evt.>` and `p.{pair}.presence`, decrypts each record with the same
traffic keys and the same subject-as-associated-data rule as a reply, and
forwards `{desktopId, kind, payload}` to the webview.
Three details that are decisions rather than mechanics:
- The traffic-key channel moves behind a `std` mutex, shared by the command
path and the stream task. A `std` mutex is correct here only because the
guard is never held across an `await` — sealing and opening are pure CPU,
and holding the lock while awaiting a reply would serialise the stream
behind every slow command.
- A record that fails to authenticate is **dropped**, not reported. A relay
can inject garbage at will while the connection is healthy, so treating
that as a protocol failure would let anyone with relay access knock the
client off a working host.
- The subscription task is aborted on disconnect and replaced on reconnect,
so a host the user removed cannot keep emitting into a UI that has
forgotten it, and a dead socket cannot keep feeding stale events.
Tested end-to-end against the real host bridge: the host publishes through its
own event path and the subscriber must receive the envelope decrypted, with
the event type, session, and run intact.
The list layer for remote desktops: a pure merge that interleaves this
machine's threads with every paired host's sessions under one ordering rule,
plus the client-role command surface and the icon registry.
The merge is pure and separately tested because three of its properties are
easy to get quietly wrong and expensive to debug in the UI:
- **Rows keep their source.** Session ids are unique per host, not globally,
so two machines can each hold a session called `shared`. They stay two
rows, each labelled with its host; a row that lost its source would be
routed to the wrong machine on click.
- **There is one ordering rule.** Local threads already rank by
`pinned, COALESCE(last_message_at, updated_at, created_at)` on the host, and
remote sessions now carry that same coalesce as `lastMessageAt`. Ranking
them together by a different rule would make the merged list disagree with
the per-machine lists the user can also see.
- **Unknown age sorts last.** A host older than the `lastMessageAt` field
sends sessions without one; treating that as "now" would float a stale
conversation to the top. Ties break on the row key so a poll cannot
reshuffle the list under the reader.
Icons are a fixed, stored-by-id set rather than free text: the glyph replaces
the machine's name in a row that also holds a title and a timestamp, so it has
to be same-width and instantly distinguishable, and an unknown id must render
the default instead of putting arbitrary stored text on screen.
The management surface for the machines this one connects out to: paste a
pairing link, then per host a connection state, a local name, an icon, and
unpairing. The remote sessions themselves stay in the shared conversation
list (with a source badge) rather than getting a second list here, so there
is exactly one place to look for "a conversation".
Placed next to Phone Control in the rail because they are the two directions
of one idea — who connects *to* this machine, and who it connects *out* to —
but kept as two entries: they are reachable from different states (Phone
Control needs a sign-in, this needs a pasteable link) and someone looking for
one should not have to know the other exists.
Three judgement calls in the UI:
- A connected host whose *agent* is unreachable shows "Agent unavailable",
not "Connected". The link is up and every command fails; saying
"connected" there is a lie the user only discovers when a message does
not send.
- Pairing shows the cost before the action: taking the link replaces the
other machine's phone pairing, so the warning is part of the form, not a
post-hoc notice.
- Unpairing uses a plain dialog, not the shared delete-confirm — nothing
the user created is destroyed, and the other machine keeps all its data.
Tests: merge/ordering and the icon registry are covered as pure units
(18 tests); the rail's nav-order guard was updated deliberately. Full desktop
suite: 3310 passing.
The visible half: a device selector above the conversation list, remote sessions
interleaved with local threads under one ordering, and a view for reading (and
replying to) a remote conversation.
Three decisions worth naming:
- **Merged mode only turns on when a remote session is actually present.** A
user with no remote desktops keeps today's list exactly — workspace groups,
chat section, selection mode. The flat merged view is a different
information architecture (a workspace name can exist on two machines), so it
should not be forced on people who have nothing to merge.
- **Remote rows are their own component**, not synthesized `StoredThread`s fed
to the local row. Almost every local affordance is wrong here: rename, pin
and delete write the local store, the run menu reads the local agent, and
selection is local state. A remote row can be opened and read; the actions
that make sense on it are host-side commands.
- **The transcript is rendered from the host's own `SessionEntry` records**
(the same projection type the local timeline uses), not converted into local
message records. A local record would be a second copy of another machine's
transcript, and every code path that treats a local record as authoritative
would then be wrong about it.
The timeline hook is where the correctness lives, so it is what is tested:
history on open, `before` taken from the host's own `nextOffset` (asking with a
count would silently return the wrong slice), only this session's pushes
appended, re-delivered events not duplicated, and — the failure that shows up
as "my history is wrong" — a slow page for the previous session never landing
under the new one's title.
The composer sends through the phone's `prompt` command, so the host's durable
receipt keyed by command id carries over and a retry cannot run the prompt
twice. It is deliberately plainer than the local composer: attachments, slash
commands and the in-box model picker are each a host-side operation, and
offering them before they are wired would produce buttons that look like they
work and silently do nothing.
Remote approvals are the one interactive thing this feature adds, and the one
easiest to get wrong invisibly: the wrong machine gets authorized, or a card
lingers after someone already answered.
The host's `approval_request` event is the only place a client learns a tool is
waiting — unlike a local session there is no approval row in any local store to
read — so the hook watches the stream and answers with `approval_decision`
naming that host and that session explicitly. With several desktops paired,
"the current one" is not the same machine as "the one that asked".
Two details that decide whether the card behaves:
- A re-delivered request (the host can resend on reconnect) replaces its card
rather than adding a second one; two identical cards would let the user
answer one question twice.
- Another client answering — the phone, or the host's own window — sends an
`approval_decision` push that clears our card, because a stale card invites
a decision that no longer exists. A decision that failed to reach the host
keeps its card and reports the error.
The card names the machine it will run on: "allow" on a card that does not say
where reads as a local action, and the whole point is that it is not.
Clicking a paired desktop now opens its settings rather than an inline accordion: automation toggles read from and written to that host (`get/update_desktop_settings`), plus a read-only summary of what that machine has — models, providers, skills, tasks. Kept as its own page, not rows in the app's Settings dialog, because every value here lives on the *other* machine: "auto-upgrade skills" would otherwise be ambiguous between this desktop and the remote one, and the two genuinely have different answers. The sections are labelled with whose machine they describe. Local-only settings (the name and the icon) sit on the same page but under a "this computer only" heading, since they never reach the host or the platform — the labels are what keep that distinction visible. Rows the host cannot serve are disabled rather than hidden: a user paired with an older build should see that the capability exists and is unavailable, not wonder why their settings look different from someone else's. Naming moves off the list row so the row stays a row and the list stays scannable.
A dropped connection used to stay dropped until something asked it to work
again. Now a connection that was healthy and then failed starts a bounded
retry: 1, 2, 4, 8, 16, 30 seconds with ±20% jitter, then a terminal failure.
Bounded and jittered, both deliberately:
- The window is finite because a client that retries forever is
indistinguishable, to the user, from one that hung — and the user has no way
to tell which. Past the schedule the failure is reported and stays reported.
- The jitter is what keeps several hosts coming back after one network blip
from stampeding the relay in the same second.
The supervisor is spawned only when a *live* connection fails, never after a
failed first connect: a user who pressed Connect and watched it fail should see
that failure, not have the app quietly keep trying. An explicit Disconnect
aborts the supervisor, so a retry scheduled a moment earlier cannot silently
undo the user's decision — asserted directly, since that is the failure this
design invites.
The tests assert the base schedule's growth and cap plus each drawn delay's band,
rather than the drawn sequence being monotonic: with jitter, 30s×1.2 exceeding
the next step's 30s×0.8 is the intended behaviour, and asserting otherwise would
be testing the noise.
Groundwork for showing a desktop's glyph instead of its full name in the session list: the paired-desktop registry gains an icon, stored by id from a fixed set rather than as a glyph or free text. Stored by id because the value ends up drawn beside a session title: it has to be same-width and distinguishable from the other desktops' glyphs, and an id this build does not recognise must render the default instead of arbitrary stored text. The set matches the desktop app's by name, so one machine does not look like two different ones depending on which device you are holding. `labelDesktop` patches name and/or icon per field — an omitted field is left alone, an empty string clears it — because the editor has two independent controls and a single "set the label" call would make clearing the name also drop the icon (and vice versa). A credential refresh preserves both, for the same reason it already preserved the name: refreshing is not the user changing how the desktop looks. An unknown desktop is a no-op rather than an error, since the picker can fire while a concurrent unpair is removing the entry.
The paired-desktops editor gains an icon row beside the name field, writing through the same local-only path: neither value reaches the desktop or the platform, so both are applied without touching the connection. Clicking the selected icon clears it, so returning to the default needs no separate "none" affordance — the same way a blank name already falls back to the desktop id. The glyph set matches the desktop app's, and both i18n bundles carry labels for it. This is the storage-and-editor half of showing a desktop's glyph in the session list; the list itself is not switched over yet.
The phone's session list can now show every paired desktop's sessions in one
time-ordered list, with a picker above it for "all desktops" or a single one,
and each row carrying its desktop's glyph.
The ordering is a pure module with its own tests, because it has to agree with
the desktop app's: `pinned` first, then the host's own `lastMessageAt`, ties
broken on a stable key. Two machines holding the same session id stay two rows,
each labelled with its source — a row that lost its source would be opened
against the wrong machine — and a session with no timestamp sorts *below* dated
ones rather than floating a stale conversation to the top.
On the connection model, stated plainly because it is a deliberate limit:
the phone still runs **one active connection** — the one whose conversation,
timeline, drafts and outbox the UI is wired to — and these additional
connections are read-only catalogue observers. Promoting them to full runtimes
would mean N timelines, N outboxes and N sets of per-conversation state, which
is a much larger change than "show me every desktop's sessions in one list"
needs. The active desktop is excluded from the observers, so its catalogue is
never fetched twice and its presence heartbeats are not doubled.
Two smaller decisions:
- The merged view replaces the workspace tree only when it has rows the tree
cannot show (another desktop's). A user with one pairing keeps today's list
exactly; the flat view is a different information architecture, because a
workspace name can exist on two machines at once.
- A row from another desktop gets no actions menu. Rename, pin and delete are
commands to the *active* desktop, and offering them on a row they would
address to the wrong machine is worse than not offering them.
Also hardened while here: a `SecureStore` read that yields `undefined` (rather
than the documented `null`) is now treated as "absent" instead of "corrupt" in
both the registry and the legacy commit marker — otherwise a platform shim's
missing value reads as a corrupted store.
The end-to-end pairing test asserted that the host reported its agent as unavailable — which is true only on a machine with no agent running, and false as soon as another test in the same run has started the shared mock agent. It passed alone and failed in the full suite, which is the signature of a test asserting the environment rather than the code. Whether an agent happens to be reachable is not something the client owns. What it owns is how it *reads* the host's report, so that is now a unit test on `agent_available` — including the case that matters: a host omitting the field must not be assumed healthy, because the flag gates a UI that says everything is fine.
huichen
enabled auto-merge (squash)
October 9, 2026 10:53
…s clean CI runs clippy twice for the desktop backend — with the default (gui) feature and with --no-default-features — and the second pass caught what the first could not: the client-role re-export exists for the GUI command layer, so in a headless build it is an unused import, which -D warnings rejects. Running only the default-feature pass locally is exactly the narrower-than-CI check that misses this.
This was referenced Oct 9, 2026
Merged
huichen
added a commit
that referenced
this pull request
Oct 10, 2026
…t behind (#982) The client role landed over eighteen PRs and left no trace in `docs/`: neither `CONNECTION.md` nor `PRODUCT.md` mentioned that a Desktop can connect *out*, and both still framed the domain as phone-only. `CONNECTION` calls itself the single maintenance location for this domain, so a reader following the repo's own convention would have concluded the desktop client could not exist. Added §2.2.2 (both languages): the two roles in one process, the handshake's identity fields and why identity is not a capability, `remote_peers.json` being separate from the host's book and why, the merged list and the `lastMessageAt` key it needed, what is hidden rather than shown as a dead button, the capability alignment with mobile, and the three known limitations stated as limitations (host-side single slot, mobile's read-only catalogue observers, device identification needing a newer host). Corrected two claims that had stopped being true: the rail entry is always shown (connecting out needs no account), and the feature is no longer phone-only. `PRODUCT`'s §5.3 now says what the two directions are for. Four things the audit turned up, all mine: * `hiddenCount` (#955) was never called — the filter selects rows, nothing reports how many it withheld. Deleted, with its assertions replaced by the filter behaviour itself. * `forgetRemoteToolTargets` (#974) was never called either, so the fetched tool-argument cache was never dropped and grew for the life of the window. Now wired into leaving a conversation, which is where the doc always said it went — and the test asserts a *re-read*, because dropping the cache would be wrong if nothing refetched. * `RemoteConversationSettings` computed a refusal message, and commented that the user "gets a value that snapped back **and a reason why**" — but never rendered it. The hook's tests asserted on the state, not on the screen, so the reason reached nobody: the user watched a setting revert with no stated cause. Now rendered as an alert beside the pickers (mutation-checked: hiding it fails the test). * Four translation keys (`toolRunning`, `loadOlderFailed`, `providersHint`, `newConversationHint`) were superseded by later changes and left behind, plus `pairedDevices`, which I wrote in #965 and never used. Removed. Also verified: `thinkingLevel.*`'s six keys are built dynamically (`t(\`thinkingLevel.${level}\`)`) and are not orphans, and the four orphan keys in `remote.json` (`connectedAs`, `reconnectingAs`, `connectionHint`, `agentUnavailable`) predate this work (#123, #242, #554) — left alone. `make check-docs` reports the same failures before and after this change (whitelisting of `agent/src/prompt/*.md`, and `docs/architecture/tasks.md` whose Chinese pair another in-flight branch has not written yet); none of them comes from these four files.
huichen
added a commit
that referenced
this pull request
Oct 11, 2026
… up (#983) * fix(remote): what rendering the client role's screens for real turned up The screenshot harness renders the real app (real CSS, real bundle, real input events) and had not been run against this feature — there was no scenario for any client-role screen. Running it found six defects, one of them mine from the first PR and none of them visible to the jsdom suite. **1. The harness was rendering blank pages, for every scenario.** `remote_peer_list` was read straight into React state, so a backend that answers `null` — the harness mock does, for a command it does not implement — put `null` into `peers`, and the first screen that rendered it (`peers.map`) threw during render and took the *whole application* down. Not just the remote screen: every capture since #955 produced a white rectangle, and nobody noticed because no scenario runs in CI. Validated at the helper boundary now (an empty list is the honest reading of "no answer"), with a test. **2. A turn that ran several tools showed only the first.** The transcript did `blocks.find(tool_call)`, so a turn that ran `read` then `shell` rendered one row — and the second call's arguments were never fetched, so the line that says what the machine actually ran was simply missing. One row per call now, each fetching its own target, with the fixture updated to a two-call turn (the old fixture had one tool per turn, which is why the tests agreed with the bug). **3. The local conversation tree disappeared in merged mode.** Merged mode turns on as soon as *any* host is connected, and it passed neither `depth` nor `hasChildren` to the local rows: forks rendered as roots, with no indent and no fold toggle, so a user with a host connected lost their tree. The rail now keeps each local row's place, and collapsing a parent hides its forks exactly as the local list does — a toggle that renders but does nothing would have been worse than no toggle. **4. The client direction's explanation was printed twice** on the Remote page: the hub renders it as the section subtitle and the section rendered it again. The host half had been fixed in the same PR that introduced this; only the client half was missed. **5. A button's label wrapped into two stacked lines.** The host-settings "保存" button measured 44×32 with the label on two line boxes (保 over 存) — the shared `Button` had no `whitespace-nowrap`. Now it does, with a test; a control whose label is unreadable is not a control. **6. The device selector had no accessible name.** Its visible name starts with a decorative glyph, so the control's accessible name was the emoji — unreadable to a screen reader and unaddressable by label. `aria-label` added. **Verified as *not* defects, by measurement rather than by eye.** A visual read claimed the remote conversation's header overlapped its compress button and that the button contained an overlapping icon. Measured: the header does not overflow (`scrollWidth == clientWidth`) and no two children's boxes intersect; the button renders no icon at all (it is `{t("compact")}` and nothing else). Both claims were artefacts of a magnified crop, and I left the code alone. **Two scenarios were also broken** by the #965 rename of the rail entry — they still tapped "手机遥控" — which is what a scenario file nothing runs in CI does. **New scenarios (desktop):** `remote-hub`, `remote-merged`, `remote-device-picker`, `remote-conversation`, `remote-host-settings`, `remote-host-tasks`, each with `eval` assertions against the rendered DOM: both directions named, this machine's and the host's conversations interleaved, a row naming its host, a remote composer saying where the message runs, tool targets read back, the host's model in the picker, no API key anywhere in the UI, and no duplicate explanation. The harness's desktop mock gained the client-role commands (peers, catalogues, workspaces, the routed `remote_peer_request` family) and a two-host fixture — one connected, one disconnected, because "a host that is not reachable" is a state the list has to survive. 11/11 scenarios captured (7 new, 4 pre-existing as a regression net) with every assertion passing, and 3679 tests with 0 uncovered lines added. * style(shot): drop the trailing blank lines eslint rejects CI lints `shot/**` as well as `src/**`; my local run only covered src, so this reached CI. Running the project's own lint script (which is what CI runs) is the scope that matters — the same lesson as clippy's --no-default-features earlier.
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.
What this is
A desktop can now act as the client half of Remote v2 — paste a pairing link
from another machine and work with its conversations — and the phone's session
list can show every paired desktop's sessions in one merged, time-ordered list.
Two roles now coexist and stay apart:
remote/remote_hostremote_peer(new)~/.future/remote_pairing.json~/.future/remote_peers.jsonremote_*remote_peer_*They answer different questions — "who is connected to me" versus "who am I
connected to" — and reading one status where the other was meant is exactly the
bug a shared namespace invites.
Desktop
Client runtime (
remote_peer/): linkparsing, platform claim/refresh/revoke, credential book (several hosts, each
independent), Noise handshake, encrypted request/reply, live event stream, and
a bounded reconnecting supervisor.
UI: a Remote Desktops screen (pair, connect state, per-host settings,
unpair) beside Phone Control; a device picker above the conversation list; local
threads and remote sessions merged under one ordering with each remote row
badged with its machine's icon; a conversation view with a transcript and a
composer; and approvals, answered against the host that asked.
An embedded terminal, reviews, the file tree and the local agent's run panels
are deliberately absent for remote sessions: none of them have a host route, and
fabricating local records to feed them would be the second-copy-of-truth this
feature must avoid.
Mobile
Per-desktop icon and name (local-only, stored by id from a fixed set), a desktop
picker above the session list, and a merged list ordered by the same rule the
desktop app uses.
Stated limit: the phone still runs one active connection — the one whose
conversation, timeline, drafts and outbox the UI is wired to. The additional
connections are read-only catalogue observers. This is a deliberate scope
choice and not the full multi-runtime M1: promoting the observers to full
runtimes means N timelines, N outboxes and N sets of per-conversation state.
The active desktop is excluded from the observers, so its catalogue is never
fetched twice and its presence heartbeats are not doubled.
Host contract change
state.sessionsnow carrieslastMessageAt, the sameCOALESCE(last_message_at, updated_at, created_at)the store's own orderinguses, so a client merging several desktops ranks rows across machines without
inventing a second rule. Optional by contract; older clients ignore it.
How it is tested
Correctness here lives in a few places that are easy to get quietly wrong, so
those are what the tests pin:
fake broker, mint the host's own invitation (so the PSK and Noise keys are
real), and drive the client through claim → handshake →
list_sessions; thendrop the PSK and reconnect over
Noise_IK; then assert a swapped host key isrefused rather than adopted. A handshake that only works against a fixture
cannot pass.
and run intact, and a record that fails to authenticate is dropped rather than
treated as a protocol failure (a relay can inject those at will).
sessions from two machines stay two rows, unknown age sorts last rather than
floating a stale conversation to the top, and ties break on a stable key so a
poll cannot reshuffle the list under the reader.
beforecomes from the host'sown
nextOffset, only this session's pushes are appended, a re-deliveredevent is not duplicated, and a slow page for the previous session is discarded
rather than landing under the new one's title.
card, and another client's decision clears it.
delay's jitter band, and that an explicit disconnect aborts the supervisor.
Local runs: Rust
1634 passed / 1 failed, desktop3326 passed, mobile3058 passed. The one Rust failure isremote::commands::bridge_tests::desktop_settings_refuse_to_guess_sandbox_availability,a pre-existing host-specific failure recorded in
.future/memory/testing-gotchas.md(the test's scripted
probe_sandboxis overridden by this machine's real probe);it fails identically without this branch and CI on Linux does not hit it.
Not in this PR
shows no actions menu rather than a menu whose commands would be addressed to
the wrong machine.