Skip to content

Scope find_skills' unscoped schema_metadata fallback to a query-named type - #2156

Merged
mstomar125 merged 2 commits into
mainfrom
worktree-issue-2148-scope-schema-metadata
Aug 19, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
worktree-issue-2148-scope-schema-metadata

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #2148

Problem

routing::declare_write_tool_fields (from #2120/PR#2150) declares create_node/update_node's field_values sub-properties from the retrieved candidates' schema_metadata. When more than one type's descriptor is present in that metadata, it unions their fields onto the write tool's declaration — safe, but imprecise compared to the golden corpus's hand-curated cases, which each declare exactly one type's fields.

The root cause: no seeded skill in skill_pipeline.rs declares node_types (the existing per-skill scoping mechanism in skill_ops::find_skills), so every candidate falls into the unscoped branch — up to MAX_UNSCOPED_SCHEMA_METADATA (5) non-core schemas, regardless of which type the turn actually concerns.

Why not per-skill node_types

The issue's own text suggests node_types declared on skills as the primary lever. I looked at this first, but it doesn't fit: the seeded skills whose tool_whitelist includes create_node/update_node — Node Creation and Graph Editing — are deliberately generic across every non-core type. There's no single static type list to give either without contradicting their purpose (and giving them the full type list is no different from today's unscoped fallback, so it wouldn't fix anything). None of the 8 seeded skills can get a meaningful static single-type node_types value.

Fix: a per-query narrowing pass

Added schema_named_in_query in packages/core/src/ops/skill_ops.rs: a purely mechanical, string-level check for whether the query text names exactly one non-core schema by id or display name (word-boundary matched, case-insensitive). find_skills' unscoped branch now uses this: when the query names exactly one non-core type, schema_metadata scopes to just that type; when it names zero or two-or-more, today's unscoped top-N fallback is unchanged.

This directly follows the issue's own "(or per-turn)" / "a narrower retrieval pass keyed to the specific tool call rather than the whole turn" alternative. It's deliberately conservative: no new embedding calls, no new tuned relevance thresholds, no attempt to resolve genuine ambiguity (2+ named types, or a request that implies a type without naming it, both fall through to the existing safe default unchanged) — matching the issue's explicit "not in scope: deciding which type a turn concerns when genuinely ambiguous."

Per-skill scoped_type_ids (when a skill does declare node_types, e.g. a future type-specific skill) is untouched — this only changes the unscoped-fallback branch.

Testing

  • 7 new unit tests for mentions_phrase/schema_named_in_query in skill_ops.rs (word-boundary matching, display-name matching, ambiguous/no-match fallthrough, core-schema exclusion).
  • Full cargo test -p nodespace-core (1162 passed) and cargo test -p nodespace-agent --lib (507 passed) green, including the pinned no_seeded_skill_scopes_its_schema_metadata test (still holds — this change adds no node_types to any seed, it's a separate per-query mechanism, documented explicitly in that test's updated doc comment).
  • prompt_assembly_snapshot gate: unaffected and unchanged (its stage2_tool_surface_matches_golden test drives declare_write_tool_fields/stage2_tools off hand-built fixture_candidates(), not find_skills, so no golden update was needed — confirmed by running the gate, all 5 snapshot tests pass with no diff).
  • Not measurable via golden_runner: it bypasses retrieval entirely (hand-authored schema_metadata per case, no daemon/DB/embedding calls — see its own doc comment), so this fix — a production retrieval-mechanism change — isn't something the golden corpus can exercise. Verified via unit tests and the doc-comment reasoning above instead.
  • cargo clippy -p nodespace-core --all-targets: clean. cargo fmt --check: clean.
  • Full pre-push gate (bun run test:all + cargo build --bin nodespaced + bun run test:e2e + cargo test -p nodespace-app) passed locally before push.

🤖 Generated with Claude Code

… type

find_skills' unscoped fallback attached up to MAX_UNSCOPED_SCHEMA_METADATA
non-core schemas to every candidate regardless of which type the request
actually concerned, since no seeded skill declares node_types (the existing
per-skill scoping mechanism). declare_write_tool_fields then unions every
attached type's fields onto a write tool's field_values declaration, which
is safe but imprecise when only one type is actually relevant.

Per-skill node_types can't fix this for the skills that whitelist
create_node/update_node (Node Creation, Graph Editing): both are
deliberately generic across every non-core type, so there's no single
static type list to give them without contradicting their purpose.

Add a per-query narrowing pass instead: when the query text names exactly
one non-core schema by id or display name (schema_named_in_query), scope
schema_metadata to just that type. Two or more named types, or none, leaves
today's unscoped top-N fallback untouched — this only narrows the
determinable case, it doesn't attempt to resolve genuine ambiguity.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…tradeoff

mentions_phrase tokenized the phrase argument with split_whitespace() while
tokenizing the haystack on any non-alphanumeric character. A multi-token
schema id with no internal whitespace (release_plan, pull-request) could
therefore never match via the id path, since the haystack's tokenization
splits "release plan" into separate tokens that never equal the single
unsplit "release_plan" word. Masked in the original tests, which only used
single-word ids. Tokenize both sides identically.

Also documents the accepted tradeoff that a lexical match can be a false
positive (a schema id/name that happens to be a common word), narrowing to
a confidently wrong type rather than the old broad fallback — tracked in a
follow-up issue rather than guarded here, since a guard needs its own
measurement to avoid suppressing true positives.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mstomar125
mstomar125 merged commit 505a7b4 into main Aug 19, 2026
@mstomar125
mstomar125 deleted the worktree-issue-2148-scope-schema-metadata branch August 19, 2026 07:52
mstomar125 added a commit that referenced this pull request Aug 20, 2026
… leave-as-is decision (#2177)

* Measure schema_named_in_query's lexical false-positive rate; document the leave-as-is decision (closes #2158)

core#2148/#2156's lexical narrowing scores 0% false positives against
every non-core schema name with real precedent in this codebase (ticket,
adr, release, release_plan, venue, invoice, equipment) over a 52-query
corpus drawn from the golden fixtures and everyday PKM-assistant queries.

It is not low for schema names that are themselves common English words
(Note, Meeting, Idea, Goal, ...), plausible in NodeSpace's own domain: a
measured 2.2% false-positive rate (33/1508 pairs across 29 such names),
reproducing the review's own worked example. No lightweight guard is
added, because a length floor or stopword list can't separate that risk
from true positives — every one of those 29 words is also the exact word
a genuine positive query for the same type would use, confirmed by a
dedicated true-positive check. The narrowing is left as-is: the doc
comment on schema_named_in_query now records the measured rates and the
bound on worst-case harm (with_declared_field_values never closes
field_values with additionalProperties: false, so a wrong narrow loses a
precision hint rather than blocking the correct write).

Adds two pinned Rust tests encoding the corpora and measured results, so
a future change to the matcher has to deliberately update this record
rather than silently drift from it.

Includes incidental cargo fmt fixes to routing.rs and
prompt_assembly_snapshot.rs picked up by quality:fix.

* Pin the risky-name aggregate false-positive count as a real Rust assertion

Adversarial review of PR #2177 (core#2158) found that the 33/1508 (2.2%)
false-positive rate for common-word schema names was only reported in
prose/doc comments — only 2 of the 1508 pairs were actually asserted in
code, so a future change to mentions_phrase could silently double the
real rate with CI staying green.

Adds risky_schema_names() (the same 29-name corpus already described in
the doc comment) and a new test that loops it pairwise against
realistic_unrelated_queries() and asserts the exact aggregate count
(33, 1508), matching the isolated-schema methodology the doc comment's
"29 names x 52 queries = 1508 pairs" already claimed. The prior
two-example test is kept as a readable, concrete illustration alongside
the pinned aggregate, plus a paired false-positive/true-positive check on
the same word ("log") to keep the "no lexical signal separates them"
claim verifiable in code as well as prose.
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.

Scope skill schema_metadata retrieval per node_types, so write-tool field declarations target one type

1 participant