Repository navigation
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
Conversation
…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]>
mstomar125
force-pushed
the
issue-4291-followup
branch
from
November 21, 2026 14:07
8541fd1 to
ef2e4be
Compare
This was referenced Nov 24, 2026
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.
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/agentfor this issue.What changed
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 concurrentDescribeToolApprovalpreview or a turn's offer could read the committed row at V and calllive(), andlive()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.landed()". Promotion after the commit leaves a residual race: a look that read the row at V before the commit and reaches the ledger afterlanded()still sees a mismatch and ends the record. The lower-version rule closes that race too and leaves the one-shot rule untouched.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 ofextendsedges can reach any tool.SqliteStore::update_node,update_node_with_version_checkandswitch_node_type_atomicnow 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.begin,as_own_write,reported_update,PendingApproval,forget,forget_scope,liveandrecordedare nowpub(crate), andforget_tagis private.NodeService::write_tool_approvalstays the only way to open a record, and the compiler enforces that.IssuedandMAX_RECORDSstay public:live_tool_approvalreturnsIssued. The database's scope name now has one definition,SqliteStore::approval_scope.process.rs; still a warning, never a refusal):#!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 Xat any level namesX;link_hops, at most 32 hops), as well as the path as written and as it resolves;user_presence::approval_reason):env:references, sorted. The rest are counted ("+N more"), as before;tool_approvals::forget_scopelogs 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) anduser_presence.What this changes in #4325's description
Known follow-ups from #4325 that this closes
All eight listed under "Known follow-ups from the last review" are closed:
begin,as_own_writeandreported_updateshould bepub(crate): closed (item 4);#!line: closed, and a relative interpreter is now replaceable too (item 5);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,
writtenin 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):landed();live_tool_approvalwhile the write is reported but not yet committed;writtenends a schema's whole database and only the node's own record otherwise;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):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,envat 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:
liveends on a lower version: the threelivetests above.emittedpasses no schema name: the service log test.#!read: the 512-byte test.writtentreats 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-asyncclean;bun run quality:fix(its workspace clippy included) clean with no changes, run again on the final tree.bun run test:changedwas run directly, with a scratchNODESPACE_HOMEand the shared target directory. It scoped itself to the rust and scripts tiers; the frontend and skill tiers were skipped as out of scope.test:scripts,types:checkandshape:checkall passed (no schema or seed changed).node-types:checkwas skipped: there is no docs checkout beside the worktree, and no node type changed.find_skills_schema_metadata_test.The targeted and mutation runs used nextest under the machine slot, with
CARGO_INCREMENTAL=0to keep the shared target's disk use flat. No real dialog was shown, and no real~/.nodespaceor keychain was used.Not merged; merging is the user's call.
🤖 Generated with Claude Code
Corrections after the independent review (APPROVE, nothing blocking):
SqliteStore::bulk_updateanddelete_nodes_by_ids_uncheckeddo not end a record. Neither has a production caller; they are tracked in a follow-up issue.