Skip to content

feat(daemon): remote-tool confirmer, pending map, answer RPC; not installed (#4291, 2/3) - #4320

Merged
mstomar125 merged 3 commits into
mainfrom
issue-4291-confirm-daemon
Nov 20, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-4291-confirm-daemon

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part 2 of 3 of the remote-tool confirmation wiring (#4291; user ruling 2026-11-20: the confirmation is an in-chat card; design note in the PR 1 description). Builds on #4318 (merged). It is inert: the confirmer is not installed on any turn, so every remote tool whose calls need confirmation is still not offered. PR 3 adds the card (a ConfirmationUi) and installs the confirmer on interactive turns.

Agent lane. This touches packages/agent (Michael's lane) and the daemon. The user's sign-off for the #4291 remote-tool build stands in for Michael's.

What it adds

packages/daemon/src/services/remote_confirmation.rs:

  • PendingConfirmations: the table of questions waiting for an answer, per database. Entry = chat, turn, stored digest, one-shot sender.
  • DaemonCallConfirmer (a CallConfirmer): per question a random id (two OS-random UUIDv4s, 64 hex characters, never reused) -> entry inserted -> ConfirmationUi::present -> wait for the answer, a 120 s timeout, the turn's cancel token or the database shutdown. Anything but an explicit yes is no.
  • Answers (answer): accepted only for the exact request id + chat + digest. The digest is compared with the STORED digest of the live request, never recomputed from client parts, and is mandatory (a no needs it too). Unknown / late / duplicate / foreign-chat / wrong-digest answers are refused and leave a pending question pending (a stray answer cannot cancel it). The first valid answer removes the entry and delivers the answer under one lock, so it is single use.
  • No late yes: a timeout, cancel, shutdown or dropped future removes the entry BEFORE anything else (a drop guard covers the dropped future); an answer that was accepted in the same instant stands (tested 40 times against a simultaneous cancel).
  • At most 4 questions waiting per chat; more is a no without being shown. Several calls in one round each get their own id; the same call asked twice gets two ids; a yes for one cannot cover another. A request with no digest is not asked.
  • clear_turn drops a turn's questions when it ends.
  • The AnswerConfirmation(node_id, request_id, digest, allow) gRPC RPC (proto + handler) returns only accepted; every refusal looks the same.
  • LocalAgentServiceImpl::confirmer_for_turn: None for a non-interactive (scheduled / headless) turn and when no card is installed; not called yet.

The answer channel (requirement (c)): the peer gate, after review

The RPC is on the daemon's same-user socket, and a program the daemon starts for a tool is the same user, so the handler judges the peer BEFORE it routes or reads the request (a refused peer sees the same answer whatever database header it sent).

How it decides (nodespace_agent::spawned, SpawnedProcessGate). The daemon RECORDS the pid of every program it starts for a tool: through the shared spawn_isolated (tool-cli, MCP stdio servers, the ACP engine) and the PTY session spawn. The peer is refused when its process GROUP is a recorded group (a background process, an orphan whose parent has exited, and a grandchild all keep the group), when it is a recorded pid (start time compared, so a reused pid is not mistaken for it), or when a recorded program is among its ancestors. Also refused: the daemon itself, pid 0 (another pid namespace), pid 1, and any peer whose own identity cannot be read. A program the daemon started that is NOT recorded passes (the tray's "Open NodeSpace" starts the app as the daemon's child, so the genuine UI is not refused on that path any more). Groups are forgotten when empty, pids when dead or reused.

Launch paths of the genuine UI: installed app (Finder / Dock): passes. bun run dev:tauri: passes. The app started by the tray: passes (not recorded). CLI and headless runs: there is no answer command. Windows: the named-pipe transport carries no peer pid, so every answer is refused by design (inert there until solved). Linux with /proc hidden (hidepid): peers are unreadable, refused.

Known limits, stated plainly. A recorded program that leaves its group (setpgid / setsid) AND whose parent has exited is indistinguishable from any other program of the same user. The fix is the peer's audit token (macOS LOCAL_PEERTOKEN) with a code-signature check against the NodeSpace team id (SecCodeCheckValidity); a debug or unsigned build would need an opt-out. That is planned as a follow-up to PR 3 (not done here). The peer pid is captured when it connects and judged on each request; a connector that has died reads as unknown and is refused. Once the card's request id and digest are stored in the chat node (PR 3), any same-user tool can read them with nodespace get: the id is NOT a secret from tools, the peer gate is the only barrier (a PR 3 acceptance criterion).

Also fixed in this round: pid 0 is refused (<= 1); confirm() races the card's write against the cancel token, shutdown and the timeout (a hung card write cannot hold a turn past its cancellation), and a dropped question ends its card as cancelled; tests with real processes: a recorded program, its grandchild and its orphan after the parent exits are refused; this process and an unrecorded child may answer; the daemon, pid 0, pid 1, no pid and a dead peer are refused; a UDS test drives the real tonic path (peer pid from UdsConnectInfo -> gate -> handler), with and without a database header.

Folded in from the #4318 review

Digest is length-prefixed (SHA-256 over len(text) as u64 BE, text, arguments) with a boundary test (("a","b\0c") vs ("a\0b","c")); a serialisation error refuses the call instead of defaulting; boundary test: arguments of exactly 16384 bytes are asked, 16385 refused; a pinned run following a same-origin 302 asks the resolver nothing more; a pin the address policy blocks (0.0.0.0 for localhost) is refused even though it is reachable; is_unsafe_for_log also covers U+E0100-E01EF and U+180B-180F.

PR 3 acceptance criteria (written down here as asked)

The card shows ONLY arguments_json and the summary; it must escape or visualise bidi, zero-width, line/paragraph-separator, tag, variation-selector and other invisible characters in BOTH the summary (destination) and arguments_json through one shared display-safe function (the is_unsafe_for_log set is currently used only for the whitelist warning log); the credential line is a separate structured field, never parsed from text; the answer carries the digest the daemon sent; other devices see a pending card read-only.

Tests and mutants

20 tests in the module (fake UI) plus 3 in the service. Mutants (26 across the two rounds, each killed by a named test or by hanging the test; the one equivalent mutant was pinned by a new unit assertion): digest comparison, empty digest (now doubly guarded), chat comparison, timeout treated as yes, per-chat cap, answer not single use, gate lets the daemon tree through, gate lets unknown peers through, short id, clear_turn too wide, a card that cannot be shown ignored, an accepted answer dropped in a race, interactive check removed, gate skipped in the handler. a_built_in_tools_result_is_unchanged in agent_loop is a pre-existing flake under cargo test.

🤖 Generated with Claude Code

mstomar125 and others added 3 commits November 20, 2026 10:53
… routing, card write raced against cancel

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-4291-confirm-daemon branch from 864fa27 to ca0710c Compare November 20, 2026 09:53
@mstomar125
mstomar125 merged commit 13eb41e into main Nov 20, 2026
@mstomar125
mstomar125 deleted the issue-4291-confirm-daemon branch November 20, 2026 09:53
mstomar125 added a commit that referenced this pull request Nov 20, 2026
…onfirmer, frontend card (local, not pushed)

Remaining: rebase onto the fixed #4320 head and then origin/main; run quality:fix, shape/types/node-types checks, test:changed; mutation batch; PR body.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
mstomar125 added a commit that referenced this pull request Nov 20, 2026
…tive turns (#4291, 3/3) (#4321)

* WIP: confirmation card: schema, chat card UI impl, interactive-only confirmer, frontend card (local, not pushed)

Remaining: rebase onto the fixed #4320 head and then origin/main; run quality:fix, shape/types/node-types checks, test:changed; mutation batch; PR body.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* feat(agent): record tool programs by group, hardening, card tests (#4291)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(frontend): card lint and focus rules (#4291)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix: card review round (credential check, delay, foreign cards, forged cards, restart cancel, shared vectors)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* test: card timing tests use fake timers

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* test: kill the delay and focus mutants with fake timers; refuse message subtypes

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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