Repository navigation
Scope find_skills' unscoped schema_metadata fallback to a query-named type - #2156
Merged
Merged
Conversation
… 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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2148
Problem
routing::declare_write_tool_fields(from #2120/PR#2150) declarescreate_node/update_node'sfield_valuessub-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.rsdeclaresnode_types(the existing per-skill scoping mechanism inskill_ops::find_skills), so every candidate falls into the unscoped branch — up toMAX_UNSCOPED_SCHEMA_METADATA(5) non-core schemas, regardless of which type the turn actually concerns.Why not per-skill
node_typesThe issue's own text suggests
node_typesdeclared on skills as the primary lever. I looked at this first, but it doesn't fit: the seeded skills whosetool_whitelistincludescreate_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-typenode_typesvalue.Fix: a per-query narrowing pass
Added
schema_named_in_queryinpackages/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_metadatascopes 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 declarenode_types, e.g. a future type-specific skill) is untouched — this only changes the unscoped-fallback branch.Testing
mentions_phrase/schema_named_in_queryinskill_ops.rs(word-boundary matching, display-name matching, ambiguous/no-match fallthrough, core-schema exclusion).cargo test -p nodespace-core(1162 passed) andcargo test -p nodespace-agent --lib(507 passed) green, including the pinnedno_seeded_skill_scopes_its_schema_metadatatest (still holds — this change adds nonode_typesto any seed, it's a separate per-query mechanism, documented explicitly in that test's updated doc comment).prompt_assembly_snapshotgate: unaffected and unchanged (itsstage2_tool_surface_matches_goldentest drivesdeclare_write_tool_fields/stage2_toolsoff hand-builtfixture_candidates(), notfind_skills, so no golden update was needed — confirmed by running the gate, all 5 snapshot tests pass with no diff).golden_runner: it bypasses retrieval entirely (hand-authoredschema_metadataper 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.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