Repository navigation
fix(computers): keep pairing across updates and restarts - #573
Conversation
|
Static follow-up found a deterministic
I am preparing the requested follow-up PR for the capability overflow, including compatibility with the unchanged 32-entry validator on |
|
The requested follow-up is now open: #574, head The follow-up splits every outgoing hello at 32 entries, retains the original configuration/move/update features in that prefix, and combines both fields under a bounded receiver limit. Older peers ignore the additive overflow field; new peers also accept unfixed The new integration coverage uses the complete production desktop constructor, includes both gateways restarting on their existing databases, and exercises the old 32-entry guard rather than only changing an app-version string. It emulates the older decoder/validator; it does not launch a released desktop binary. No local tests or servers were run; execution and repository checks are left to CI. The static conclusion remains: this exact release pair has a deterministic capability-count rejection after successful TLS pin verification. The traced normal startup/update/keychain paths do not silently rotate the identity or open a listener before secrets load. Without production logs, that does not establish the cause of every earlier update report or explain why re-pairing succeeded on the reported machine. |
The full desktop hello grew from 32 capabilities in nightly.133 to 33 in nightly.137 when #559 added `remote_thread_panel_v1`. Both versions reject more than 32 as `Unauthenticated: Invalid computer identity`, so an update reconnect can fail after TLS pin authentication succeeds. #573 prevents the false pairing warning, but does not repair this handshake failure. Keep the original nightly.133 capabilities in field 7 (at most 32 entries) and send subsequent capabilities in additive `NodeHello.additional_capabilities` (field 8). Older peers ignore field 8 and keep all their existing configuration, move and update capabilities. New peers combine both fields before negotiation and accept unfixed nightly.137 hellos containing 33 entries in field 7. Bound the combined list at 128 and reject overflow with `InvalidArgument`. Pair requests/responses, connect, welcome and rename broadcasts all use the same encoding. TLS pins, certificate verification and owner scoping retain their existing checks. Added gateway-to-gateway integration coverage using the actual desktop `startComputerLinks` constructor, which enables every production capability: - Complete production pairing, followed by restarting both gateways on their existing databases; compare pins and full negotiated capabilities. - Raw unfixed 33-entry Pair and Connect requests over pinned TLS, plus malformed overflow rejection without changing persisted trust. - Mixed-version pairing in both directions and rename handshakes against the nightly.133 32-entry guard and unknown-field behavior. This fixture emulates the old decoder/validator; it does not run a released desktop binary. Validation: generated protobuf bindings with `bun run gen`; formatted changed source files; `git diff --check` is clean. No local tests, typecheck, lint, build, servers or Docker runs: the maintainer has a performance measurement running and requested CI-only execution. CI must validate the new coverage and repository gates. No UI copy changed. Static investigation and startup/updater/keychain evidence: #573 (comment). The source establishes this release regression in the full desktop configuration; incident logs would be needed to attribute every earlier report or explain successful re-pairing under a different configuration. Fixes: #559 Related: #573
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
31bd38b to
8cbb63f
Compare
|
Rebased onto The repeated CI failure was a real route-retention bug, not timing. Connect's The mismatch class now overrides that check to require its own local prototype (transport.ts:27–34). This retains Connect error handling while ensuring RPC status/messages cannot produce the local TLS proof. Strengthened the LAN regression to check route retention after the first attempt and added a repeated failed-TLS/manual-route scenario. The existing real-key-change/no-auto-trust scenario still passes. Authorized local verification ran sequentially, one file at a time, at
The full checks are running in CI for the new head. No other local test files were run. |
The cross-version pairing recovery test read B's saved version immediately after observing A's `connected` status. In both failed #573 runs it expected `0.2.0-nightly.137` and received the pairing-time `0.0.0-dev`. A can finish processing B's hello while B is still processing A's welcome, so A's status is not a barrier for B's database write. This is test timing. Each side already awaits its [hello metadata write](https://github.com/itsoltech/canopy/blob/12a6346b262c50e2d8fbabfcb63689bffcf75822/apps/gateway/src/computers/runtime-frames.ts#L255-L267) before publishing its own [connected status](https://github.com/itsoltech/canopy/blob/12a6346b262c50e2d8fbabfcb63689bffcf75822/apps/gateway/src/computers/runtime-frames.ts#L316-L321). A [queues its welcome](https://github.com/itsoltech/canopy/blob/12a6346b262c50e2d8fbabfcb63689bffcf75822/apps/gateway/src/computers/runtime-frames.ts#L284-L288) before that status write; completion across the two independent gateways is asynchronous. Let the online helper wait for a specified peer/store, and wait for both sides before reading their final versions. Add a controlled barrier around B's metadata write and force the B → A dial after listener startup. The test now proves A can be connected while B still holds the old version, releases B, then waits for B's own connected commit. It retains the trust, protocol, version and upgraded-capability assertions. No sleeps, larger timeouts or assertion retries were added to hide the ordering. Evidence from the original failures: [attempt 1 / job 131276846769](https://github.com/itsoltech/canopy/actions/runs/43245418155/job/131276846769), [attempt 2 / job 131286358670](https://github.com/itsoltech/canopy/actions/runs/43245418155/job/131286358670), both at `linked-pairing-recovery.test.ts:267`. Validation on the authorized file only, sequentially with `TMPDIR=/var/tmp nice -n 19 bun run check:tmp`: - Complete file: **10 passed**, temp directory clean. - Forced-order scenario with `--rerun-each 10`: **10 passed**, temp directory clean. - Changed-file lint, formatting and `git diff --check` passed. Required CI validation: two complete consecutive green attempts for the same head, rerunning the entire workflow once after the first green result. This is pending; local repetition is not counted as CI evidence. Related: #573
The pairing suite could leave a deliberately persisted `pairing_required` untouched when restoring the original peer. Its shared fixture starts the runtime before the listener (`tests/integration/support/computers.ts:42`), so a startup dial races the listener's first address announcement. That announcement retires sockets and aborts dials (`apps/gateway/src/computers/runtime-lan.ts:51`). The suite's single reconnect tick can observe the closing incoming connection and skip dialing (`apps/gateway/src/computers/runtime-connection.ts:149`); its next automatic retry is deliberately 60 seconds away, beyond the 5-second assertion window. This is fixture timing. The #579 failure occurs in `restoreB()`, after the test intentionally sets `pairing_required`, not in shared setup or a previous test. The failed job shows two expected `server_pin_mismatch` probes followed by an aborted startup connection and no subsequent successful handshake. Self-heal writes `connected` only after a successful pinned handshake (`apps/gateway/src/computers/runtime-frames.ts:316–321`). There is no evidence here of that write being overwritten. Pause dialing during fixture startup until its listener and initial address publication have completed. Explicit ticks then establish links, and shared setup/recovery wait for each gateway's own committed connected status. Preserve the cross-version metadata barrier, remove its route-deletion workaround, and extend the persisted-state recovery case with a barrier holding listener startup open. Validation: - With the previous startup helper, the controlled barrier fails deterministically: expected zero startup dials, received one. - Five consecutive complete file runs with `TMPDIR=/var/tmp nice -n 19 bun run check:tmp ./tests/integration/linked-pairing-recovery.test.ts`: **10 passed, 0 failed each time** (50 test executions), each about 4.4 seconds; every temp-directory check passed. - Changed-file formatting, lint and `git diff --check` pass. No other local tests run. - Pending: two complete consecutive green CI attempts on the same head, rerunning the entire workflow once. Related: #573 Related: #575 Related: #579
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
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 persistedpairing_required, and on LAN it deleted the route. This behavior exists in the original linking implementation (feat(gateway): link computers with pinned mutual tls #13), before the reported release range.v0.2.0-nightly.120..v0.2.0-nightly.137and the.133→.137diff, including feat(threads): inherit access mode for subagents and bot threads #547, fix(updates): clear remote failures once the target is current #548, fix(computers): show connectors and schedules for remote threads #559, fix(computers): take thread locks in one order to avoid deadlocks #562, fix(gateway): isolate linked stream project identities #565, fix(computers): keep mirror controls on their original home #566 and fix(files): resolve and preview files from remote threads #546. The full desktop hello grew from 32 capabilities to 33 in fix(computers): show connectors and schedules for remote threads #559; both releases reject more than 32 asUnauthenticated: Invalid computer identityafter pinned TLS succeeds. Merged fix(computers): preserve legacy capability handshakes #574 fixes this capability overflow, including compatibility with the older validator. This branch is rebased onto that fix indev. Full source evidence: fix(computers): keep pairing across updates and restarts #573 (comment).computer_identity; the private key uses the existing encrypted secrets key. Desktop keeps the same Canopy data directory, database, app/keychain name andsecrets.encacross 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.Unavailable.manualmeans 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
CertificatePinMismatchsignal emitted only after TLS proof of possession and validation of a different self-signed certificate. Override ConnectError's inherited structuralSymbol.hasInstancecheck 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.pairing_requiredafter restart.Regression coverage
Added gateway↔gateway integration scenarios using independent databases and real TLS listeners:
Unauthenticatedon 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.Unavailablefor bothPairandConnectuntil ready..133hello without new capabilities links with a.137hello and resumes after upgrading.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
nice -n 19, usingTMPDIR=/var/tmpandbun run check:tmp:linked-pairing-recovery.test.ts10 pass,linked-capability-compatibility.test.ts3 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.git diff --checkis clean. Earlier dependency install and repository formatting/lint checks passed before the original push.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