Repository navigation
Remote access, part three: control - #57
Merged
Merged
Conversation
…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
…n when a phone answers first
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.
…trol # Conflicts: # DECISIONLOG.md
This was referenced Nov 29, 2026
Draft
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.
Remote access, milestone M1 part three: control (Phase B, requirements C1–C10). A paired phone with a
controlgrant 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.mdand indocs/remote-protocol.schema.json.Choices for the app team
POST /v1/sessions/{id}/messages,POST /v1/sessions/{id}/abort,POST /v1/sessions/{id}/permissions/{pid},POST /v1/sessions/{id}/questions/{qid},GETandPUT /v1/sessions/{id}/config, andGET /v1/sessions/{id}/commands. Paths mirrorcodesmith serve's; errors are the{"error": {code, message}}shape (E1).{"turn": "<turn id>"}at once (C1); the id is the one the turn's events carry inturn. 409busywhile a turn runs or the last one is still stopping. Nothing is queued from a device in this part: onbusy, wait forsession_status {busy: false}and send again.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.client_id(S26) is taken now: optional, 1–64 ofA-Z a-z 0-9 - _ ., echoed in the turn'suser_message. A device's text reachesuser_messageexactly as sent (S25).attachmentsis 400bad_request(the body limit is 64 KiB; media comes with the media item later)./namerunsnamewhen it's a custom command, an MCP prompt (/server:prompt), a native command (/review…) or/compact;GET /v1/sessions/{id}/commandslists 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.{"aborted": true|false}. On an idle session it does nothing (unlike serve's abort, which also stops background commands). The stream getsdone {"error": "aborted"}when the turn is told to stop, andsession_status {busy: false}when the session really is idle (C10), from every owner, the TUI included.once,sessionorreject(with an optionalmessage, at most 4 KiB, for the model);alwaysis 400 (C2). A winning answer is 200{"ok": true}; a late one, or an id not open in that session, is 404not_found(E3).{"answers": [[...], ...]}(one list per prompt, in order) or{"dismiss": true}, as serve takes them. A wrong number of lists is 400.prompt_resolved.by.kindisterminal,device(with the device's name) or the newtimeout(whenremote.prompt_timeoutruns out; the reply is thenrejector null).permissionevents gainorigin(who started the asking turn, asturn_starthas it) and, foredit,writeandpatch,diff: a unified diff of at most 256 KiB, cut at a line with"diff_truncated": true(C6).questionevents gainorigintoo.GET /v1/sessions/{id}/configgives{agent, model, effort, pending, agents, models, efforts}; awatchdevice may read it.PUTtakes any ofagent,model,effort, answers with the same shape, and takes effect at the end of the running turn or at once when idle (C3);pendingshows a waiting change and aconfigevent comes when it lands. Effort values are the model's variants plusdefault.featuresinGET /v1/machinebecomes["watch", "control", "session_reply"]:controlfor abort, prompt answers and config;session_replyfor messages and slash commands.remote.prompt_timeout(default30m,0for 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.How it works
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 acontrolline to the owner holding the session. The gateway tells owners which sessions devices control (control_grants), for the timeout.remote/tap.rs, newrace.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_racinglet the owner's own prompt stop when a phone wins. Messages, abort and config go to the owner'sController.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,pendingconfig, no 30 s refusal when a phone may answer), ACP (device turns stream to the editor, the editor's request is withdrawn with$/cancel_requestwhen a phone wins).codesmith_core::selection;all_commandsand the "which slash command may a client run" lookup arecommand::all_with/command::invoked/command::listed, used by ACP, serve and the TUI.remote/diff.rsbuilds 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:
client_id), abort with C10, prompt answers (first wins, 404 after), config (C3) and slash commands (C4)originand diffs on prompts (C6),remote.prompt_timeout(C7), the TUI's 300 ms key guard (S10)remote/control_tests.rs), routes unit and property tests, serve/ACP/TUI owner tests, e2e (a_phone_drives_the_terminal_app)Follow-up to the app team's review (all 15 choices confirmed):
session_status) runs with it.remote.prompt_timeoutrejects withNobody answered within 30 minutes.(the configured time in words); a question times out as dismissed.unavailableon 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 504outcome_unknown.queuedis documented as reserved: nothing sends it yet.Checks:
cargo fmt --check, clippy (default and--no-default-features) clean;cargo test --workspace --no-fail-fast4819 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):
serve's own HTTP clients get only a minimalprompt_resolvedwhen a phone answers firstNext: the remote terminal (B2), push (C).