Skip to content

fix: remote-tool approval follow-ups: a racing look keeps a re-approval, merges and store writes end approvals under the guard, deeper pin warning, dialog order (#4291 follow-up) - #4331

Merged
mstomar125 merged 1 commit into
mainfrom
issue-4291-followup
Nov 21, 2026

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #4291. Follow-up to #4325 (remote-tool approval, merged): it fixes the low findings from that PR's final independent review. The user signed off the agent-lane work in packages/agent for this issue.

What changed

  1. A look that raced a re-approval no longer ends it (nodespace_core::tool_approvals::live). The node service reports the approval's write while its transaction is still open, so the record is live at the new version V+1 before the commit. A concurrent DescribeToolApproval preview or a turn's offer could read the committed row at V and call live(), and live() ended the record on any version mismatch. That threw away the person's confirmed re-approval of a tool that was still enabled ("written but not in effect"). Now a node at a lower version than the record leaves the record and does not count. A node at a higher version, or with another creation time, still ends it. This is safe because every write the node service reports after the approval's own already ends the record (the one-shot rule). So a lower stored version can only be a stale read, or a row put back behind the service's back, and neither can make a later write look like the approval's own.
    • I chose this over "promote the record to live in landed()". Promotion after the commit leaves a residual race: a look that read the row at V before the commit and reaches the ledger after landed() still sees a mismatch and ends the record. The lower-version rule closes that race too and leaves the one-shot rule untouched.
  2. A merge ends approvals under the write guard (NodeService::merge_nodes). The forget now runs inside the merge's transaction, so no approval can land between it and the raw-SQL rewrite. The node types are read in that transaction, and when either side is a schema, every approval of the database ends (the same schema rule as any other schema write). The merge's re-pointing of extends edges can reach any tool.
  3. Store-level updates end the approval as they write. SqliteStore::update_node, update_node_with_version_check and switch_node_type_atomic now end the record under the write guard, before the commit (or right after the single statement), using the same rule as the notifier. Before, a read-back error, a concurrent delete or a cancellation skipped the notification for a write that had already committed. The notifier still ends it as well.
  4. Visibility. begin, as_own_write, reported_update, PendingApproval, forget, forget_scope, live and recorded are now pub(crate), and forget_tag is private. NodeService::write_tool_approval stays the only way to open a record, and the compiler enforces that. Issued and MAX_RECORDS stay public: live_tool_approval returns Issued. The database's scope name now has one definition, SqliteStore::approval_scope.
  5. Replaceable-program warning (process.rs; still a warning, never a refusal):
    • the #! line is read to 512 bytes, as macOS reads it (was 256);
    • #! chains are followed up to 4 interpreters deep, so an interpreter that is itself a script is checked at every level, and a #!/usr/bin/env X at any level names X;
    • every symbolic-link hop is walked, wherever the link sits in the path (link_hops, at most 32 hops), as well as the path as written and as it resolves;
    • a relative interpreter is treated as replaceable, instead of being checked against the daemon's working folder.
  6. Dialog (user_presence::approval_reason):
    • the pin warnings now come right after the code and the name, before the program path or host. The reason reads: "approve code X for the remote tool “NAME” (WARNING: programs of this user can replace its program file) (WARNING: it starts X from the PATH, which is not pinned), which runs /path (that file's content is pinned), with the credentials …, then …";
    • a program path, or the method and host, longer than 160 characters keeps its first 48 and its last 111 around an ellipsis (U+2026). Node text cannot draw that character, because anything outside ASCII is shown as an escape. So the program's folder and file name, or the end of the host and its port, stay visible;
    • credentials are named in the daemon's order, not the node's: keychain references first, sorted by reference, then env: references, sorted. The rest are counted ("+N more"), as before;
    • cosmetic: for a URL the parser cannot read, the head now shows the text only up to where the rest begins, so the rest is not printed twice.
  7. Schema-write endings are logged. When a schema write ends records, tool_approvals::forget_scope logs at info the schema's name and how many approvals it ended. It logs nothing else about the database: no path. A write that ends none logs nothing.

Module docs were updated where they described the old behaviour: tool_approvals, process, tool_approval (the dialog order, the warning's reach, the unparsable-URL head) and user_presence.

What this changes in #4325's description

  • "A live record counts only while the stored node has exactly that version and creation time; a node that differs in either ends it": a node at a lower version now leaves the record, as described in item 1.
  • "a merge ends the record of the survivor and of the loser before it runs" now reads "inside its transaction, under the write guard". "(a merge of two schema nodes ends only the records of those two ids …)" no longer holds: a merge involving a schema ends every record of the database. The remaining narrow case, a bare property write on a schema node, is unchanged.
  • "the store-level updates whose notification can be skipped by a failed read-back or cancellation" no longer holds: those updates end the record before the read-back.
  • The dialog order is now: code, name, warnings, program or host (start and end when over 160 characters), credentials (keychain first, in the daemon's order), arguments.

Known follow-ups from #4325 that this closes

All eight listed under "Known follow-ups from the last review" are closed:

  • the record going live at buffer time, so a concurrent poll could end a re-approval: closed (item 1). The record still goes live when the write is reported, but a stale look no longer ends it;
  • a merge forgetting before it takes the write lock, and a schema merge ending only the two merged ids: closed (item 2);
  • store-level updates notifying after a read-back that can fail: closed (item 3);
  • begin, as_own_write and reported_update should be pub(crate): closed (item 4);
  • the replaceable-program warning not walking every symlink hop, checking one interpreter level and reading 256 bytes of the #! line: closed, and a relative interpreter is now replaceable too (item 5);
  • credentials beyond the fourth hidden in an order the node chooses: closed (item 6). The ones past the fourth are still counted, not named;
  • a very long program path pushing the warnings out of a shortened panel: closed (item 6);
  • any schema write silently ending every approval of its database: closed (item 7).

Still open, unchanged: the Stage 4, Stage 5 and ADR follow-ups listed in #4325.

Tests

Reproduce-first: the new and changed behaviour tests were written before the fixes, and all 13 failed on the unfixed code, each for the reason it targets. The read-back test was then reworked: the first trigger wrote invalid JSON, which the JSON expression indexes refuse at write time, so nothing landed. Its failure on the unfixed code is shown by M3u/M3v/M3s below: each one removes one path's new early forget, which is exactly the old code for that path. The two log tests cover new behaviour and were checked by mutation only. Existing tests were adjusted where the rule changed on purpose: the lower-version case, written in the schema unit test, the interpreter helper's new signature, and a 154-character path in the "not cut" case so it stays under the new 160 limit.

Each test was then mutation-checked alone: it fails under a mutation of the code it guards, and passes on the clean tree. That was 21 mutations in 4 batches, and none survived. Each batch combined mutations in independent places, and every failure in a batch was the expected one, with no spill-over:

  • tool_approvals (unit):
    • a look that read the node before the approval's write landed leaves it, both inside the write (between the report and the commit) and after landed();
    • through the real node service, a look between the approval's write and its commit leaves the approval. This test runs the update in a transaction inside the approval's mark, reads the committed row from another connection and calls live_tool_approval while the write is reported but not yet committed;
    • an approval that lands while a merge waits for the write guard is ended by the merge (the test holds the guard, lets the merge reach it, then makes both records live);
    • a lower version leaves the record, while a higher one or another creation time ends it (changed);
    • written ends a schema's whole database and only the node's own record otherwise;
    • a schema write logs schema=<name> ended=<n> once, and not the database path; one that ends nothing logs nothing; through the service, the created schema's name is the one logged.
  • tool_subtypes_test (integration, real store):
    • a merge of two schemas ends every approval of the database;
    • on each of the three store update paths, a write that lands but whose read-back fails ends the approval. An SQLite trigger leaves an unparsable modified_at, and the test checks the stored version moved on, so the write did land.
  • process (agent): a #! interpreter named past byte 256 is the one checked; an interpreter that is itself a script is followed, env at the second level is named, and a self-referencing script ends; a relative interpreter (#!python3, #!./bin/python3) is replaceable; a link in the middle of a chain, and a folder link in the middle of a path, are walked, while an unrelated link is not.
  • tool_approval (agent): an unparsable URL's head does not repeat the rest.
  • user_presence (daemon): the warnings come before the program path (exact reasons); a 400-character path keeps its start and end, has one ellipsis, fits 160 characters and leaves the credentials after it; a path at the limit is whole; an ellipsis in node text is escaped; credentials are named keychain first, sorted, then env.

Mutations, and the tests they failed:

  • M1 live ends on a lower version: the three live tests above.
  • M2a the merge's forget moved back before the transaction: the guard test.
  • M2b schema rule dropped in the merge: the two-schema merge test.
  • M2c the merge ends nothing: both merge tests and the guard test.
  • M3u / M3v / M3s each store path's early forget removed: the read-back test, at "update", "versioned update" and "type switch" respectively.
  • M4a / M4b logging with nothing ended, and no logging: the log tests.
  • M5 emitted passes no schema name: the service log test.
  • M6 256-byte #! read: the 512-byte test.
  • M7 one interpreter level: the chain test.
  • M8 relative interpreter not replaceable: the relative test.
  • M9 no link hops: the hop test.
  • M10 unbounded chain: the chain test timed out (a 60 s nextest limit was set for that batch).
  • M11 the URL repeats its rest: the URL test.
  • M12 warnings after the path: the two new dialog tests, plus three existing ones.
  • M13 path shown whole: the long-path test.
  • M14 no credential sort, and M15 sort by text only: the order test.
  • M16 written treats a schema like any node: the unit schema test, the integration schema test and the two-schema merge test.

I also checked one thing for information: the store notifier's own forget, which predates this PR, is still needed. Removing it fails the existing delete-path and direct-write tests.

Not covered by an automated test: how the real system panel lays out or shortens the new reason (no real dialog was shown), and whether this macOS would run an interpreter that is itself a script. The walk follows the chain either way, and it is a warning only.

Checks: cargo fmt; cargo clippy -p nodespace-core -p nodespace-agent -p nodespace-daemon -p nodespace-cli --all-targets -- -D warnings -D clippy::unused-async clean; bun run quality:fix (its workspace clippy included) clean with no changes, run again on the final tree.

bun run test:changed was run directly, with a scratch NODESPACE_HOME and the shared target directory. It scoped itself to the rust and scripts tiers; the frontend and skill tiers were skipped as out of scope.

  • skill installer script, test:scripts, types:check and shape:check all passed (no schema or seed changed).
  • node-types:check was skipped: there is no docs checkout beside the worktree, and no node type changed.
  • Workspace nextest: 6506 passed, 0 failed (122 skipped). As always it loads the embedding model in find_skills_schema_metadata_test.
  • App unit tests: 478 + 10 passed.

The targeted and mutation runs used nextest under the machine slot, with CARGO_INCREMENTAL=0 to keep the shared target's disk use flat. No real dialog was shown, and no real ~/.nodespace or keychain was used.

Not merged; merging is the user's call.

🤖 Generated with Claude Code

Corrections after the independent review (APPROVE, nothing blocking):

…al, merges and store writes end approvals under the guard, deeper pin warning, dialog order (#4291 follow-up)

- tool_approvals: a node read at an earlier version than the live record
  (a look that raced the approval's write) leaves the record and does not
  count; a later version or another creation time still ends it.
  begin, as_own_write, reported_update and the rest are pub(crate).
  A schema write logs at info how many approvals it ended.
- merge_nodes ends both approvals inside its transaction, under the write
  guard; a merge involving a schema ends every approval of the database.
- SqliteStore update paths end the approval before the read-back that
  notifies (update_node, update_node_with_version_check,
  switch_node_type_atomic).
- process: the #! line is read to 512 bytes, interpreters are followed up to
  4 deep, every symbolic link hop is walked, and a relative interpreter is
  replaceable (still a warning).
- Dialog: the pin warnings come right after the code and name; a program
  path or host over 160 characters keeps its start and end around an
  ellipsis; credentials are named keychain references first, sorted, then
  env; an unparsable URL no longer repeats its rest.

Co-Authored-By: Claude Opus 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