Repository navigation
Add fabricated-id guard: reject nodespace:// ids no tool result grounds - #2492
Conversation
…ds (closes #2281) E4B reported an invented nodespace:// id alongside real create_node calls — the existing anti-fabrication guards all key on zero tool calls or writes that persisted nothing, so a genuinely successful write narrated with a different, made-up id passed straight through. Any nodespace:// id in the final response is now checked against every id appearing in this turn's tool call args/results (recursively, covering search results, resolve_query, etc.); an id absent from that grounded set converts the response to the existing confirmation request. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0164eHb266SowSDBWtyaq3Gs
Code Review SummaryThis is a well-scoped, deterministic fix for issue #2281. The core mechanism — extract Net positive: this closes a real gap (the existing guards all keyed on zero-tool-calls or zero-persisted-fields; neither catches "tool ran, succeeded, model narrated the wrong id"), the regression test reproduces the exact #2281 reply verbatim, and the two acceptance-criteria bullets not addressed here (extending to claimed field writes, re-measuring the E4B rate) are explicitly and correctly called out as out-of-scope follow-up in the PR description — that is a legitimate scoping decision, not a missing implementation. One real (if narrow) gap is worth a conscious decision before or shortly after merge: grounding via tool call arguments, not just results, can be laundered. FindingsSuggested Improvements
Nitpicks
VerdictApprove as a net positive. The core fix is correct, well-tested, faithfully reproduces the reported bug as a regression test, and closes a real detection gap with a cheap, deterministic check. The args-laundering gap is real but narrow, doesn't regress anything, and is easy to tighten in a fast follow-up if the team wants to close it before or after merge — it does not block this PR. No security, architectural, or correctness blockers found. Standard project conventions (no lint suppression, no backward-compat scaffolding, inline-only doc comments, Bun-only tooling) are all followed. |
malibio
left a comment
There was a problem hiding this comment.
Pragmatic code review complete (see detailed comment above). Verdict: APPROVE as a net positive. Core fix is correct, well-tested (13/13 new tests pass, clippy clean), faithfully reproduces the #2281 scenario as a regression test, and closes a real detection gap the other three guards miss. One non-blocking Improvement flagged: grounding via tool call args (not just results) permits a narrow id-laundering path — a model could pass a fabricated id as an argument to an unrelated executing tool call to get it into the grounded set without any tool result ever confirming it. Recommend tightening to result-only or specific id-shaped arg keys as a fast follow-up. No security, architectural, or correctness blockers.
…kfile drift
Two review findings addressed:
- grounded_node_uris now scans only tool RESULTS, not arguments. Grounding
on args let a model launder a fabricated id by passing it as an argument
to any unrelated executing call (e.g. search_nodes({"query": "nodespace://
invented-id"})) — the call succeeds, the tool never validates the
argument, and the id would enter the grounded set unconfirmed. This
matches the issue's own stated invariant: ids come from a tool result or
they do not exist.
- Added grounded_node_uris_from_history, scanning session.messages' Role::Tool
entries (prior turns' serialized tool results, which format_tool_result
pushes into history verbatim and which do feed back into inference). Without
this, a response correctly recalling an id from an earlier turn — with no
tool call in the CURRENT turn — would have been flagged as fabricated, a
reachable false-positive the turn-scoped-only version didn't guard against.
- extract_node_uris' terminator set now also excludes `"`, since the guard
scans raw serialized JSON (session history) as well as prose; without it,
an id immediately followed by a JSON closing quote failed to match the
plain grounded string.
- Reverted an unrelated bun.lock lockfile-drift diff (configVersion field)
picked up from a different local Bun version during `bun install`.
Also addressed: PR comment noted the args-laundering gap could theoretically
worsen with the args removed if a legitimate `update_node(id: "nodespace://
abc")` pass-through relied on args grounding — verified this is a non-issue,
since every write tool (create_node, update_node) echoes the id back in its
RESULT too, so result-only grounding still covers that case.
Reviewer's other two nitpicks (test overlap between unit and loop-level
fabricated-id tests; collect_node_uris walking whole JSON trees rather than
specific keys) were left as-is — both are explicitly-documented, deliberate
tradeoffs favoring false-negatives-in-grounding over false-positives-in-
flagging, not defects.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0164eHb266SowSDBWtyaq3Gs
Addressed review feedbackFixed:
Not changed (both explicitly-documented, deliberate tradeoffs rather than defects, per the review's own framing):
Verification:
Pushed as |
Re-review: commit 52aaf57 → 219556fFocused on the diff addressing the prior review's two findings ( Verification performed
Finding 1 (args-laundering) — confirmed fixed, test verified non-trivial
Finding 2 (cross-turn scope) — confirmed fixed, test verified non-trivial
Item 1 — is scanning raw
|
malibio
left a comment
There was a problem hiding this comment.
Re-review of commit 219556f (fixes commit 52aaf57's review findings). Verdict: APPROVE.
Both prior findings verified fixed with non-trivial regression tests (confirmed each would fail/not-compile against the old code): (1) grounding now scans only exec.result, closing the args-laundering path; (2) grounded_node_uris_from_history correctly closes the cross-turn scope gap by scanning session.messages' Role::Tool entries.
Traced the new surface area end-to-end: the sole production writer of Role::Tool message content is format_tool_result (always serde_json::to_string(&result) or its error-wrapped form) — never args, never model-authored text. maybe_summarize_history correctly inserts its synthesized summary as Role::System, not Role::Tool, so summarization can't smuggle model prose into the grounding scan. No path pushes a synthetic Role::Tool entry in production. The new '"' regex exclusion is a pure false-negative fix (real ids are UUIDv4, never contain a quote) with no new false-negative introduced.
cargo test -p nodespace-agent --lib: 613 passed. Scoped to local_agent::agent_loop: 171 passed (matches PR description). Both new tests pass individually. cargo clippy -p nodespace-agent --all-targets -- -D warnings -D clippy::unused-async: clean. bun.lock revert confirmed clean against origin/main.
Two non-blocking nits posted in the detailed comment: (1) ungrounded_node_uris runs the full history scan unconditionally on every non-empty response, even when the response mentions no nodespace:// id at all — a cheap short-circuit (check extract_node_uris(text) first) would avoid wasted work on the common case; (2) a stale doc comment at the guard's call site still says ids come from a tool result '(or a prior turn's args)', which is inaccurate now that args grounding was removed. Neither blocks merge.
- Short-circuit the fabricated-id guard's grounding computation when the response contains no "nodespace://" substring at all — semantically identical (extract_node_uris already returns empty in that case), but skips the history/result scan entirely on the common path of a response that never mentions an id. - Fixed a stale doc comment on the guard that still said ids come from "a prior turn's args" — args grounding was removed in the previous commit; ids now come from a tool result, this turn or an earlier one. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0164eHb266SowSDBWtyaq3Gs
Addressed re-review nitsBoth non-blocking nits from the re-review addressed in
Pure cleanup, no logic change to the guard's behavior — no further re-review needed. Ready for merge pending final approval. |
Summary
nodespace://id (and claimed a field write that never ran) after two realcreate_nodecalls succeeded. The existing anti-fabrication guards (zero tool calls, no-op writes) don't catch this shape because a real tool did run and did succeed — the fabrication is purely in how the model described it.nodespace://<id>reference in the model's final response text is checked against the union of ids appearing anywhere in this turn's tool call arguments and results (recursively — coverscreate_node/update_node's top-levelid,search_nodes' nested results,resolve_query'sresolved/id, etc.). Any id not in that grounded set converts the response to the existingCONFIRMATION_REQUEST, the same mechanism the other guards already use.Test plan
ungrounded_node_uris_flags_id_no_tool_ever_produced/fabricated_id_guard_converts_a_response_naming_an_invented_id— regression test using the exact reply recorded in E4B reports a fabricated nodespace:// id and field writes that never ran #2281 (verbatim fabricated id, real tool id it should have used instead)fabricated_id_guard_leaves_a_response_naming_the_real_id_alone/fabricated_id_guard_does_not_fire_when_response_names_no_id— guard does not fire on grounded or id-free responsesextract_node_uris/grounded_node_uris/ungrounded_node_uris(dedup, markdown-delimiter/sentence-punctuation boundaries, nested JSON result shapes)cargo test -p nodespace-agent— full package, no regressionsbun run test:all— 233 frontend files / 4913 tests, 4 browser test files, full Rust workspace — all greenbun run quality:fix— clean (eslint, svelte-check, tsc, cargo fmt, cargo clippy -D warnings)🤖 Generated with Claude Code
https://claude.ai/code/session_0164eHb266SowSDBWtyaq3Gs