Repository navigation
feat(gateway): link computers with pinned mutual tls - #13
Merged
Merged
Conversation
nixuuu
force-pushed
the
feat/linked-computers-1
branch
from
November 3, 2026 22:29
f85e23b to
b78c76c
Compare
nixuuu
marked this pull request as ready for review
November 4, 2026 05:57
nixuuu
added a commit
that referenced
this pull request
Nov 4, 2026
Stage 2 of linked computers (stacked on #13; the whole stack merges into `dev` together when the plan is complete). Threads, workers and projects of every connected linked computer appear next to your own, with a machine badge. Reading, sending, steer, queue, interrupt, approvals and creating a thread on a partner's worker are sent to the thread's home computer over the pinned link; nothing is copied or queued. - `canopy.link.v1`: chunked `RemoteRequest`/`RemoteResponse`/`RemoteCancel`, gated by the new `remote_threads` capability (protocol stays 1). - The gateway does the routing via `<uuid>~<node16>` ids; the home only answers allowlisted thread methods, with no forwarding onward. - An unreachable or outdated partner fails fast with a clear reason; its threads are listed only while it is connected (offline mirrors are stage 3). - UI: machine badges, a read-only banner, and "Needs an update" in Settings. - Tests: `tests/integration/remote-threads.test.ts` (10), two gateways with separate databases and the real mTLS link; check:tmp 686 pass / 0 fail. - Docs: `docs/linked-computers.md` → "Konkretny protokół etapu 2".
nixuuu
added a commit
that referenced
this pull request
Nov 4, 2026
Makes CI reliable again; one item is a real desktop regression. - **Desktop gateway crashed on every start since #13** (`tsyringe requires a reflect polyfill`): the desktop sidecar loads the gateway lazily, so `@peculiar/x509`'s tsyringe ran before `reflect-metadata`. The desktop release jobs failed on it (no broken installer was published). Fix: load `reflect-metadata` first in the sidecar. - **Linked computers closed live links under a slow database**: heartbeats were handled after two DB round trips inside the per-link reader (300–430 ms against a 400 ms dead-link limit). A heartbeat now marks the link alive immediately and writes `last_seen` at most every 5 s; a late-firing timer no longer declares the peer dead. 37 → 0 failures under identical load. - **Desktop sidecars ignored a stop during startup** (kept running, or orphaned forever if the app died). They now exit at once. - **Moves**: shutdown stops move work before announcing; the roll-forward test really stops the source and waits for the target's own record. - Test harness/fixtures: unique scripted provider thread ids (collisions closed the worker link and cascaded 5 s timeouts); Postgres test containers without fsync and a non-blocking readiness wait (45 s, psql error in the message); the registry fixture counts only package downloads; the orphan test waits for the killed guardian's sidecars. Verification: seven linked/queue/move files ×20 (final 360/360 + 180/180 after the last fix), desktop integration ×20 with no leftover dirs, restart loops 50/50, three full check:tmp runs green (833 pass / 0 fail); install, gen:check, typecheck, format:check, builds clean. Follow-ups (not in this PR): one failing worker message stops event processing for that worker until it reconnects; the fixed 100 ms wait for the shutdown announcement could drop it under load.
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
Separate locally verified TLS pin mismatches from retryable RPC authentication failures. Confirm changed certificates across failed route rounds, preserve pinned identities through restarts, and explain identity changes consistently. Add gateway-to-gateway restart, authentication recovery, legacy capability and trust regression coverage. Local tests await maintainer clearance; lint and formatting pass. Related: #13
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
An update or restart can surface an authentication failure as “Pair again” even when the saved computer identity has not changed. Reconnect now treats RPC authentication failures as retryable and requires repeated, locally verified TLS pin mismatches before requesting new trust. A successful handshake with the saved identity clears stale pairing state. ## Investigation - The dial catch classified **every** `ConnectError(Code.Unauthenticated)` as a pin mismatch. That includes invalid certificate validity, a peer rejecting the client pin, and hello validation; on a manual route it persisted `pairing_required`, and on LAN it deleted the route. This behavior exists in the original linking implementation (#13), before the reported release range. - Reviewed `v0.2.0-nightly.120..v0.2.0-nightly.137` and the `.133` → `.137` diff, including #547, #548, #559, #562, #565, #566 and #546. The full desktop hello grew from 32 capabilities to 33 in #559; both releases reject more than 32 as `Unauthenticated: Invalid computer identity` after pinned TLS succeeds. Merged #574 fixes this capability overflow, including compatibility with the older validator. This branch is rebased onto that fix in `dev`. Full source evidence: #573 (comment). - Identity and the 20-year certificate are persisted in `computer_identity`; the private key uses the existing encrypted secrets key. Desktop keeps the same Canopy data directory, database, app/keychain name and `secrets.enc` across versions and channel changes. Keychain/decryption failure stops startup rather than replacing the identity. Reinstalling while preserving that data preserves trust; deleting it creates a new identity. - Production starts computer links, including loading identity and peers, before opening Network access. There is no demonstrated listener-before-store race in that path. The new readiness guard also makes an early or stopping link service explicitly return `Unavailable`. - `manual` means entered by the user, including a LAN/Tailscale address; it is separate from the network's address type. A bad manual path must not override another route or an incoming connection proving the saved pin. The capability-count rejection is source-proven for the reported version pair's full desktop configuration; incident logs would still be needed to attribute every earlier report or explain successful re-pairing. ## Changes - Use a local `CertificatePinMismatch` signal emitted only after TLS proof of possession and validation of a different self-signed certificate. Override ConnectError's inherited structural `Symbol.hasInstance` check so ordinary RPC errors cannot impersonate this local class. Without this override the new LAN test correctly caught a real route-deletion bug, not test timing. Invalid/expired certificates remain rejected without declaring an identity change. - Exhaust routes first. Require the same different certificate at the same manual route in two consecutive failed rounds. A matching pinned TLS connection or ready incoming link outweighs stale addresses. Only a verified pin mismatch removes a discovered LAN route. Saved pins are never replaced automatically. - Clear confirmation evidence after pinned TLS verification, a successful handshake, explicit pairing, route edits and unlink. Existing successful handshake recovery also clears a persisted `pairing_required` after restart. - Use the shared reason “{name}'s identity changed. Pair again to trust it.” for linked computer availability and app updates, including the relay's name when its identity changed. Remove the contradictory automatic-retry explanation for that state. Add stable auth-failure classifications to diagnostics without logging certificates, keys, addresses or RPC payloads. - Document persistence and recovery. No proto changes, protocol bump or migration. ## Regression coverage Added gateway↔gateway integration scenarios using independent databases and real TLS listeners: 1. Repeated startup `Unauthenticated` on manual and LAN routes preserves trust and resumes; verify the LAN route remains after each attempt. RPC error text cannot impersonate a local pin mismatch, and failed TLS connections cannot confirm a manual route's identity change. 2. An early listener returns `Unavailable` for both `Pair` and `Connect` until ready. 3. Both gateway/core restarts reuse persisted identities/certificates and reconnect; a protocol-1 `.133` hello without new capabilities links with a `.137` hello and resumes after upgrading. 4. A real new key requires confirmed pairing, receives no RPC, never replaces the pin, and has consistent availability/update explanations. 5. A persisted stale pairing state heals after restart; a valid alternate route outweighs a stale manual address with another key. The older-version scenario exercises the compatible wire hello/capability set, not archived app binaries. Installer and OS keychain behavior was inspected in source, not exercised on macOS/Windows. ## Validation - After maintainer clearance, ran only the two authorized test files, sequentially, at `nice -n 19`, using `TMPDIR=/var/tmp` and `bun run check:tmp`: `linked-pairing-recovery.test.ts` **10 pass**, `linked-capability-compatibility.test.ts` **3 pass**. Both temp-directory checks passed. The original LAN failure reproduced before the fix (8 pass / 1 fail); the strengthened assertion confirmed deletion immediately after the first auth failure. - Changed-file formatting and lint passed; `git diff --check` is clean. Earlier dependency install and repository formatting/lint checks passed before the original push. - CI validates generation, full typechecking, all test shards and builds for the rebased head. Browser verification remains pending; the UI change reuses existing components and only changes status explanations. ## Copy audit (§8) “{name} must be paired again” / “Link it again…” / “unavailable, trying again automatically” → “{name}'s identity changed. Pair again to trust it.” The text states the verified problem and the explicit trust action, uses two short sentences and avoids TLS jargon. The compact action badge remains “Pair again”. Names are interpolated as whole values and existing wrapping/layout remains in place; short/long-name checks at desktop/phone widths have not been run yet. Related: #13
This was referenced Nov 13, 2026
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.
Each local gateway can now pair with another computer and retain its own identity,
database and execution state. Settings → Linked computers provides pairing,
fingerprint comparison, names, listener control, presence, versions and unlinking.
The dedicated
canopy.link.v1connection uses pinned mutual TLS with encryptedP-256 identity keys. One-use invitations authenticate the first connection before
the secret is sent; persistent attempt limits prevent replay and brute force.
Protocol negotiation reports which computer needs an update on both sides.
Reconnect tries known routes, while announced lifecycle states survive disconnects.
Migration 0048 adds the identity, peer, pairing and revocation records.
Validation: dependency installation, generated-contract check, monorepo typecheck,
full
check:tmp, web production build, and 11 focused two-gateway PostgreSQL/mTLSintegration tests. Chromium checks paired two independent production stacks through
the UI in light/dark at 1440 and 390 px. Evidence and screenshots:
artifacts/linked-computers/verification.md.Stages 2–8 remain out of scope. Actual packaged Electron sleep/update behavior and
macOS/Windows were not exercised; the implemented lifecycle hooks are best effort.