Skip to content

Sign the server in to an Atomic Chat account and share its API with the account's devices - #97

Open
Vect0rM wants to merge 7 commits into
mainfrom
change/add-server-account-remote-host
Open

Vect0rM wants to merge 7 commits into
mainfrom
change/add-server-account-remote-host

Conversation

@Vect0rM

@Vect0rM Vect0rM commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What

Atomic Server can sign in to an Atomic Chat account and share its OpenAI-compatible API with the devices of that account — the desktop app today (its client role is in AtomicBot-ai/Atomic-Chat#410), a phone later. This is the server side of accounts part 3 (remote access); the backend is already live on api.atomic.chat.

  • Sign-in without a browser on the server: an emailed one-time code, or a device code approved from any browser (Google works on the activate page). The session lives in the server process (account.json, 0600); signing in over a live session is refused, because it would end every device's access.
  • The server as a remote access host: a device pairs once — by typing the code, pasting the link / scanning the QR code, or by asking and being allowed here with a 6-digit check code. It gets its own key for /v1 (inference only) and a sealed copy of the server's current tunnel and LAN addresses, refreshed after restarts and tunnel URL changes. The backend never sees keys or addresses.
  • Keys: device keys live in remote-access.json (0600) and join the keyring through publicApiKeys only while sharing is on for the signed-in account; they never touch client-keys.json. Revoking is immediate.
  • Stopping sharing ends every device's access (ADR 2026-11-13-end-every-device-when-sharing-stops, superseding the "off pauses" part of the 2026-11-12 ADR): the keys go here first, then every request is denied and every approved or active grant revoked on the account service, so the desktop shows "access ended" instead of "Connected". The host record stays (no second "new computer" email); devices pair again. --forget also removes the server from the account's computers. Every client asks first while devices have access.
  • Disconnect notice: a key a sync drops because its grant ended elsewhere (the device disconnected, another device revoked it, it signed out) is listed in the snapshot's account.remote.ended for five minutes; the terminal says " disconnected from this server" once in its status line, the web admin shows a toast until dismissed. The person's own Revoke or stop lists nothing.
  • Everywhere: account.* workspace operations (all secret for agents), the snapshot's account, atc login | logout | account and atc remote share | add-device | devices | allow | deny | revoke (hidden from help for now), an Account section in the terminal UI and the web admin — as in the desktop app, a rail item above Help (the account's initial once signed in) with Overview (sign in, who, sign out) and Remote models (the share switch, Add a device, requests, devices with access); Server → Remote access keeps the tunnel and the LAN (ADR 2026-11-13-give-the-account-its-own-section) — an access-request notice, and an atc login hint at the end of setup.
  • Off by default: account.enabled (config version 7). Flip it in a later release once accounts ship in the desktop app.

Design notes

  • Crypto follows the backend README "Remote access API" and is tested against the backend's tests/remote_protocol.py vectors (the same ones the desktop uses). HPKE via hpke-js (@hpke/core 1.9.0, @hpke/dhkem-x25519 / @hpke/chacha20poly1305 1.8.0, @hpke/common held at 1.10.1); HMAC/HKDF/SHA-256 and the X25519 public key via node:crypto; QR codes via uqr 0.1.3. Versions are the newest at least two weeks old. The owner approved the dependencies; see ADR 2026-11-12-share-the-server-with-account-devices.
  • The core's PUT /server/client-keys is not used: the core ignores it when the embedder has a keyring, as atc does.
  • Without the web admin the CLI's in-process workspace refuses account.*, so there is never a second copy of the session.
  • ADRs: 2026-11-12-sign-in-to-an-atomic-chat-account, 2026-11-12-share-the-server-with-account-devices, 2026-11-13-give-the-account-its-own-section, 2026-11-13-end-every-device-when-sharing-stops.

Security review

An independent review ran before the first commit. Its findings are fixed and have regression tests:

  • A request gets a key only with a local allow record (grant, device and the key the check code covered). An approved that the backend reports by itself, a changed key, or an unknown method is denied.
  • Device keys count only for the account signed in now. Changes take effect in memory first, so a failed write never keeps a removed key working. Sharing can be turned off while signed out.
  • Logout goes through a fresh token and reports when the service did not confirm it. A refresh that lands after a sign-out is dropped.
  • Device-flow intervals and lifetimes are clamped, the activate page must be https, and names from other devices lose their control characters.
  • account.status is hidden from agents, because a waiting device code would let whoever approves it first own the server.

The same allow-record issue exists in the desktop host. Its fix is a separate change on AtomicBot-ai/Atomic-Chat#410.

Testing

  • npm run verify on macOS arm64:
    • lint, typecheck, format and notices pass;
    • unit + contract: 3918 tests;
    • UI: 675 tests;
    • build and build:bin succeed (Bun 1.4.4);
    • e2e: 73 tests (5 skipped);
    • e2e-web: 33 tests;
    • runtime-compat passes under vitest and bun test 1.4.4;
    • installers pass.
  • tui-editors-tools "URL refusal" can fail on a dev machine where the installed Atomic Chat app listens on port 1337 (the test's config v5 migrates to that port); it passed in this run and passes on main CI.
  • CI on this branch was red before these commits on Windows (owner-only 0600 mode asserted where Windows reports 0666) and on macOS/Windows (an ENOENT rename race when a remote-host test's temporary folder is removed under a pending write). Not fixed here yet.
  • test/contract/daemon-account.test.ts runs against a real core with the account service in memory. It goes through atc login → atc remote share on → a device asks → atc remote allow <check code>. The device key then gets 200 on /v1/models, and 401 after atc remote revoke. A third case: a device that disconnects on its side shows up in remote.ended; atc remote share off asks first, and with --yes revokes the remaining grant on the service, the key gets 401, and the host stays registered.
  • Clicked through the compiled binary against a local fake account service: sign-in, sharing, the Add a device QR dialog, Allow, and the request toast. The Account section was clicked through in the web admin (sign-in, Overview, Manage devices → Remote models, Server → Remote access, Settings without Account).
  • Not run yet: a real api.atomic.chat account with a real desktop client over a tunnel.

Follow-ups

🤖 Generated with Claude Code

Vect0rM and others added 4 commits November 13, 2026 12:25
…he account's devices

The server can sign in to an Atomic Chat account (email one-time code or
RFC 8628 device code) and act as a remote access host: devices of the same
account pair once (code, QR link, or "Allow" with a check code), get their
own key for the public API, and keep a sealed copy of the server's current
tunnel and LAN addresses through api.atomic.chat, which never sees either.

- src/account: session (single-flight refresh, no sign-in over a live one),
  sign-in flows, and the remote host (protocol checked against the backend's
  reference vectors, HPKE via hpke-js, host plan, long-poll loop).
- Device keys join the keyring through publicApiKeys only while sharing is on
  for the signed-in account; revoking is immediate.
- account.* workspace operations (all secret for agents), snapshot field,
  config account.enabled (version 7, off by default), hidden commands
  atc login|logout|account and atc remote share|add-device|devices|allow|deny|revoke.
- Hardened after a security review: a request gets a key only with a local
  allow record for its device and key, memory-first writes, logout through a
  fresh token, refresh races, clamped service numbers, cleaned device names.
- New dependencies @hpke/core, @hpke/dhkem-x25519, @hpke/chacha20poly1305 and
  uqr; ADRs 2026-11-12 sign-in and sharing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Settings -> Account signs the server in by an emailed code or a device code
and signs it out behind a warning. Server -> Remote access gets "Your devices":
the share switch, where devices can reach the server, Add a device (code,
link, QR code and countdown), requests with their check code and Allow/Deny,
and devices with Revoke. The status line announces a new request; the last
setup step points at atc login. Nothing shows while account.enabled is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Settings -> Account (email code, device code page in a new tab, sign-out),
the "Share with your devices" card on Server -> Remote access with the Add a
device dialog (lifted from the desktop app; the QR code is the server's SVG
shown as an image), an access-request toast that shares one stack with the
update notice, and the atc login hint on the last setup step. Hidden while
account.enabled is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A smoke run on a Mac with a VPN app published its tunnel interface
(198.18.0.1, the fake-IP range such apps use) as the first LAN address, so a
device would wait on a dead address before the real one. Loopback, link-local
(169.254/16, fe80::/10, which would also need this machine's zone id) and
198.18/15 are no longer offered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Vect0rM and others added 3 commits November 13, 2026 17:47
Account leaves Settings and becomes its own rail item above Help in the
terminal UI and the web admin, shown only while account.enabled, with the
account's initial once signed in. Its tabs come from ACCOUNT_SECTIONS:
Overview signs the server in and out, and Remote models holds sharing with
the account's devices (the switch, Add a device, requests, devices with
access), moved off Server -> Remote access. Remote models shows the sign-in
while nobody is signed in. Server -> Remote access keeps the tunnel and the
local network and ends with one line on how sharing stands. The access
request notice opens Account -> Remote models. Turning accounts off while
the page is open falls back to Server.

ADR 2026-11-13 "Give the account its own section, as the desktop app does".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nects

Turning sharing off used to pause it: the keys stopped working here, but
the grants stayed active on the account service, so the desktop kept
showing "Connected". Now off drops the keys, allowed requests and the
pairing code from the file first, then denies every pending request and
revokes every approved or active grant (from the service's own list when it
answers, else from what this server knew). The host record stays, so
sharing again sends no new "new computer" email; devices pair again.
--forget also removes the server from the account's computers. The CLI,
the terminal UI and the web admin ask first while devices have access.

A key a sync drops because its grant ended elsewhere (the device
disconnected, another device revoked it, it signed out) is listed in
snapshot account.remote.ended for five minutes, at most five. The terminal
says "<device> disconnected from this server" once in its status line; the
web admin shows a toast until dismissed.

ADR 2026-11-13 "End every device's access when sharing stops" supersedes
the "off pauses" part of ADR 2026-11-12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR CI failed on Windows and macOS:
- Windows has no POSIX modes, so the 0600 checks now run off Windows only
  (the data folder's owner-only ACL guards the files there).
- The host loop ran as a fire-and-forget promise: a failure after it gave up,
  such as a write into a test folder already removed, became an unhandled
  rejection. It now reports that failure like any other, and settled() lets
  a caller wait for the loop and the last write before the folder goes.
- The fake account service let a host deny an active grant; the service
  allows deny only on a pending or approved grant, and approve only on a
  pending one. A stop that raced the loop turned an active grant "denied".
- The disconnect test waited for the key to go, then read the notice written
  right after it; it now waits for the notice itself.

Six runs of the account tests under full CPU load pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant