Repository navigation
Harden Desktop-owned remote connections and mobile recovery - #554
Merged
Merged
Conversation
tallcode
enabled auto-merge (squash)
September 11, 2026 08:08
huichen
added a commit
that referenced
this pull request
Sep 24, 2026
* fix(remote): serve the invitation the desktop is showing
A bridge generation rebuilt after the first invitation was minted (an
unscanned code, a NATS disconnect, suspend/resume) re-ran `establish()` and
minted a fresh invitation — new desktop NKey, new secure identity, new PSK —
for the same `pair_id`. `shared_runtime` reused the cached runtime for that
pair_id, and with it the cached `HandshakeState`, so the bridge kept offering
the *old* identity while the GUI showed the new QR. Every scan then failed
`secure_open` with `remote_secure_channel_invalid`; the phone folds that into
`desktop_handshake_failed` and shows PA005 ("update both apps"), and nothing on
either side logs why. Only stopping the bridge (which drops `bridge_shared`)
cleared it.
Reuse the cached runtime only while it still serves the invitation these
credentials describe, identified by the two public keys the phone
authenticates against (`desktopKey` and `secureKey`). A credential refresh
keeps both, so a rotated JWT still inherits its single-flight reply slots and
pairing confirmation; a re-minted invitation inherits neither, and the cached
identity is replaced rather than reused.
Regression: #554 cached the handshake state per `pair_id`; before it, every
generation built its `HandshakeState` from the credentials it had just
resolved, so the QR and the served identity could not diverge.
* fix(remote): make a refused pairing diagnosable, and stop blaming the app version
Two follow-ups to the identity fix, both about the same gap: a pairing that
cannot succeed was invisible and gave the wrong instruction.
Desktop side. `secure::Transport::handshake` collapsed every refusal into the
opaque `remote_secure_channel_invalid` and the command loop dropped it on the
floor, so an expired invitation, an already-consumed one, a peer proving the
wrong key, and an undecryptable open all looked identical — and when the phone
sent no reply subject, nothing was reported anywhere at all. A refusal now
carries its reason (`invitation_expired`, `invitation_already_used`,
`peer_mismatch`, `open_undecryptable`, ...) after the unchanged
`remote_secure_channel_invalid` prefix, reaches the desktop's stderr through
the quota-limited `HANDSHAKE_EPISODE`, and is returned to the phone. The
signature-challenge path names the field that disagreed instead of replying a
bare `pairing_identity_mismatch`; a QR describing an identity the bridge no
longer serves fails exactly there.
Mobile side. The phone discarded the desktop's error and its handshake wrapper
turned every outcome into `desktop_handshake_failed: ...`, which the screen
then matched on the word "handshake". So a desktop that was simply unreachable
told the user to update both apps. Timeouts now read as a network problem
(NW001) and a refused handshake as "generate a new code on the desktop"
(PA002); PA005 is left for what it actually means — the two builds cannot
complete the handshake (`pairing_confirmation_mismatch`, a confirmation
without `e2ee_v2`). The desktop's reason is appended to the stable
`pairing_signature_invalid` token, which the credential classifier and
connection presentation both match on, so it stays in the phone's console for
support without changing either classification.
Docs: the PA002 row now covers a refused handshake, and PA005 is narrowed to
the protocol mismatch it is reserved for.
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.
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.
Desktop-owned remote access could lose lifecycle ownership during reconnects, expose stale work after a stop or restart, and leave Mobile with inconsistent recovery and customer status across screens. This change gives Desktop one connection supervisor, separates Remote protocol code from Desktop host adapters, and makes Mobile connection replacement, replay, credential storage, pending operations, and state recovery generation-safe while preserving the existing pairing flow and server APIs.
The customer presentation now derives color, customer state, recovery action, and support code from one model on each client. Blue means available, yellow means a connection is still being attempted, and red means disconnected; technical detail remains in rate-limited console logs. The connection design, operational boundaries, validation plan, and deferred server work are recorded in
desktop/DEV_MD/CONNECTION.md.Validation:
cargo fmt --checkand Clippy with all targets and warnings deniedgit diff --checkNative simulator/device lifecycle and real gateway fault-injection remain runtime acceptance work. No
future-servercode or API was changed.