Skip to content

Offer resolve_query when either site renders the entity-types block (#1894) - #1906

Merged
malibio merged 3 commits into
mainfrom
issue-1894-resolve-query-guidance
Aug 2, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-1894-resolve-query-guidance

Conversation

@malibio

@malibio malibio commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

resolve_query was unreachable in practice: 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. It asked "did this candidate contribute the block?" when the tool's required node_type parameter only needs "will the assembled prompt contain it?".

That asymmetry is what made the tool unreachable: 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, withholding the tool even when workspace context had rendered the block from its own semantic retrieval.

What changed

tools_with_available_guidance 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.

Deliberately preserved:

  • The score gate still governs eligibility. The workspace block makes the parameter answerable; it does not make an unmatched skill's tools eligible (ADR-038's trust boundary).
  • routing_disabled still 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_path verified), gemma-4-e4b-q4km, n_ctx 32768:

before after
resolve_query in toolsOffered 0/3 3/3
model calls resolve_query 0/3 3/3

No guidance wording change was needed. The existing INDIRECT TARGET prose 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_query now documents that the tool resolves against user-defined (non-core) types only. Both render sites filter is_core schemas, 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_query returns no_match for "the 2400 one" against a node that does have replacement_cost: 2400 — a resolver-internal decomposition/search issue, downstream of this gate.
  • Scenarios 3/8a/8b regress to create_node when create_schema isn't offered, which makes matrix scenario 6 unwinnable by construction from upstream rather than from this bug.
  • The two-injection-site asymmetry itself is worth flagging for Spike: re-evaluate the agent prompting architecture from first principles #1802's broader prompting-architecture pass.

Test plan

  • cargo test -p nodespace-agent — 417 passed, 0 failed
  • bun run test:all — 171 frontend files / 4108 tests, 20 browser tests, all Rust suites, 0 failures
  • bun run quality:fix — clean
  • Pre-push gate passed
  • Live verification above

Closes #1894

🤖 Generated with Claude Code

https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163

…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
@malibio

malibio commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

🔍 Pragmatic Code Review — PR #1906

Review Type: Initial review (full PR, 0 prior reviews/comments)
Scope: 1 commit 91efbfed, 3 files, +149/−25, all Rust
Verification performed: re-ran cargo test -p nodespace-agent --lib routing:: → 38 passed, 0 failed; traced both render sites, the header constant, the is_core filters, and the set_session_context call ordering in local_agent_service.rs against the claims in the doc 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 resolve_query was never in toolsOffered. The approved re-scope was three things:

Re-scoped requirement Status Evidence
Land a narrow gate fix ✅ tools_with_available_guidance now consults both render sites; the change is 8 lines of logic, the rest is documentation and tests
Verify the ordering claim against actual call order ✅ Confirmed independently: build_workspace_context (local_agent_service.rs:515) → create_session (:517) → set_session_context (:521), all before the loop is spawned. session.dynamic_context is genuinely populated at agent_loop.rs:742
Write down the core-type scope boundary explicitly ✅ tools.rs:375-391 on def_resolve_query, cross-referenced from routing.rs:343-350

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

🔴 Critical

None. 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 — fail_open_surface has the identical bug this PR just fixed, and the new doc comment implicitly asserts it doesn't
📁 packages/agent/src/local_agent/routing.rs:436-441 (unchanged by this PR, but now inconsistent with it)

stage2_tools has two fail-open branches — no candidate clears the score gate (:416), or the whitelist names only unregistered tools (:427). Both route through:

fn fail_open_surface(all: &[ToolDefinition]) -> Vec<ToolDefinition> {
    all.iter()
        .filter(|t| !super::tools::requires_routed_guidance_tool(&t.name))
        .cloned()
        .collect()
}

This strips resolve_query unconditionally, on exactly the reasoning this PR just established is wrong. Its doc comment (:433-435, and the longer version at :398-408) says the tool is dropped because "that block is injected by render_candidates_for_prompt only alongside a scoped whitelist; on the full-surface fallback it never renders." After this PR, that sentence is factually false — the block also reaches the prompt from the resident workspace context, which is present on fail-open turns too.

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, resolve_query is still withheld. That is the same class of unreachability, one branch over.

I am not treating this as a blocker, and I want to be explicit about why: stage2_tools' filter runs first and tools.retain runs second, so on the fail-open path the tool is already gone before tools_with_available_guidance is consulted — meaning fixing it is a genuine behaviour change to the fail-open contract, not a mechanical extension. The score gate is also load-bearing here in a way it isn't in the fixed function: fail-open means nothing was routed, so there's a real argument that offering a routed-guidance tool there is wrong on eligibility grounds independent of parameter answerability. That's a decision, not an oversight.

What I'd ask for in this PR is not the fix but the honesty: the doc comments at :398-408 and :433-435 now state a reason that this PR proves incorrect. Leaving a stale rationale in place is how the two-site drift happened in the first place — RELEVANT_ENTITY_TYPES_HEADER's own doc comment (context_ops.rs:102-108) records that exact history ("an earlier version of this fix touched only one, leaving the other to reinforce the exact contamination the first was changed to guard against"). Suggest amending those comments to say the exclusion is an eligibility decision (nothing routed ⇒ no routed-guidance tools) rather than an availability one (the block never renders), and noting the workspace site explicitly. That is a comment-only change and keeps the behaviour decision for #1802.

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 max_chars truncates between header and first line
📁 packages/agent/src/local_agent/routing.rs:360

let workspace_has_block = workspace_context.contains(RELEVANT_ENTITY_TYPES_HEADER);

I checked the false-positive concern properly rather than assuming. In context_ops.rs::format_for_prompt:

  • :391 guards the header with if !self.relevant_schemas.is_empty(), so the header never renders for an empty schema list. Good — the obvious false positive doesn't exist.
  • But :392-394 writes the header if it fits the max_chars budget, then :404-407 breaks out of the per-schema loop if the next line would exceed the budget. With the budget at 4000 (local_agent_service.rs:1895), a context whose collections section leaves 130-ish bytes of headroom will emit the 118-char header and then break before writing a single entity line.

The result is a workspace context containing the heading with nothing under it, and contains() returns true — so resolve_query is offered with a required parameter pointing at an empty block. That is precisely the failure mode tools_with_available_guidance's original per-candidate precision existed to prevent, reintroduced through the new path.

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 format_for_prompt return the block's presence as structured data rather than having a consumer in a different crate re-derive it by string-scanning the rendered prompt. Substring-matching rendered prose is a brittle coupling: any future change to format_for_prompt's budget handling, ordering, or heading placement silently changes tool availability with no compile error. The shared constant makes the heading drift-proof but does nothing for the structure around it.

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
📁 packages/agent/src/local_agent/routing.rs:355-359

<'a> ties the returned HashSet<&'a str> to candidates only, and workspace_context: &str gets its own elided, independent lifetime. This is correct and minimal: workspace_context is consumed entirely by the contains() call on :360, producing a bool — nothing derived from it escapes into the return value. Tying it to 'a would have over-constrained the signature for no benefit. At the call site (agent_loop.rs:742-747) dynamic_ctx borrows from session.dynamic_context, which outlives the call regardless. No issue.

🟢-2 — The short-circuit removal is correct and intentional, not a regression
📁 packages/agent/src/local_agent/routing.rs:355-372

Verified the claim rather than taking it on trust. The old if render_disabled { return HashSet::new() } was an early return; the new code folds render_disabled into the per-candidate predicate as workspace_has_block || (!render_disabled && ...). Two things make this right:

  1. routing_disabled is set from the routing-probe verdict and is specifically about candidate-block injection suppressing tool-calling on some served models (agent_loop.rs:700-707 documents this, and the flag's only other effect at :709-721 is forcing candidate_block to None). It has no bearing on session.dynamic_context, which flows into TemplateContext.workspace_context at :755 unconditionally. The claim holds.
  2. The score gate stays outside the disjunction (:363, .filter(|c| clears_score_gate(c)) still runs first), so a workspace block cannot rescue an unmatched skill's tools. The comment at :365-367 states this and a_workspace_block_does_not_rescue_a_candidate_below_its_score_bar enforces it.

The truth table is fully covered: {block present} × {render_disabled} × {clears gate} × {candidate metadata present} — all the meaningful combinations have a test. No branch is untested.

🟢-3 — Test quality is high; the mutation testing deserves specific credit
📁 packages/agent/src/local_agent/routing.rs:763-868

The 4 new tests are well-chosen: one proves the fix (a_workspace_entity_types_block_supplies_guidance_a_candidate_lacks, which asserts both the before-state and after-state in one test — a nice touch that makes the delta explicit), and three are guards against over-correction (score gate, routing_disabled independence, heading-specificity). The 4 modified tests all gained "" as the third argument, which preserves their original semantics exactly — each was testing a candidate-path property with no workspace block, and passing "" keeps that the case. They still test what their names claim.

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, workspace_with_block() gains a sibling fixture and that's covered.

🟢-4 — def_resolve_query's core-type scope claim verified accurate at both sites
📁 packages/agent/src/local_agent/tools.rs:375-391

I read both filters rather than trusting the comment:

  • context_ops.rs:231-238 — parse_and_filter_non_core_schemas applies .filter(|s| !s.is_core), and it is the sole producer of relevant_schemas (:326), which is the only vector rendered under the heading (:391-393). Confirmed. (The sibling related_schemas path at :213 also filters is_core, and renders under a different heading anyway.)
  • skill_ops.rs:203-210 — the unscoped fallback is if scoped_type_ids.is_empty() { !s.is_core } else { scoped_type_ids.contains(&s.id) }. Confirmed for the fallback branch.

One precision note on the wording: the claim "both sites drop is_core schemas" is true of skill_ops' fallback branch but not universally — a skill declaring node_types: ["task"] would put a core type into schema_metadata via the scoped_type_ids.contains(&s.id) branch, which has no is_core filter. That's hypothetical today (no shipped skill scopes to a core type) and doesn't affect the conclusion for resolve_query, whose whitelisting skill is the unscoped Graph Editing. Worth a half-sentence hedge — "skill_ops's non-core fallback (the branch that applies to resolve_query's unscoped whitelisting skill)" — so the note stays true if someone later adds a core-scoped skill.

🟢-5 — Documentation-to-code ratio
📁 packages/agent/src/local_agent/routing.rs:309-353, tools.rs:375-391

~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 routing_disabled doesn't apply — and it's the kind of knowledge that costs a full re-investigation to recover. The core-type note in tools.rs earns its place particularly well, since it pre-empts a "this is a bug" misreading of behaviour that's implicit in two filters in another crate.

The risk to watch is the one 🟡-1 identifies: long rationale comments become liabilities when the code moves and they don't. The RELEVANT_ENTITY_TYPES_HEADER comment's own history is the cautionary tale. Nit-level suggestion: the middle paragraph of tools_with_available_guidance ("Still more precise than…") is narrating a rejected alternative implementation rather than the current one, and could be trimmed to a sentence without losing the load-bearing insight.


Standards Compliance

Standard Status
No lint suppression / #[allow(dead_code)] / #[deprecated] ✅ none introduced; quality:fix clean
Greenfield — no back-compat shims, no migration/transition code ✅ signature changed in place, all 5 call sites updated, no dual-mode
No issue numbers in code comments ✅ for this PR — I checked every added line. routing.rs:302 carries (#1846) and context_ops.rs:100 carries (#1846), but both are pre-existing on main and untouched here. Not this PR's violation; worth a cleanup pass sometime, out of scope to demand it here
Docs in ../nodespace-docs/ only ✅ no .md files added; all documentation is rustdoc on the code it describes, which is the correct home for it
ADR-038 trust boundary preserved ✅ score gate remains authoritative for eligibility

On the deliberately-scoped-out items

I reviewed the three known-adjacent issues and agree with all three exclusions:

  • resolve_query returning no_match for "the 2400 one" — genuinely downstream. This PR governs whether the tool is offered; that bug is inside the resolver's decomposition. Fixing them together would produce a change where a failure can't be attributed to either half. Correctly separated.
  • Matrix 3/8a/8b regressing to create_node — upstream of this gate (create_schema not being offered), and the PR body's observation that it makes scenario 6 unwinnable by construction from upstream is the right diagnosis. Bundling it would violate atomicity.
  • The two-injection-site asymmetry → Spike: re-evaluate the agent prompting architecture from first principles #1802 — agreed, and 🟡-1 is evidence the asymmetry is worth that broader pass rather than another point fix. This PR fixes one consumer of the asymmetry; fail_open_surface is a second; the architectural answer is for prompt assembly to expose what it rendered rather than having consumers infer it.

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 — toolsOffered is deterministic given the same inputs, so the offering half is effectively proven. The "model calls it 3/3" half is the stochastic one, and per the #1862 lesson that single-run matrix numbers aren't decision-grade, I'd read that as "the model can now reach it" rather than "the model reliably uses it." The PR body doesn't overclaim here, so this is just underlining where the evidence stops.


Recommendation

✅ APPROVE

This 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:

  • 🟡-1 is a comment-accuracy issue in code this PR didn't touch; the underlying behaviour question genuinely belongs to Spike: re-evaluate the agent prompting architecture from first principles #1802. Amending the two stale rationale comments would be a welcome follow-up in this PR (comment-only, zero risk) but I won't hold the merge for it.
  • 🟡-2 is a narrow false positive that is strictly better than the status quo — the failure mode is "tool offered with an empty block" replacing "tool never offered at all." Worth fixing, ideally as a follow-up alongside the structured-signal refactor rather than as a bolt-on substring heuristic.

Suggested follow-ups (none blocking): amend the fail_open_surface / stage2_tools rationale comments (🟡-1); harden or restructure the block-presence signal (🟡-2); hedge the skill_ops scoped-branch wording in def_resolve_query (🟢-4).

Reviewed against the agreed re-scope in issue #1894 comment 5154181473, per the Pragmatic Quality framework.

@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.

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 when format_for_prompt's max_chars budget 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.

malibio and others added 2 commits August 2, 2026 03:05
…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
@malibio

malibio commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Review response — all findings addressed

Commits 951a6dfb and 8084337e. No recommendation was skipped outright; the one behaviour change the review deliberately left open (fail_open_surface) is documented below as scoped-out with its reasoning, per the reviewer's own framing.

🟡-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 fail_open_surface and missed the second on stage2_tools:398-408; caught it on re-read of the review and fixed in 8084337e.

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. stage2_tools filters before tools.retain, so extending the fix here is a real change to the fail-open contract, not a mechanical one. Agreed that belongs with #1802 rather than bolted on here.

🟡-2 — substring false positive ✅

Fixed, and the reviewer's diagnosis was correct on inspection: context_ops.rs:395 pushes the heading, then :407 can break before the first type line when the budget is exhausted, leaving a bare heading that a naive contains accepts.

The check now requires a type actually listed under the heading. Both renderers emit - <type_id> lines (EntityTypeDescriptor::render_line), so it tests the first non-blank line after the heading:

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 contains and pass with the fix, so they pin the behaviour rather than merely executing it.

On the structured-signal refactor: agreed it's the better long-term shape, and not taken here. Having format_for_prompt return block presence as data is a cross-crate signature change touching every consumer of workspace context — squarely #1802's "prompt assembly should expose what it rendered" territory. Taking it now would mean a second, larger refactor inside a PR whose value is an 8-line gate fix.

🟢-4 — is_core hedge ✅

Correct and worth fixing — skill_ops' scoped branch filters by declared id with no is_core filter, so a skill declaring node_types: ["task"] would render a core type. Hedged in both places (def_resolve_query and tools_with_available_guidance), with the latent widening path named explicitly so the note stays true if someone adds a core-scoped skill.

🟢-5 — documentation ratio ✅ (partial)

Took the specific nit: the paragraph narrating the rejected "is the block Some" alternative is now one sentence stating the invariant that survived — both checks require a type listed, not merely a heading — which the workspace path now enforces too, so it states once what was previously said twice.

Left the rest of the rationale in place. The reviewer's own 🟡-1 is the argument for it: the failure mode here is comments going stale, not comments existing, and the fix for that is keeping them accurate — which this round did in three places.

Not addressed (agreed scope)

On the verification caveat

Agreed and worth restating: toolsOffered is deterministic given the same inputs, so 0/3 → 3/3 offered is effectively proof. The 3/3 called half is stochastic and should be read as "the model can now reach it," not "reliably uses it" — consistent with the #1862 lesson that single-run numbers aren't decision-grade. Scenario 6 still does not pass end-to-end, because resolve_query returns no_match for "the 2400 one" against a node that does carry replacement_cost: 2400 — a resolver-internal decomposition bug, downstream of this gate and filed separately.

Verification

  • cargo test -p nodespace-agent → 419 passed, 0 failed (routing::tests 40, up from 34)
  • cargo fmt --check clean · cargo clippy --all-targets → 0 warnings
  • Pre-push gate passed on both commits

Re-review: not needed in my view — every change since the review is documentation, except the 🟡-2 predicate, which is small, directly specified by the reviewer, and covered by two mutation-tested cases. Happy to re-run if you'd prefer eyes on the predicate.

@malibio
malibio merged commit 9b2b6b2 into main Aug 2, 2026
2 checks passed
@malibio
malibio deleted the issue-1894-resolve-query-guidance branch August 2, 2026 01:27
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.

resolve_query is offered but not called for indirect-target updates (model-guidance gap)

1 participant