Repository navigation
resolve_query's guidance and required context are gated behind Graph Editing's routing score; fail-open delivers the tool without either - #1855
Conversation
resolve_query is whitelisted by exactly one skill (Graph Editing), and its required node_type parameter tells the model to copy the id from the RELEVANT ENTITY TYPES block that only render_candidates_for_prompt injects — and only when a candidate clears the Stage-2 score gate. stage2_tools's fail-open paths (no candidate clears the gate, or a whitelist resolves to nothing registered) handed the tool over anyway, directing the model to copy from context it never receives. Tool::requires_routed_guidance marks resolve_query as depending on routed guidance; stage2_tools's fail-open branches now exclude any such tool from the full-surface fallback rather than stranding the model with unusable instructions. The scoped (non-fail-open) path is unaffected: whenever resolve_query is offered there, the same score-gate filter that permits it also renders its guidance block. Co-Authored-By: Claude <[email protected]>
Code Review: PR #1855 — Exclude
|
malibio
left a comment
There was a problem hiding this comment.
Review recommendation: REQUEST CHANGES (GitHub blocks a request-changes review from the PR author's own account, so recording via --comment instead — see full review posted above for the actual recommendation and required action).
Code review on PR #1855 found a second door to the same defect stage2_tools's fail-open exclusion closes: when session.routing_disabled is true, candidate_block (the RELEVANT ENTITY TYPES block resolve_query's required node_type parameter depends on) is forced to None regardless of whether a candidate cleared the score gate. A Graph Editing candidate that legitimately clears its bar still puts resolve_query in `tools` via stage2_tools's normal scoped path, which is unaffected by routing_disabled -- so the tool reaches the model with no guidance again, through a path stage2_tools's own exclusion doesn't cover. Re-derive the exclusion from what the model is actually about to receive (candidate_block) rather than from why routing produced no candidates: after computing candidate_block, retain only tools that either don't require routed guidance or are accompanied by a rendered block. This subsumes stage2_tools's own fail-open exclusion (empty candidate_block there too) without duplicating its logic. RecordingEngine (test fixture) now also captures each generate() call's offered tool names, and a new test reproduces the exact scenario: a Graph Editing candidate whitelisting resolve_query at score 0.9 (clears the gate) with routing_disabled=true. Verified the test fails without the fix (temporarily neutralized the retain(), confirmed the new test catches it, restored the fix). Co-Authored-By: Claude <[email protected]>
|
Addressed the Critical finding from the initial review: Fix in Added
|
Code Review: PR #1855 — Exclude
|
malibio
left a comment
There was a problem hiding this comment.
Re-review recommendation: APPROVE. Follow-up commit 4d221b6 correctly closes the routing_disabled gap identified as Critical in the initial review — verified placement, condition equivalence, no conflict with stage2_tools's existing exclusion, and the new regression test. Build clean, cargo test -p nodespace-agent --lib: 387/387 passed, clippy clean on a fresh rebuild. Full report posted as a PR comment (GitHub blocks --approve from the PR author's own account, so recording the recommendation here explicitly).
The routing_disabled fix (4d221b6) used candidate_block.is_none() as the "no guidance was sent" signal. That's coarser than reality: render_candidates_for_prompt returns Some(...) from its header text alone once ANY eligible candidate exists, even if the specific candidate whitelisting resolve_query has empty schema_metadata and so never renders its own RELEVANT ENTITY TYPES sub-block. A Graph Editing candidate with no typed entities (schema_metadata: []) would have sailed through the routing-enabled, gate-cleared path with resolve_query offered and no entity-types block for it -- the identical defect through a third door, not caught by either previous fix or their tests (both fixtures used non-empty schema_metadata or routing_disabled, never the "block header present but this candidate's own sub-block empty" combination). Add routing::tools_with_available_guidance(candidates, render_disabled) as the single precise source of truth: a tool counts as having available guidance only if some eligible candidate both whitelists it AND has a schema_metadata that actually renders a non-empty entity- types block, with render_disabled short-circuiting to empty (mirrors session.routing_disabled forcing candidate_block to None regardless of what would otherwise render). agent_loop.rs now filters tools against this instead of the coarser candidate_block.is_none() check. Tests: 3 new unit tests directly on tools_with_available_guidance (empty-metadata exclusion, real-metadata inclusion, render_disabled override, below-bar exclusion) in routing.rs; 2 new agent_loop.rs integration tests -- the true happy path (real schema_metadata, routing enabled, resolve_query correctly offered) and the specific edge case (empty schema_metadata, routing enabled, block header present but resolve_query still excluded), the latter asserting the premise (header present, sub-block absent) so the test can't pass for the wrong reason. Co-Authored-By: Claude <[email protected]>
|
One more precision fix, pushed as `d5396a28`, before merge. While double-checking the `routing_disabled` fix (`4d221b6a`), I found it used `candidate_block.is_none()` as the "no guidance was sent" signal — coarser than reality. `render_candidates_for_prompt` returns `Some(...)` from its header text alone once any eligible candidate exists, even if the specific candidate whitelisting `resolve_query` has empty `schema_metadata` and never renders its own `RELEVANT ENTITY TYPES` sub-block. A Graph Editing candidate with no typed entities would sail through the routing-enabled, gate-cleared path with `resolve_query` offered and no entity-types block for it — the same defect through a third door. Added `routing::tools_with_available_guidance(candidates, render_disabled)` as the precise source of truth: a tool counts as having available guidance only if some eligible candidate both whitelists it AND actually renders a non-empty entity-types block. `agent_loop.rs` now filters against this instead of the coarser `candidate_block.is_none()` check. 7 new tests: 4 directly on `tools_with_available_guidance` (empty-metadata exclusion, real-metadata inclusion, `render_disabled` override, below-bar exclusion — one caught a real bug in my first draft of the below-bar test itself, since `resolve_query` alone is a read tool with a lower bar than I'd assumed) plus 2 `agent_loop.rs` integration tests: the genuine happy path (real `schema_metadata`, routing enabled, `resolve_query` correctly offered) and the specific edge case (empty `schema_metadata`, routing enabled, block header present but `resolve_query` still excluded — asserts the premise so it can't pass for the wrong reason). `cargo test -p nodespace-agent --lib`: 393/393. `cargo clippy`: clean. Full pre-push gate passed end-to-end on push, including both previously-flaky tests (`architecture-benchmarks.test.ts`, `ai_chat_send_to_idle_test`) — those failures across earlier push attempts were machine contention from other concurrent sessions' daemons/evals, confirmed by isolated re-runs passing cleanly each time. |
Code Review: PR #1855 — Exclude
|
malibio
left a comment
There was a problem hiding this comment.
Re-review recommendation: APPROVE. Commit d5396a2 correctly tightens the routing_disabled fix from candidate_block.is_none() (coarse) to routing::tools_with_available_guidance (precise, per-candidate rendering check) — closing the exact edge case flagged non-blocking in the prior round-2 re-review. Verified: reuses existing clears_score_gate/render_schema_metadata helpers rather than reimplementing; candidate_block no longer used for filtering anywhere (only prompt content + telemetry); retain() placement precedes all downstream consumers of tools; 6 new tests cover both the true-positive happy path and the exact edge case end-to-end, with premise assertions so they can't pass for the wrong reason. Build clean, cargo test -p nodespace-agent --lib: 393/393 passed (matches implementer's claim), clippy clean on a forced rebuild. Full report posted as a PR comment (GitHub blocks --approve from the PR author's own account, so recording the recommendation here explicitly).
Closes #1840