Skip to content

Ask the user when a write's ids do not resolve (closes #3808) - #3809

Merged
malibio merged 2 commits into
mainfrom
issue-3808-ask-unresolved-write-ids
Oct 14, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3808-ask-unresolved-write-ids

Conversation

@malibio

@malibio malibio commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

What

A write whose id resolves to no node ended the turn on the raw tool error. It now follows the same shape as the duplicate-entity and declined-work guards.

  • ToolError::UnresolvedId is a typed error the executor raises when a write tool gets OpsError::NotFound (no string matching).
  • The loop turns it into an unresolved_id refusal that tells the model to search and retry once, or route_clarify.
  • unresolved_id_backstop runs at turn end: if the refusal is unresolved, the model did not ask, and no write landed after it, the reply becomes a question offering the candidates a name search returned.

Tests

Unit tests for the typed error, the refusal, and the backstop (asks / model already asked / write landed after), plus a loop-level test that a corrected retry runs. nodespace-agent suite: 1156 passed.

Not done here: the in-process E4B run of question-blocks-task (needs a calm machine for the model).

🤖 Generated with Claude Code

@malibio

malibio commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type: Initial Review

Code Review Summary

Small, well-scoped change that follows the existing refusal + turn-end-backstop pattern (duplicate entity, declined work). The typed ToolError::UnresolvedId is a real improvement over string matching, and the backstop ordering and tests are sensible. Two correctness concerns (over-capture of NotFound, and a release condition that is broader than the sibling backstop's) are worth fixing before merge; neither is a security issue.

Requirements Check

  • Unresolvable id on a write produces a typed refusal the loop recognises (ToolError::UnresolvedId, unresolved_id_refused_result, is_unresolved_id_refusal).
  • A turn ending with the refusal unresolved asks the user (unresolved_id_backstop).
  • Unit tests: refusal, backstop (asks / model already asked / write landed after), loop-level corrected retry.
  • Verified in-process on locked E4B for question-blocks-task: pending (machine busy), not a defect.

Findings

🟡 Important: NotFound is over-captured by ops_error_to_tool

📁 packages/agent/src/local_agent/tools.rs:678-688 (with packages/core/src/ops/mod.rs:153)

OpsError::NotFound is not only "a node id did not resolve". NodeServiceError::CollectionNotFound(name) is mapped to OpsError::NotFound { id: name } (ops/mod.rs:153), and skill_ops emits NotFound { id: "skill \"<key>\"" }. For a write tool (e.g. create_node/update_node with a collection path), the new code turns a missing collection into UnresolvedId, so the model is told no node has the id "Projects/Foo" and to "search for the node by name", and the backstop would ask ""Projects/Foo" doesn't match any node". That is a wrong diagnosis and a misleading question.
Recommendation: make the signal precise at the source rather than inferring from a variant that several unrelated lookups share, e.g. map CollectionNotFound to its own OpsError variant (or ValidationFailed/InvalidParams) so only node lookups yield NotFound; add a test that a missing collection on a write stays ExecutionFailed. Principle: a typed signal is only valuable if its type means one thing.

🟡 Important: backstop release condition is broader than its sibling's

📁 packages/agent/src/local_agent/agent_loop.rs:1429-1434

unresolved_id_backstop returns early if any write landed after the refusal (after.iter().any(landed_write)). duplicate_entity_backstop documents exactly why that is too broad ("in 'add Northwind and Tailspin', the Tailspin create succeeding says nothing about Northwind ... 'Added both.' through unchallenged"). Same shape here: refused create_relationship to a placeholder, then an unrelated create_node lands, and the turn ends with a "Done" reply while the link was never made and the user is never asked. Tighten to a landed write of the same tool as the refused one (the corrected retry is the same tool with a real id), and add a test with an unrelated write after the refusal.

🟡 Important: only the last refusal is considered; first one can be silently dropped

📁 packages/agent/src/local_agent/agent_loop.rs:1420-1424
rposition finds the last refusal only. Two refused writes with different placeholders where the second is later resolved (or asked about) leave the first unreported. The sibling backstop notes the same limitation in its doc comment; add the same note, or evaluate every unreleased refusal.

🟢 Suggestion: delete_node behaviour change

📁 packages/agent/src/local_agent/tools.rs:6432-6439
delete_node of a missing id now becomes an UnresolvedId (a refusal that makes the backstop ask "Which node did you mean?"). For an already-deleted node (idempotent repeat, or a stale id after a confirmed delete) the better answer is "already gone", not a question. Consider excluding delete_node from the typed path, or at least pin the intended behaviour with a test.

🟢 Suggestion: model's own prose question is overwritten

📁 packages/agent/src/local_agent/agent_loop.rs:1429
The backstop only defers to result.clarify (set by route_clarify). If the model ends the turn with a plain-text question about the id, the reply is replaced with the template question. Verify this matches how declined_work_backstop treats prose questions; if that one has a "reply already asks" check, reuse it.

🟢 Suggestion: message wording for non-node ids / other callers

📁 packages/agent/src/agent_types.rs:43-52
#[error] text always says "no node has the id". Daemon/MCP paths just to_string() the error (no exhaustive ToolError matches found outside the agent crate, so nothing breaks), but they lose the original OpsError display. Fine once the CollectionNotFound issue above is fixed.

Nitpicks

  • Nit: agent_loop.rs search_candidates reads nodes or results; a comment naming which search tools emit which shape would prevent drift. Also UNRESOLVED_ID_MAX_CANDIDATES is declared after its use; move above for readability.
  • Nit: tools.rs test covers one write and one read tool only; a parametrised check over is_write tools plus the collection case would pin the boundary.

Tests

Good coverage of the happy and release paths; the loop-level test is a solid addition. Missing: unrelated write after refusal, missing collection on a write, two refusals, delete_node.

Recommendation: COMMENT (leaning REQUEST CHANGES on the two Important correctness items; no blockers on security/architecture)

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: COMMENT (self-authored PR; leaning request-changes on the two Important correctness findings: NotFound over-capture for collections, and over-broad backstop release). Full findings in the review comment above.

@malibio

malibio commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review (commit pushed):

  • Important: OpsError::CollectionNotFound added; a missing collection is no longer reported as an unresolved node id (daemon maps it to the same not_found status).
  • Important: backstop released only by a landed write of the refused tool; picks the last unreleased refusal. Tests added for unrelated write and earlier released refusal.
  • Nit: constant moved above its use.
  • Skipped: excluding delete_node (asking which node was meant is the right answer for a delete of an unknown id); prose-question handling matches declined_work_backstop.

Re-review needed: logic changed in the backstop and a new error variant was added.

@malibio

malibio commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type: Re-review (delta: e0579ec)

Summary

Both Important findings are addressed correctly and the new variant is cleanly threaded. No new blockers.

Prior findings

  • NotFound over-capture: Fixed at the source. NodeServiceError::CollectionNotFound now maps to OpsError::CollectionNotFound { name }, so ops_error_to_tool only types node lookups as UnresolvedId. A test pins a missing collection to ExecutionFailed. The daemon ops_error_to_status was updated to keep not_found; no other match site depended on collections arriving as NotFound.
  • Broad release condition: Fixed. A refusal is released only by a later landed write of the same tool, and the last unreleased refusal is chosen. Tests cover an unrelated write and a released earlier refusal.
  • Multiple refusals: Documented as a known single-question limitation. Accepted.
  • delete_node / prose question: Skip rationale accepted.
  • Nit (constant ordering): Done.

Remaining (all Nit)

  • Nit: test an_earlier_unreleased_refusal_is_still_asked_about actually exercises an earlier released refusal plus a later unreleased one; rename accordingly.
  • Nit: release is by tool name only, so a later landed create_relationship for a different pair releases an earlier refused one. Same granularity as the sibling backstop; acceptable.
  • Nit: get_node on a missing collection path now surfaces as a failed call rather than 'Node not found' text; harmless.

Requirements

E4B in-process verification remains pending by design, not a defect.

Verdict: APPROVE (no re-review needed)

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review verdict: APPROVE in substance (self-authored PR, posted as a comment). Both Important findings are fixed correctly; only optional nits remain. Details in the comment above.

malibio and others added 2 commits October 14, 2026 11:35
A write whose id resolves to no node now returns a typed UnresolvedId
refusal; the loop lets the model search and retry once, and a turn-end
backstop asks the user, offering name-search candidates, when it did not.

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

- OpsError::CollectionNotFound so a missing collection is not read as an
  unresolved node id (daemon maps it to the same not_found status)
- Backstop releases only on a landed write of the refused tool, and picks
  the last unreleased refusal
- Tests: unrelated write, earlier released refusal, collection not-found
- Skipped: excluding delete_node (asking which node was meant is sound for a
  delete of an unknown id); prose-question parity matches declined_work_backstop

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3808-ask-unresolved-write-ids branch from e0579ec to b3e5948 Compare October 14, 2026 09:35
@malibio
malibio merged commit 5e8e7e9 into main Oct 14, 2026
@malibio
malibio deleted the issue-3808-ask-unresolved-write-ids branch October 14, 2026 09:35
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