Skip to content

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

Merged
Vect0rM merged 12 commits into
mainfrom
change/add-server-account-remote-host
Nov 24, 2026
Merged

Vect0rM merged 12 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, 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.
  • On for everyone (ADR 2026-11-24-turn-accounts-on-for-everyone): account.enabled defaults to on and the commands are listed in help. Config version 8: migration 7 → 8 drops a stored account.enabled: false (config set saves the whole field table, so every file written since version 7 carries the old default; the commands were hidden, so nobody could have meant it) and keeps an explicit true. atc config set account.enabled false still turns accounts off.
  • A stop has the last word: stopping sharing drops the keys at once, then waits (at most 10 s) for a host round already in flight before ending the grants, and a round stops starting calls or writes once it is stopped. Before, a stopped round could still revoke a grant, or in a narrow window write and upload a device key after the stop (the CI flake in drops the keys here first). A stop that cannot reach the service for the current list also ends a grant it knew as both a stale request and a live grant only once: before, it denied it (409, then a revoke) and revoked it again, so the second revoke hid a failure of the first (90daf02).

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

  • main v0.2.20 merged in (6580774); main's rebuilt setup screens keep the atc login hint.
  • Core pin 0.24.8 (483ade1): resumable streamed chat completions, context compaction with automatic context windows, the engine repo rename. The TensorRT-LLM context_length default is now 0 (automatic); the engine-config contract test reads it from the core's schema.
  • npm run verify on macOS arm64 at 483ade1:
    • lint, typecheck, format and notices pass;
    • unit + contract: 3975 tests;
    • UI: 682 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.
  • The last CI run before the merge (a603dee) failed drops the keys here first on Linux and Windows ARM: the stopped-round race above, now fixed together with the double revoke (new host-round.test.ts and host-stop.test.ts cases fail on the old code). geniex-models also failed on Windows ARM there; it is not part of this change, and main's CI at v0.2.20 is green.
  • 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 8 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>
Conflicts:
- package.json, bun.lock: main's core pin 0.24.4 plus this branch's
  @hpke/* and uqr; the lockfile is main's plus `bun install`.
- docs/decisions/INDEX.md: both sides' records, in date order.
- src/daemon/daemon.ts, src/workspace-service/service.ts: both sides'
  options and stop calls. The daemon's opening comment is reflowed to
  stay within the 300-line limit.
- admin setup Purpose.tsx / SetupWizard.tsx: main's rebuilt onboarding,
  with this branch's "Share this server with your devices: atc login"
  hint re-applied to Destinations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stopping sharing aborted the host loop but did not wait for it. A round
already past its sync answer kept acting: it could revoke a grant the stop
was about to end (the CI flake in "drops the keys here first"), and in a
narrow window it could write and upload a device key after the stop had
dropped them.

- applySync takes the round's signal and starts no further call or write
  once it aborts; a key caught being written is not sent and is taken
  back.
- setSharing(false) still drops the keys at once, then waits (at most
  10 s) for the stopped round before ending the grants on the account
  service.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `account.enabled` defaults to on; `atc login`, `logout`, `account` and
  `atc remote ...` are listed in help.
- Config version 8: migration 7 -> 8 drops a stored `account.enabled:
  false`. `config set` saves the whole field table, so every file written
  since version 7 carries the old default, and the commands were hidden,
  so nobody could have meant it. An explicit `true` stays. Turning
  accounts off is still `atc config set account.enabled false`.
- docs/concepts.md and the generated docs/commands.md follow.

ADR 2026-11-24-turn-accounts-on-for-everyone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a request was allowed and keyed after the last sync, the list of
pending requests this server kept still named it, so a stop that could not
reach the service for the current list denied it (409 invalid_state, then
a revoke) and revoked it again as a live grant. The second revoke hid a
failure of the first, which is what still made "drops the keys here first"
flaky on macOS and Linux ARM CI after e85cb0d.

A grant this server holds a key for is live and is ended once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resumable streamed chat completions, context compaction with automatic
context windows, and the engine repo rename. The TensorRT-LLM
context_length default is now 0 (automatic); the engine config contract
test reads the default from the pinned core's schema instead of copying
it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vect0rM
Vect0rM merged commit 55ce9d9 into main Nov 24, 2026
9 checks passed
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