Repository navigation
Let a remote agent ring the Mac to ask for the relay - #40
Merged
Merged
Conversation
A Linux box or cloud agent whose calls get 503 mac_offline had no way to ask for the relay: the Mac only dials the Worker while the relay is on. The Worker now takes a second, low-privilege Mac socket, the doorbell, authenticated with an HMAC of the relay secret so no new Worker secret is needed, and a POST /.keysrs/doorbell from the agent's own client token or pairing. Only SHA-256 hashes of those reach the Mac, one ring at a time and at most every ten seconds; the Mac's answer becomes the agent's status.
The Worker can now ring, but the Mac had nothing listening while the relay was off. Keysrs.app keeps the doorbell socket open from launch once the person turns it on (keys relay doorbell on, one Touch ID to derive the key), checks each ring's hash against live client tokens and pairings, answers away, pending or not_now without a prompt where nobody should be asked, and otherwise asks for Touch ID naming the token that rang before turning the relay on as keys relay on would. Setup re-derives the key; reset, purge and the kill switch turn the doorbell off and delete it.
Code review found that a ring's Touch ID prompt ran inside the lock that keys relay off and revoke --all take, so a prompt nobody answered left the kill switch hanging, and an approval that landed after the doorbell was turned off or the token revoked still turned the relay on. The prompt now runs outside that lock and both are checked again after it. Also: rings are spaced per caller address so a made-up token cannot lock out real agents, the Mac caps rings it handles, refusals that never showed a prompt no longer count against the hour, a doorbell loop that ended by itself reads as off, and a restart no longer races the old socket.
ThreadSanitizer on CI caught the doorbell test polling FakeRelayDialer's attempts while the loop under test appended to them under the dialer's lock; the read now takes the same lock.
The full suite pins which commands may launch the app and which read it gracefully; the doorbell verbs follow keys relay on/off and keys relay status, so they join those two sets.
Two RelayHostTests turned the relay off right after turning it on and then asserted the fake socket was closed. When the stop landed before the loop had dialed, there was no socket to close and the test failed on timing alone (seen on this PR's ThreadSanitizer runs and on main). Both now wait for the connection first.
A completed shutdown could be followed by a pending approval starting the relay. Serialize final validity and start with shutdown, invalidate outstanding approvals on off, and serialize credential revocation through the catalog transaction while keeping Touch ID outside the toggle lock. Workers retain pre-update hibernating sockets without doorbell tags. Discover and replace those legacy relay sockets by their attachment without treating doorbells as relays; cover both blockers with deterministic offline regressions.
This was referenced Nov 6, 2026
Merged
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 and why
Adds an opt-in relay doorbell so an agent whose relay is offline can ask the person at the Mac to turn it on. The Worker accepts a separate doorbell socket using a key derived from the relay secret, forwards only hashes of the ringer's client token or pairing, throttles rings, and maps the Mac's answer to an HTTP response. The Mac validates the live credential, screen state and prompt limits before asking for Touch ID naming the ringer. CLI on/off/status, app launch/lifecycle handling and API status are included; the local MCP still cannot turn the relay on.
Fixes the two confirmed blockers in the reviewed head:
{ connectedAt }attached. Discovery and reconnect replacement now recognize that legacy shape. Doorbells require their explicit kind, so relay and doorbell sockets neither count as nor replace one another.Merged current main
9ca4b392c35e47299d3c7f44efff52026716b8c6, including the other 11 reviewed PRs, before final verification. Fix commit:574121c; integrated head:9ab440feb9893c9a5c2840d2335cde2417b7eed5.How tested
Final runs on the integrated head, all synthetic/offline with
KEYS_TEST_ISOLATION=1andGROK_HOME,CODEX_HOME,KEYS_DROID_HOMEpointing at task temp directories:swift test --filter 'Gateway|Grant|Relay|Revoke|Share|Unwrap|HeldClientToken': 446 executed, 3 skipped, 0 failures; 82.64 s wall. Includes all 34 doorbell tests, including 8 new deterministic regressions for the original kill race, doorbell off/off-on, relay off, process shutdown, revoke-all, token revoke and pairing revoke. Shutdown callbacks run both during the prompt and at the former check/start boundary, without timing sleeps.swift test --sanitize=thread --filter 'Gateway|Grant|Relay|Revoke': 396 executed, 3 skipped, 0 failures, no race reports; 109.72 s wall.npm --prefix Relay test: 68 passed, including 2 new workerd regressions for legacy discovery and reconnect replacement with a doorbell present; 8.51 s wall. NoUncaught (in promise)failures. The existing workerd reader-canceled diagnostic appeared without failing the suite.swift build: passed; 3.47 s wall.git diff --check: passed.Before the fix, the original deterministic Swift reproducer failed both assertions (47.20 s including initial build):
Both Worker regressions also failed on the reviewed implementation (1.72 s): legacy discovery returned null, and reconnect left the legacy socket open. An initial test-fixture attempt returned a WebSocket through a non-upgrade test-runner request; the fixture was corrected to keep sockets inside the Durable Object callback before reproducing either production failure.
Full Swift suite and UI suites are left to CI on the exact pushed commit. Parent will independently review the final code/security diff and handle CI; this implementation run does not watch or wait for CI.
Risks
npm cireported 5 existing dependency advisories (2 moderate, 3 high); dependencies were not changed.What's left