fix: treat same-computer companion reconnect as a hand-off, not a takeover#42
Merged
Merged
Conversation
…eover The companion registry identified connections solely by userId, so a forgotten 'zero browser connect' reconnecting from the same machine would evict the active session with the alarming 'another computer took over' message — and the two could ping-pong. Give each runner a stable ~/.zero/device-id, sent as x-zero-companion-device. When a new connection carries the same deviceId as the one it displaces, the server closes the old one as 'superseded' and the runner exits quietly without reconnecting. A genuinely different machine still gets the 'replaced' takeover warning. Older clients omit the header and are unaffected. Also drop the redundant helper text from the device-approval screen; the UI speaks for itself.
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
The companion registry identified connections solely by
userId, with last-writer-wins. A forgotten or backgroundedzero browser connectreconnecting from the same machine would evict the active session and print:…even though it was the same laptop. Worse, two such clients could ping-pong, each evicting the other. The server had no way to tell "this computer reconnecting" from "a different computer taking over."
Change
~/.zero/device-id(kept separate from auth config so it survives logout) and sends it as thex-zero-companion-deviceheader.deviceId, the server closes the old one as"superseded"and the runner exits quietly (↪ a newer zero browser connect on this computer took over…) without reconnecting."replaced"takeover warning.Files
server/lib/companion/registry.ts—register()takesdeviceId, branches same-device vs cross-device on evictionserver/lib/http/ws.ts— readsx-zero-companion-devicezero/src/sdk/config.ts—getOrCreateDeviceId()zero/src/companion/runner.ts— sends header, handlessupersededclose reasonweb/src/pages/DevicePage.tsx— drop explanatory textNot included (follow-ups)
Testing
tsc --noEmitclean for all touched files;bun build.tsrebuilds the CLI bundle. Not yet exercised against a live two-runner hand-off — recommend a manual end-to-end check of the close-reason flow before merge.