Skip to content

Route completion-state updates to Graph Editing; keep route_clarify on Stage 2 (closes #2912) - #3051

Merged
malibio merged 2 commits into
mainfrom
issue-2912-stage2-clarify
Sep 25, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2912-stage2-clarify

Conversation

@malibio

@malibio malibio commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Closes #2912.

Problem

"The incident Rowan was on call for — mark it resolved" retrieved Conflict Resolution first, on the shared word "resolve". None of the top-3 skills whitelisted update_node, so Stage 2 had no write tool. The model found the incident and then gave up in prose.

What changed

1. Retrieval (the fix). Graph Editing's description now names the completion states users actually say ("mark it resolved, done, closed, paid…", "the invoice is paid, the ticket is closed").

Measured with the locked nomic embedding model over the real seeded registry:

Query Before (Graph Editing rank) After
The incident Rowan was on call for — mark it resolved 6 2
mark the incident as resolved 4 2
mark incident resolved 5 2
set the incident's resolved field to true 4 2
mark the invoice as paid 3 1
close out the support ticket 3 1
mark the outage report done 6 1

Top-3 is what matters here: update_node isn't destructive, so Stage 2 offers it from any eligible candidate. Controls: conflict-journal requests still route to Conflict Resolution at rank 1, and all 6 existing retrieval tests in the file still pass.

New live tests (#[ignore]d, need the embedding GGUF) in tests/live_skill_retrieval_stability.rs:

  • completion_state_updates_route_graph_editing
  • control_conflict_requests_still_route_conflict_resolution

2. Stage-2 clarify surface. route_clarify now stays on every scoped Stage-2 surface even when no matched skill whitelists it (ADR-038's Stage-2 "or clarify" branch, previously unwired). It is withheld once the intent has already clarified, the same once-per-intent rule Stage 1 follows. Its description now also covers "none of the offered procedures can do what was asked". Covered by two agent-loop tests.

What was measured and not shipped

A candidate-block instruction ("judge each procedure by what it does; if none fits, call route_clarify") was A/B tested on gemma-4-e4b against the old wording, using the real Conflict Resolution, Relationship Management and Node Merge candidates and the real tool definitions. 0/15 clarified on the new arm, identical to the old arm at every step: the first action, after a successful get_related_nodes, after a successful search_nodes, and after both. The model keeps reading and never notices it has no write tool. The wording was reverted, and a code comment records the result. The in-code backstop for this class of failure is filed as #3047.

Notes

  • Seeded skill descriptions only reach an existing database on reseed, so reset the DB to pick up the new description.
  • Pushed with --no-verify (approved by the author): the gate failed on nodespace-core's rollover_moves_a_task_rather_than_leaving_it_in_both_cycles, a crate this branch doesn't touch. That test fails every time between local midnight and 02:00 CEST, when the local date differs from the UTC date. Agent crate tests, clippy and quality:fix all pass.

🤖 Generated with Claude Code

…y on Stage 2 (closes #2912)

"Mark it resolved" retrieved Conflict Resolution on the shared word
"resolve" and left no write tool on Stage 2's surface. Graph Editing's
description now names the completion states users say; it enters the
top-3 for 7/7 such requests (was 2/7) while conflict-journal requests
still route to Conflict Resolution first. Guarded by two new live
retrieval tests.

route_clarify now stays on every scoped Stage-2 surface (ADR-038's
Stage-2 clarify branch), withheld once the intent already clarified.
A matching candidate-block instruction was measured inert on E4B (0/15
clarified at every step) and is not shipped; the deterministic backstop
is filed as #3047.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3051

Review Type: Initial Review
Recommendation: APPROVE (posted as a comment, since GitHub blocks self-approval)

Summary

This is a net-positive change that stays tightly scoped. The specific failure ("mark it resolved" → Conflict Resolution → no write tool) is fixed where it happens, in retrieval, and the fix is backed by measurement (Graph Editing reaches the top-3 in 7/7 cases, up from 2/7) and by a control in the other direction. ADR-038's Stage-2 clarify branch is now wired with a small, pure helper. The negative prompt-wording result is written down instead of shipped. I verified locally that cargo test -p nodespace-agent passes: 693 lib tests plus all integration binaries, including the 3 new unit tests. I did not run the #[ignore]d live retrieval tests (they need the GGUF).

Requirements Check

  • ✅ Reported failure fixed. Graph Editing now reaches the top-3 for the incident request and 6 sibling phrasings. Because update_node isn't destructive, top-3 placement is enough for it to reach Stage 2. The reasoning is correct: stage2_permitted_names restricts only removes_user_data_tool to the top candidate.
  • ✅ Issue's proposed shape (Stage-2 clarify/bail path). The surface is wired and follows the once-per-intent rule, with tests for both branches. The PR says openly that E4B does not use the path unprompted (0/15). A deterministic backstop is filed separately (Stage 2: deterministic clarify backstop when no offered tool can write and the turn gives up in prose #3047) instead of being mixed into this PR. Given the measurement, this is a sound resolution.
  • ✅ Repo conventions. No lint suppression, no backward-compat code, no issue numbers in code comments. The "reset the DB to pick up the new description" note matches the no-migration rule.

Code Review Findings

🟡 Important

1. No deletion control for the broadened Graph Editing vocabulary
📁 packages/agent/src/skill_pipeline.rs:527, packages/agent/tests/live_skill_retrieval_stability.rs:460-486

  • Issue: The new description names "resolved, done, closed, paid, complete". Those are exactly the qualifiers users put on deletion requests: "delete the resolved incidents", "remove the closed tickets", "get rid of the paid invoices". Destructive tools are the one place where rank 1, not top-3, decides the outcome. delete_node is admitted only from the top tool-bearing candidate. If Graph Editing now outranks Node Deletion on such a request, delete_node is withheld silently. The only log line is the info! "withheld" message, and the user sees an agent that "declined" to delete. The new control covers Conflict Resolution only, and the existing controls cover Schema Creation, Relationship Management, Node Creation and Organization. None of them covers Node Deletion.
  • Recommendation: Add a rank-1 control to control_conflict_requests_still_route_conflict_resolution, or a sibling test, using routing_misses(..., "Node Deletion", true) over 2–3 deletion requests that carry a completion-state word. If one fails, narrow the Graph Editing wording before merging. This is cheap to run with the harness the PR already adds.
  • Principle: A vocabulary change in a shared embedding space moves every neighbour, and a control only proves the direction it tests. Here the untested direction is the one guarding the destructive trust boundary.

🟢 Suggestions

2. Once-per-intent applies only to the added clarify, but the comment says it matches Stage 1
📁 packages/agent/src/local_agent/agent_loop.rs:1960-1967

  • Issue: The gate only stops with_stage2_clarify from adding route_clarify. The tool stays on the surface after an answered clarification in two cases: when a candidate whitelists it (Node Creation and Graph Editing both do), and on the fail-open surface (fail_open_surface keeps it). So on the exact path this PR targets, a second clarification within one intent is still possible whenever Graph Editing is retrieved. That may be intended, since a Stage-2 "which record?" after resolve_query returns multiple_matches is a different question. But the comment says "the contract Stage 1 enforces applies here too", which overstates what the code does.
  • Recommendation: Pick one of the two. (a) Enforce it uniformly: if session_already_clarified(session) { tools.retain(|t| t.name != ROUTE_CLARIFY_TOOL) } else { tools = with_stage2_clarify(...) }. (b) Reword the comment to say the rule covers only the "none fits" clarify this branch adds, and that record disambiguation from whitelisting skills stays available.
  • Principle: Comments should describe the invariant the code actually holds (least surprise). A future reader will assume the contract is global.

3. The new route_clarify wording names something the prompt may not contain
📁 packages/agent/src/local_agent/tools.rs:1810-1815

  • Issue: "none of the procedures offered for this request" refers to the REFERENCE candidate block. That block is absent on fail-open turns (retrieval found nothing) and on every turn for a model probed routing_disabled, but route_clarify is still on those surfaces with the same description. This is the "guidance naming a structure that isn't in the prompt" failure mode seen before. It's low-impact here because the tool is rarely picked, but it's free to avoid.
  • Recommendation: Use wording that stands on its own without the block, such as "or none of the available tools can do what was asked". That also matches the real failure better: the model had no write tool, not a missing procedure.
  • Principle: Every input a prompt names should exist on every path where the prompt is rendered.

4. Every Stage-2 surface now carries route_clarify, and nothing measures over-clarification
📁 packages/agent/src/local_agent/agent_loop.rs:1965

Nits

  • Nit: live_skill_retrieval_stability.rs:405-408: routing_misses runs an extra un-repeated find_skills per query just for the eprintln! diagnostics. That's fine for an ignored live test. Consider printing only on a miss so passing runs stay quiet.
  • Nit: skill_pipeline.rs:517-526: the comment cites the 5-of-7 measurement and the guarding test names, which is good. Consider also naming the control test, since that's what shows the widening didn't just move the false positive.

What's Done Well

  • The fix targets the root cause (retrieval), and a measured-inert prompt tweak was not shipped. The comment in render_candidates_for_prompt recording the 0/15 result keeps anyone from re-trying the same wording.
  • with_stage2_clarify is pure, idempotent, won't invent a definition the registry lacks, and is covered by one focused unit test.
  • Insertion order is correct. It runs after stage2_tools and before declare_write_tool_fields, the live-status rewrite and the tools_with_available_guidance retain. route_clarify isn't requires_routed_guidance, so the retain never drops it. It's non-destructive, so it doesn't interact with destructive gating. The existing Stage-2 interception already handles a batched write alongside it.
  • The two agent-loop tests fail on the pre-change code in both directions: the "offer" test fails without the add, and the "withhold" test fails without the gate.
  • The options description ("Empty when the question is not a choice between records") matches the parser and format_clarification, which both accept empty options.

@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: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

…ify wording

- Narrow Graph Editing's description: the 'closed/paid' noun phrasing
  outranked Node Deletion on 'remove the closed tickets' and 'get rid of
  the paid invoices', silently withholding delete_node. 'Keep it / stay'
  holds both on Node Deletion while completion requests stay 7/7 top-3.
- Add control_deletion_requests_are_not_outranked_by_graph_editing.
- route_clarify description: 'none of the available tools' instead of
  naming a candidate block that is absent on fail-open/routing-disabled turns.
- Correct the Stage-2 clarify comment: the once-per-intent skip covers only
  the added route_clarify, not skills that whitelist it.

Skipped: measuring over-clarification on ordinary turns (belongs with the
backstop issue's matrix run); printing rankings only on a miss (the file's
other tests always print them).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (9662ba8)

✅ 🟡 1: No test checked that deletion requests still go to Node Deletion. The finding was real. The first description ("the invoice is paid, the ticket is closed") put Graph Editing above Node Deletion on "remove the closed tickets" and "get rid of the paid invoices", which would have silently withheld delete_node. On main, Node Deletion was first on both.

  • Narrowed the description to: "Update a record that already exists and keep it: mark it resolved, done, or paid… Use when the user wants an existing item to stay but move to a new state." Node Deletion is back ahead of Graph Editing on all three deletion requests, and all 7 completion requests stay in the top 3.
  • Added control_deletion_requests_are_not_outranked_by_graph_editing. All 9 live retrieval tests pass.
  • Pre-existing, not changed here: "delete the resolved incidents" ranks Conflict Resolution above Node Deletion. It already did on main, on the shared word "resolve", regardless of Graph Editing. The test's doc comment records this.

✅ 🟢 2: The comment claimed more than the code enforces. Reworded. The once-per-intent skip only governs the added route_clarify. Skills that whitelist it themselves, and the fail-open surface, still offer it.

✅ 🟢 3: The route_clarify wording referred to a candidate block that isn't always in the prompt. It now says "none of the available tools can do what was asked".

✅ Nit: the skill_pipeline comment now names all three guarding tests, and records why the wording is kept narrow.

⏭️ 🟢 4: Measure over-clarification on ordinary turns. Skipped here. It needs a matrix run, which fits with #3047's backstop work.

⏭️ Nit: print rankings only on a miss. Skipped. The file's other live tests always print their rankings, and the scores are the useful diagnostic.

Tests: cargo test -p nodespace-agent passes, clippy is clean, and the live retrieval suite passes 9/9. Pushed with --no-verify (approved by the author) because of the unrelated nodespace-core rollover test, which fails between local midnight and 02:00 CEST. A fix for it is in progress separately.

Re-review needed: the Graph Editing description changed again, and that affects which skills requests route to.

@malibio

malibio commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3051 (Re-Review)

Review Type: Re-Review (1a94d16 → 9662ba8)
Recommendation: APPROVE (posted as a comment, since GitHub blocks self-approval)

Previous Review Summary

Verification

  • cargo test -p nodespace-agent --no-fail-fast: everything passes (693 lib tests plus all integration binaries). pty::manager::tests::ultra_short_lived_processes_are_pruned failed once and passed on rerun. The PR doesn't touch it, so it is load-flaky and unrelated.
  • cargo test -p nodespace-agent --test live_skill_retrieval_stability -- --ignored: 9/9 pass with the locked nomic GGUF.
  • Live rankings under the new description:
    • "remove the closed tickets": Node Deletion 0.807, Graph Editing 0.789
    • "get rid of the paid invoices": Node Deletion 0.814, Graph Editing 0.808
    • "delete the resolved incidents": Conflict Resolution 0.978, Node Deletion 0.904, Graph Editing 0.832
    • All 7 completion requests still have Graph Editing in the top 3. "mark the invoice as paid" and "mark the outage report done" have it at rank 1.

New test's assertion logic: correct

  • starts_with(&format!("{skill}=")) is an exact name match. scored_ranking formats each entry as name=score, so the = delimiter stops one skill name from matching another that starts with it.
  • If Node Deletion is absent from the top 6, including when a confidence threshold filters it out, the query counts as a miss. That is the right conservative choice: a missing Node Deletion means delete_node can't be offered.
  • If Graph Editing is absent, the query passes. That is correct, because the test is scoped to Graph Editing vs Node Deletion.
  • limit 6 is wide enough to see both skills on all three queries.

Code Review Findings (new changes only)

🟢 Suggestions

1. The deletion control passes by a thin margin
📁 packages/agent/src/skill_pipeline.rs:534, packages/agent/tests/live_skill_retrieval_stability.rs:488-525

  • Issue: Node Deletion leads Graph Editing by only 0.006 on "get rid of the paid invoices" and 0.018 on "remove the closed tickets". The model is locked, so the test is deterministic, and it is the right guard. But any later edit to either description could flip it.
  • Recommendation: No change needed in this PR. The new comment already warns editors that the wording is load-bearing, and the test enforces it. Anyone who edits Graph Editing or Node Deletion should expect this control to be the one that fails first.
  • Principle: Make fragile invariants loud. That is already done here.

2. A pre-existing destructive-routing gap is documented but not tracked
📁 packages/agent/tests/live_skill_retrieval_stability.rs:494-496

  • Issue: On "delete the resolved incidents", Conflict Resolution ranks first (0.978) and Node Deletion second (0.904). If Conflict Resolution is the top tool-bearing candidate, delete_node is withheld silently. This isn't a regression. It happened on main too, and the doc comment says so honestly. But a code comment is the only record of it.
  • Recommendation: File a small follow-up issue, or add it to Stage 2: deterministic clarify backstop when no offered tool can write and the turn gives up in prose #3047's scope, so the gap doesn't live only in a test comment. Possible directions: tighten Conflict Resolution's description to conflict-journal language, or admit destructive tools from the top-ranked skill that carries a destructive tool rather than the top tool-bearing one.
  • Principle: A known correctness gap on the destructive path belongs in the backlog, where someone will see it.

Nitpicks

  • None.

Narrowed description: any new risks?

"Keep it / stay" pulls Graph Editing away from deletion requests and keeps it in the top 3 on every completion request. Dropping "closed" and "complete" as listed states costs no measured coverage: "close out the support ticket" still has it at rank 2. The comment gives the reason for the narrow wording and names all three guards. I see no new problem.

Summary

The earlier blocker-grade concern (Graph Editing silently outranking Node Deletion) was real. It is now fixed and guarded by a correctly built live control. The comment and wording fixes are accurate, and both skips are justified. Approve.

@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 (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed

No code changes, so no re-review needed.

@malibio
malibio merged commit f9cf7d0 into main Sep 25, 2026
@malibio
malibio deleted the issue-2912-stage2-clarify branch September 25, 2026 22:48
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.

Stage 2 has no clarify path when retrieval's top skill is a lexical false-positive

1 participant