← Back to DAGDA | Support | Source: https://github.com/reka18/codesmith/pull/57
Skip to content

Remote access, part three: control - #57

Merged
reka18 merged 11 commits into
mainfrom
feature/remote-m1-control
Nov 29, 2026
Merged

reka18 merged 11 commits into
mainfrom
feature/remote-m1-control

Conversation

@reka18

@reka18 reka18 commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Remote access, milestone M1 part three: control (Phase B, requirements C1–C10). A paired phone with a control grant can drive the sessions it may watch: send messages and slash commands, abort, answer permission requests and questions, and change the agent, model and effort. The remote terminal (Phase B2) and push (Phase C) are not in this PR.

The routes are written down first, in the new Control section of docs/remote-protocol.md and in docs/remote-protocol.schema.json.

Choices for the app team

  1. Routes. POST /v1/sessions/{id}/messages, POST /v1/sessions/{id}/abort, POST /v1/sessions/{id}/permissions/{pid}, POST /v1/sessions/{id}/questions/{qid}, GET and PUT /v1/sessions/{id}/config, and GET /v1/sessions/{id}/commands. Paths mirror codesmith serve's; errors are the {"error": {code, message}} shape (E1).
  2. A message answers 202 {"turn": "<turn id>"} at once (C1); the id is the one the turn's events carry in turn. 409 busy while a turn runs or the last one is still stopping. Nothing is queued from a device in this part: on busy, wait for session_status {busy: false} and send again.
  3. New error code closed (409) for a control route on a session no process holds (owner: "closed"). The machine doesn't open a session by itself for a device.
  4. client_id (S26) is taken now: optional, 1–64 of A-Z a-z 0-9 - _ ., echoed in the turn's user_message. A device's text reaches user_message exactly as sent (S25).
  5. No attachments yet: a message body with attachments is 400 bad_request (the body limit is 64 KiB; media comes with the media item later).
  6. Slash commands go through the messages route: a text starting /name runs name when it's a custom command, an MCP prompt (/server:prompt), a native command (/review …) or /compact; GET /v1/sessions/{id}/commands lists them as [{name, description}]. The terminal's own commands (/exit, /sessions, /mobile, /undo …) are never run from a device: such a text goes to the model as an ordinary message, as ACP does today.
  7. Abort answers 200 {"aborted": true|false}. On an idle session it does nothing (unlike serve's abort, which also stops background commands). The stream gets done {"error": "aborted"} when the turn is told to stop, and session_status {busy: false} when the session really is idle (C10), from every owner, the TUI included.
  8. Permission replies are once, session or reject (with an optional message, at most 4 KiB, for the model); always is 400 (C2). A winning answer is 200 {"ok": true}; a late one, or an id not open in that session, is 404 not_found (E3).
  9. Question replies are {"answers": [[...], ...]} (one list per prompt, in order) or {"dismiss": true}, as serve takes them. A wrong number of lists is 400.
  10. prompt_resolved.by.kind is terminal, device (with the device's name) or the new timeout (when remote.prompt_timeout runs out; the reply is then reject or null).
  11. permission events gain origin (who started the asking turn, as turn_start has it) and, for edit, write and patch, diff: a unified diff of at most 256 KiB, cut at a line with "diff_truncated": true (C6). question events gain origin too.
  12. GET /v1/sessions/{id}/config gives {agent, model, effort, pending, agents, models, efforts}; a watch device may read it. PUT takes any of agent, model, effort, answers with the same shape, and takes effect at the end of the running turn or at once when idle (C3); pending shows a waiting change and a config event comes when it lands. Effort values are the model's variants plus default.
  13. features in GET /v1/machine becomes ["watch", "control", "session_reply"]: control for abort, prompt answers and config; session_reply for messages and slash commands.
  14. remote.prompt_timeout (default 30m, 0 for ever) applies to sessions some device has a control grant on (C7), in every owner; elsewhere serve keeps its 30-second refusal of prompts no client sees.
  15. Never offered (C9): shell commands outside a turn, fork, delete, archive, the environment, and editing saved permission rules have no device routes.

How it works

  • Gateway (remote/routes.rs, gateway.rs, owners.rs): the control routes parse and check the body, re-read the device's grant just before forwarding (a revoke or narrowing that landed meanwhile wins), audit the action without content, and send a control line to the owner holding the session. The gateway tells owners which sessions devices control (control_grants), for the timeout.
  • Hub (remote/tap.rs, new race.rs): each open prompt has a race; a device's answer settles it in the hub (no owner code involved). Asker::ask_racing / Questioner::ask_racing let the owner's own prompt stop when a phone wins. Messages, abort and config go to the owner's Controller.
  • Owners: the TUI (tui/remote_host.rs: runs on the tab holding the session, 📱 From <device>, closes the dialog and guards keys for 300 ms), serve (device turns, idle abort does nothing, pending config, no 30 s refusal when a phone may answer), ACP (device turns stream to the editor, the editor's request is withdrawn with $/cancel_request when a phone wins).
  • Core moves (C3, C4): ACP's selection logic is now codesmith_core::selection; all_commands and the "which slash command may a client run" lookup are command::all_with / command::invoked / command::listed, used by ACP, serve and the TUI.
  • Diffs (C6): remote/diff.rs builds the unified diff from the running edit/write/patch call, reading only text files inside the session's folder and never one a secret guard covers.

Decisions

D41 (control through the owner), D42 (first answer wins), D43 (selection waits for the turn; logic in core), D44 (remote.prompt_timeout).

Done / Not done / Next

Done:

  • The protocol section and schema
  • Messages (202 + turn id, 409 busy, client_id), abort with C10, prompt answers (first wins, 404 after), config (C3) and slash commands (C4)
  • TUI, serve and ACP owners
  • origin and diffs on prompts (C6), remote.prompt_timeout (C7), the TUI's 300 ms key guard (S10)
  • Tests: loopback iroh (remote/control_tests.rs), routes unit and property tests, serve/ACP/TUI owner tests, e2e (a_phone_drives_the_terminal_app)
  • Docs, changelog, decision log

Follow-up to the app team's review (all 15 choices confirmed):

  • A pending config change is spelled out: made during a turn, it applies when that turn ends; the next message (after session_status) runs with it.
  • remote.prompt_timeout rejects with Nobody answered within 30 minutes. (the configured time in words); a question times out as dismissed.
  • 503 unavailable on control routes is now definite: requests carry a 10 s deadline the owner enforces (late commands are refused unrun; a late answer is refused under the race's lock, so it can never win), and the gateway waits 20 s past it. The one ambiguous case (owner took it in time, then went quiet or away) is the new 504 outcome_unknown.
  • queued is documented as reserved: nothing sends it yet.

Checks: cargo fmt --check, clippy (default and --no-default-features) clean; cargo test --workspace --no-fail-fast 4819 passed (default) and 4708 passed (--no-default-features), none failed; CI green on Linux x86_64, Linux arm64 and macOS arm64.

Not done (later parts):

  • Queue of device messages (409 for now), undo/redo, read state, diffs and media routes, background and jobs
  • Attachments on device messages
  • serve's own HTTP clients get only a minimal prompt_resolved when a phone answers first

Next: the remote terminal (B2), push (C).

@reka18 reka18 added the do not merge Not ready: wait until this label is removed label Nov 29, 2026
…swers, config

The gateway checks the grant again before forwarding, audits every action,
and tells owners which sessions devices control. Prompts race between the
terminal and phones; the first answer wins. Selection and slash-command
lookup move into core.
… shown as from the device, abort, config, and prompts a phone answers first close here
@reka18
reka18 marked this pull request as ready for review November 29, 2026 12:10
…e timeout's reason in words

A control request has a deadline at the process holding the session,
which never acts on one it takes later; a late prompt answer is refused
under the lock its race is settled under. The model is told
"Nobody answered within 30 minutes." Docs say exactly when a pending
config change applies, and that queued is reserved.
@reka18 reka18 added do not merge Not ready: wait until this label is removed and removed do not merge Not ready: wait until this label is removed labels Nov 29, 2026
@reka18
reka18 merged commit eb9073a into main Nov 29, 2026
3 checks passed
@reka18
reka18 deleted the feature/remote-m1-control branch November 29, 2026 13:26
This was referenced Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Not ready: wait until this label is removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant