Skip to content

feat(devices): pair phones and tablets over pinned TLS on the home network - #8336

Draft
rapuckett wants to merge 11 commits into
amd:mainfrom
rapuckett:upstream/pr2-device-pairing
Draft

rapuckett wants to merge 11 commits into
amd:mainfrom
rapuckett:upstream/pr2-device-pairing

Conversation

@rapuckett

Copy link
Copy Markdown

Summary

Lets a phone or tablet on the same Wi-Fi pair with GAIA and use a small, fixed set of routes over its own listener, with TLS pinned to the PC's certificate. Off by default.

Why

GAIA had no way to be used from a phone without sending traffic through an outside service. This adds the PC side: a second listener that only answers paired devices, pairing by QR code, Allow and Remove on the PC, and a deliberately small list of what a device may call. The feature is off until device_pairing is set in ~/.gaia/config.json, and nothing listens until the PC turns it on.

Linked issue

Refs #6385 (a phone that stays trusted across restarts and can be revoked). Depends on #8335.

Changes

  • Who a request is from comes from the listener it reached: requests on the device listener are the device whose token they carry, never the PC. The main listener decides who the PC is exactly as before.
  • A paired device may call only: pairing and unpairing itself, health and status, listing, reading and creating chats (plus the chat-list stream), sending a turn and its stream, stopping it, answering permission prompts and questions, and reading schedules and goals. Everything else is refused with 403 pc_only and stays available on the PC. The list is one file, src/gaia/ui/devices/routes.py.
  • Files: a device reads only files inside the folders its chat was given, through the same secret-file policy as the PC.

Test plan

  • python -m pytest tests/unit/chat/ui -q
  • python -m gaia.ui.export_route_access --check and python -m gaia.ui.export_openapi --check
  • With "device_pairing": true, start GAIA normally (python -m gaia.ui.server), turn on the listener, and from another machine call GET /api/health on the device port with a paired token (200), without one (401), and GET /api/providers/list with one (403 pc_only)
  • With device_pairing off: GET /api/devices/status answers 403

Evidence

  • Agent UI: N/A in this PR (Settings › Devices is PR 4).
  • MCP / CLI: N/A.
  • HTTP API: a device paired with a PC started the normal way gets 401 before Allow and 200 after; unlisted routes answer 403 pc_only.

A reply that ended because the model failed showed as failed only while it
streamed; reopen the chat and it looked like an ordinary answer. The saved
message now carries the same failed flag as the stream's done event, on
streamed, non-streamed and scheduled turns alike.
A phone paired on the home network reaches GAIA on its own listener, so the
server has to tell it apart from the PC and from mobile access. Requests on
that listener are the paired device whose token they carried, or nobody; on
the main listener the PC is decided exactly as before.

- principal() names the caller (pc, device:<id> or tunnel), and
  require_local_pc, is_local_pc and the device guards read it.
- refuse_on_device_listener keeps a route on the PC for paired devices.
- audit_approval records who approved a tool call, goal, schedule or folder.
- export_route_access writes each route's guard class for the phone app, so
  it can say "change this on your PC" instead of offering a control that
  would fail.
GAIA can now be used from a phone on the same Wi-Fi as the PC. The PC shows a
QR code; the phone scans it, pins the PC's certificate and waits until the PC
allows it. Each device has its own token, which the PC can revoke at any time.
Pairing is off until device_pairing is set in ~/.gaia/config.json.

- gaia.ui.devices: the single-use pairing window, the device table (tokens
  stored hashed), the owner-only key folder and certificate, and a second
  uvicorn listener whose device auth runs before the app.
- /api/devices: turn the listener on or off, open a pairing window, allow,
  unpair and reset from the PC; pair and unpair itself from the device.
- A paired device can't change what stays on the PC: mobile access, provider
  keys and connection settings, connector setup and grants, agent installs,
  logs and the troubleshooting report, the memory profile scan and admin,
  documents added by path or folder, and opening files on the PC's screen.
- Device pairings reach only the PC's own windows, and tool, goal, schedule
  and folder approvals are written to the audit log with who made them.
A phone browsing files, opening a preview or an image, or searching sees only
the folders the chat was given, never the rest of the PC's home folder, and
never a key, .env or credential file even inside those folders. Previews on a
phone are capped at 50 lines. Documents are added to the library on the PC; a
phone opens a cited document through file preview.

- Browse, preview, image and search take the chat's session_id on the device
  listener, and refuse a path outside its folders before touching the file.
- secret_read_refusal() is the one copy of the read policy the agent's read
  tools and these routes share.
Every backend started through `gaia.ui.server.main()` completed TLS with a
phone and then hung up without answering, so pairing failed on every real
install. main() injects truststore into `ssl`, which made the listener's
server context a truststore one; that context checks the peer's certificate
after each handshake, and a phone sends none. The test harness never injects
truststore, so it answered normally.

- The listener's server context is now a stock `ssl.SSLContext`, built
  through `gaia.tls.stock_ssl_context`, which the injection doesn't reach.
- The listener runs one in-memory handshake before it binds, so a context
  that can't serve fails the start and the status says so instead of
  reporting listening.
The device listener let an allowed device call about 210 of the backend's
routes, from mailbox sends to wiping memory. It now refuses every route it
doesn't list, so a route stays on the PC until a change opens it to devices
on purpose; each later feature widens the list for its own routes.

- DEVICE_ROUTES lists the phone's core: its own unpairing, health and
  status, chats and their messages, sending a turn and its stream, stopping
  it and answering its prompts, and reading schedules and tasks.
- The gate lets a request through only when every route that matches it is
  listed, so a listed template never opens a sibling such as
  /api/sessions/search. Anything else is a 403 with code pc_only.
- routeAccess.gen.ts marks every unlisted route not_on_listener, and the
  device API, the listener's security model and device_pairing are
  documented.
The phone's chat list stays current through the same session event stream
the PC's windows read; only the PC's own windows get the pairing and
security events on it.
DELETE /api/devices/me also matches DELETE /api/devices/{device_id}, which
only the PC may call, so the gate refused a device unpairing itself. A
sibling route that refuses devices with its own guard no longer blocks a
listed one; an unlisted sibling that would serve a device still does.
The pairing models and /api/devices routes were missing from
api.schemas.json and api.gen.ts, so the schema drift test failed.
@kovtcharov-amd kovtcharov-amd added this to the vFutures milestone Nov 17, 2026

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

agents cli CLI changes dependencies Dependency updates documentation Documentation changes security Security-sensitive changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants