Repository navigation
Offer resolve_query when either site renders the entity-types block (#1894) - #1906
Conversation
…1894) `resolve_query` was withheld from every turn in a workspace whose custom schemas didn't match the request, including turns whose prompt did carry a `RELEVANT ENTITY TYPES` block. The block reaches the prompt from two independent sites: the Stage-2 candidate block (`render_candidates_for_prompt`) and the resident workspace context (`context_ops::build_workspace_context`). Both render through the same renderer under the same shared heading constant, but `tools_with_available_guidance` consulted only the first — asking "did this candidate contribute the block?" when the tool's required `node_type` parameter only needs "will the assembled prompt contain it?". That asymmetry made the tool unreachable in practice: Graph Editing whitelists `resolve_query` but declares no `node_types`, so `skill_ops` falls back to "all non-core schemas" for its `schema_metadata` — empty whenever retrieval surfaced nothing, which withheld the tool even though workspace context had rendered the block from its own semantic retrieval. The gate now consults both sites. Its purpose is unchanged — never offer a tool whose required parameter points at something the model cannot see — and a block the model can see satisfies that purpose whichever site rendered it. The score gate still governs eligibility (the workspace block makes the parameter answerable, it does not make an unmatched skill's tools eligible), and `routing_disabled` still suppresses the candidate path only, since that flag is about candidate-block injection and says nothing about the resident workspace block. Verified live (purged isolated daemon, e4b, n_ctx 32768): `resolve_query` now appears in `toolsOffered` and the model calls it 3/3 on "The 2400 one came back — set it to returned", against 0/3 before. No guidance wording change was needed — the existing INDIRECT TARGET prose was already correct and simply had no reachable tool to name. Also records `resolve_query`'s custom-types-only scope on `def_resolve_query`: both render sites filter `is_core` schemas, so core-type (`task`/`text`) bare-value updates render no block and correctly withhold the tool. The boundary was implicit in two filters in another crate and reads as a bug without this note. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163
🔍 Pragmatic Code Review — PR #1906Review Type: Initial review (full PR, 0 prior reviews/comments) Requirements Check (against the agreed re-scope, not the original AC text)The issue was re-scoped in comment 5154181473 after the original premise ("model has the tool and ignores it") was refuted — the reproduction measured a daemon predating #1893 and
The re-scope did not leave anything important unaddressed for this PR's stated purpose. I do flag one thing the re-scope arguably should have swept in — see 🟡-1 — because it is the same bug class, in the same function's immediate neighbour, and the PR's own doc comment now describes the fixed invariant in a way the neighbour violates. I want to note the investigation quality explicitly: catching that the original repro measured a stale daemon, and that the tool was never offered at all, turned a speculative prompt-tuning task into an 8-line correctness fix. That is the outcome the "verify the premise before implementing" discipline exists to produce. Code Review Findings🔴 CriticalNone. This is a net-positive correctness fix with real live verification (0/3 → 3/3 offered and called) and a mutation-tested test suite. 🟡 Important🟡-1 —
fn fail_open_surface(all: &[ToolDefinition]) -> Vec<ToolDefinition> {
all.iter()
.filter(|t| !super::tools::requires_routed_guidance_tool(&t.name))
.cloned()
.collect()
}This strips The practical consequence: on a turn where retrieval returns nothing above the score bar (embedding service degraded, or simply a request no skill matches) but workspace context did render the entity-types block, I am not treating this as a blocker, and I want to be explicit about why: What I'd ask for in this PR is not the fix but the honesty: the doc comments at Principle: comments must explain the actual "why"; a rationale invalidated by a change in the same file is worse than no rationale, because it actively misdirects the next reader. 🟡-2 — The substring match can produce a false positive when let workspace_has_block = workspace_context.contains(RELEVANT_ENTITY_TYPES_HEADER);I checked the false-positive concern properly rather than assuming. In
The result is a workspace context containing the heading with nothing under it, and This is narrow (needs the budget to land in a ~130-byte window) and strictly better than the status quo of never offering the tool at all, so it is not a blocker. But the fix is cheap and removes the coupling concern at the same time: match on the header plus evidence of a following line, e.g. let workspace_has_block = workspace_context
.split_once(RELEVANT_ENTITY_TYPES_HEADER)
.is_some_and(|(_, rest)| rest.trim_start_matches('\n').lines().next()
.is_some_and(|l| !l.trim().is_empty()));Alternatively — and I think this is the better long-term shape — have To be fair to the current approach: the shared constant is the right call given the two sites, and this is materially better than the independently-worded copies it replaced. This is about the next increment, not a criticism of the choice made. Principle: prefer structured signals over re-parsing rendered output across a module boundary; a rendering budget should not be able to silently change tool availability. 🟢 Suggestions🟢-1 — Lifetime annotation is sound; confirming explicitly since it was flagged for scrutiny
🟢-2 — The short-circuit removal is correct and intentional, not a regression Verified the claim rather than taking it on trust. The old
The truth table is fully covered: 🟢-3 — Test quality is high; the mutation testing deserves specific credit The 4 new tests are well-chosen: one proves the fix ( The reported mutation test — reverting the logic fails exactly the 2 fix-dependent tests while the 2 guard tests still pass — is the check that distinguishes tests that pin behaviour from tests that merely execute code. That should be the standard for this kind of predicate change. The one gap is 🟡-2's case: no test covers a workspace context where the header is present but the list under it is empty. If you take the 🟡-2 fix, 🟢-4 — I read both filters rather than trusting the comment:
One precision note on the wording: the claim "both sites drop 🟢-5 — Documentation-to-code ratio ~60 lines of doc comment for ~8 lines of logic change. I went back and forth on flagging this and landed on: it's justified here, but it's near the ceiling. The content is genuinely non-obvious and hard-won — the two-site asymmetry, why the score gate stays outside the disjunction, why The risk to watch is the one 🟡-1 identifies: long rationale comments become liabilities when the code moves and they don't. The Standards Compliance
On the deliberately-scoped-out itemsI reviewed the three known-adjacent issues and agree with all three exclusions:
One process note, offered as a caution rather than a criticism of this PR: the live verification is 3/3 vs 0/3 on single runs. For a gate that either fires or doesn't, 3/3 is adequate — Recommendation✅ APPROVEThis is a clean, well-evidenced correctness fix that materially improves code health. The premise-checking that produced it — discovering the original bug report rested on a stale-daemon measurement, and that the tool was never offered at all — turned a speculative prompting task into an 8-line gate fix with live before/after numbers and mutation-tested coverage. The change is atomic, the score gate and ADR-038 trust boundary are preserved deliberately and with tests proving it, and the lifetime and ordering claims both hold up under independent verification. Neither 🟡 finding blocks merge:
Suggested follow-ups (none blocking): amend the Reviewed against the agreed re-scope in issue #1894 comment 5154181473, per the Pragmatic Quality framework. |
malibio
left a comment
There was a problem hiding this comment.
Pragmatic code review complete — APPROVE. Full report posted as a PR comment above: #1906 (comment)
No critical findings. Two 🟡 Important items, neither blocking:
fail_open_surface's rationale comments now state a reason this PR proves incorrect (comment-only fix; behaviour question belongs to #1802)- The
contains(RELEVANT_ENTITY_TYPES_HEADER)substring match can false-positive whenformat_for_prompt'smax_charsbudget truncates between the header and the first schema line
Verified independently: 38/38 routing tests pass, lifetime annotation sound, set_session_context ordering confirmed at local_agent_service.rs:521 (before the loop), and the core-type scope claim checked against both is_core filters.
…e rationale Three findings from the review of #1906. Require a type actually listed under the heading, not just the heading itself. `context_ops`'s renderer pushes the heading and then breaks out of its per-schema loop once the character budget is spent, so a budget consumed by the first type line leaves a bare heading behind. A plain `contains` would pass that and offer `resolve_query` with its required `node_type` pointing at an empty list — reintroducing the exact strand this gate exists to prevent, from the opposite direction. Both renderers emit `- <type_id>` lines, so the check is the first non-blank line after the heading. Correct `fail_open_surface`'s rationale, which said the block is injected only by routing. That is now false: workspace context renders it independently. The exclusion stays — but as an eligibility judgement rather than a claim about what is present. Fail-open means retrieval matched nothing, and ADR-038 puts the trust boundary at what retrieval surfaced; offering a reference-resolving tool precisely when the system could not identify the needed capability widens the surface where there is least reason to. Behaviour is unchanged, only the reasoning is now accurate. Hedge the core-type claim on `def_resolve_query`. "Both sites drop is_core" holds for `skill_ops`' unscoped fallback but not its scoped branch, which filters by declared `node_types` id and would render a core type if a skill named one. No seeded skill does today, so the boundary stands — but it rests on that, not on the filters alone. Two tests added for the truncated/prose heading cases (40 in routing::tests, 419 in the crate). Verified both fail against a naive `contains` and pass with the fix. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163
… trim Three remaining items from the PR review, all documentation. `stage2_tools`' doc carried the same invalidated reasoning already corrected on `fail_open_surface` — "the routing-only RELEVANT ENTITY TYPES block" and "on the full-surface fallback it never renders". Workspace context renders it independently of routing, so both clauses were false. Reframed as the eligibility judgement it actually is, matching its callee. Hedged the `is_core` claim here as on `def_resolve_query`: it holds for `skill_ops`' unscoped fallback (the branch `resolve_query`'s whitelisting skill takes) but not its scoped branch, which filters by declared id and has no `is_core` filter. Trimmed the paragraph narrating the rejected "is the block Some" alternative down to the invariant that actually matters — both checks require a type listed, not merely a heading — now that the workspace path enforces the same rule and the two can be stated once. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163
Review response — all findings addressedCommits 🟡-1 — stale rationale on the fail-open path ✅The reviewer asked for honesty rather than the behaviour change, and flagged two comment sites. I initially fixed only Both now frame the exclusion as an eligibility judgement rather than an availability claim: fail-open means retrieval matched nothing, and ADR-038 puts the trust boundary at what retrieval surfaced — so withholding a reference-resolving tool at the moment the system could not identify the needed capability is defensible on its own terms, independent of whether the block happens to be present. Behaviour deliberately unchanged. 🟡-2 — substring false positive ✅Fixed, and the reviewer's diagnosis was correct on inspection: The check now requires a type actually listed under the heading. Both renderers emit let workspace_has_block = workspace_context
.split_once(RELEVANT_ENTITY_TYPES_HEADER)
.and_then(|(_, after)| after.lines().find(|l| !l.trim().is_empty()))
.is_some_and(|first| first.trim_start().starts_with("- "));Two tests added for the truncated-heading and heading-followed-by-prose cases. Both verified to fail against the naive On the structured-signal refactor: agreed it's the better long-term shape, and not taken here. Having 🟢-4 —
|
Summary
resolve_querywas unreachable in practice: withheld from every turn in a workspace whose custom schemas didn't match the request, including turns whose prompt did carry aRELEVANT ENTITY TYPESblock.The block reaches the prompt from two independent sites — the Stage-2 candidate block (
render_candidates_for_prompt) and the resident workspace context (context_ops::build_workspace_context). Both render through the same renderer under the same shared heading constant, buttools_with_available_guidanceconsulted only the first. It asked "did this candidate contribute the block?" when the tool's requirednode_typeparameter only needs "will the assembled prompt contain it?".That asymmetry is what made the tool unreachable: Graph Editing whitelists
resolve_querybut declares nonode_types, soskill_opsfalls back to "all non-core schemas" for itsschema_metadata— empty whenever retrieval surfaced nothing, withholding the tool even when workspace context had rendered the block from its own semantic retrieval.What changed
tools_with_available_guidancenow consults both sites. Its purpose is unchanged — never offer a tool whose required parameter points at something the model cannot see — and a block the model can see satisfies that purpose whichever site rendered it.Deliberately preserved:
routing_disabledstill suppresses the candidate path only — that flag exists because candidate-block injection suppresses tool-calling on some served models, which says nothing about the resident workspace block.Verification
Live, on a purged isolated daemon (
NODESPACE_HOME,served_db_pathverified),gemma-4-e4b-q4km,n_ctx32768:resolve_queryintoolsOfferedresolve_queryNo guidance wording change was needed. The existing
INDIRECT TARGETprose was already correct — it simply had no reachable tool to name. This is the finding that reframed #1894: it was filed as a model-guidance gap, but the model never had the tool.Unit coverage: 4 new tests in
routing.rs(38 total, up from 34). Verified they genuinely catch the bug — reverting the logic fails exactly the two fix-dependent tests while the two guard tests still pass.Scope boundary recorded
def_resolve_querynow documents that the tool resolves against user-defined (non-core) types only. Both render sites filteris_coreschemas, so core-type (task/text) bare-value updates render no block and correctly withhold the tool. That boundary was implicit in two filters in another crate and reads as a bug without the note. Widening it means deciding to render core types into that block — a change affecting every consumer, not a local one.Known-adjacent, deliberately not fixed here
Surfaced during investigation, each its own concern:
resolve_queryreturnsno_matchfor "the 2400 one" against a node that does havereplacement_cost: 2400— a resolver-internal decomposition/search issue, downstream of this gate.create_nodewhencreate_schemaisn't offered, which makes matrix scenario 6 unwinnable by construction from upstream rather than from this bug.Test plan
cargo test -p nodespace-agent— 417 passed, 0 failedbun run test:all— 171 frontend files / 4108 tests, 20 browser tests, all Rust suites, 0 failuresbun run quality:fix— cleanCloses #1894
🤖 Generated with Claude Code
https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163