Skip to content

Measure schema_named_in_query's lexical false-positive rate; document leave-as-is decision - #2177

Merged
mstomar125 merged 2 commits into
mainfrom
worktree-issue-2158-schema-lexical-guard
Aug 20, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
worktree-issue-2158-schema-lexical-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #2158

What this is

core#2158's acceptance bar required real measurement before deciding among its three documented outcomes (leave as-is / add a lightweight guard / move to embedding-based search) — not guessing at the risk core#2148/#2156's review flagged: schema_named_in_query's lexical match can be a false positive if a user-defined schema's id/display name happens to also be a common English word (e.g. a schema literally named Note), narrowing schema_metadata to a confidently WRONG type instead of the old broad-but-safe top-N fallback.

No production behavior changed. This is a measurement + documentation PR, same shape as #2159's negative result for core#2147.

What was measured

Two corpora, tested against the real mentions_phrase/schema_named_in_query functions (now pinned as Rust tests, not just an ad hoc script):

  1. Precedent schema names — every non-core schema id/display-name that actually appears anywhere in this codebase's tests, golden fixtures, or docs: ticket, adr, release, release_plan, venue, invoice, equipment (drawn from packages/agent/goldens/*.toml, this module's own tests, and the Venue/Invoice examples in ADR-063 and schema-management.md).
  2. Risky common-word names — 29 plausible-but-unprecedented names a NodeSpace user could give a custom type, since NodeSpace is a personal knowledge tool, not only a dev tracker: note, meeting, idea, goal, plan, record, item, event, contact, order, review, report, request, log, entry, message, post, draft, file, link, alert, reminder, question, answer, update, change, book, recipe, habit.

Both checked against a 52-query corpus: verbatim user = "..." turns from packages/agent/goldens/*.toml (this project's own dev-workflow query corpus) plus a hand-built everyday-PKM-assistant corpus.

Results:

  • Precedent names: 0/364 false positives (0%). The risk did not reproduce at all for domain-specific names.
  • Risky common-word names: 33/1508 false positives (2.2%), including the review's own worked example almost verbatim: a schema named Note narrows on "please note that the meeting moved to 3pm".

Why no guard was added despite the confirmed risk: every one of the 29 risky words is also the exact word a genuine true-positive query for that same type would use (verified separately — e.g. a Log schema is correctly found by "add a log for today's workout" using the identical token that falsely matches "log me out of this session"). There's no lexical signal in mentions_phrase's input that separates the two cases, so a length floor or stopword list would suppress true positives at the same rate it suppresses false ones — exactly the failure mode the issue warned against, now confirmed rather than assumed.

Why leave-as-is is still the right call: the failure mode is bounded even in the worst case. with_declared_field_values (packages/agent/src/local_agent/tools.rs) never sets additionalProperties: false on field_values, and its own tool description explicitly instructs the model to add any key the user supplied that the declared list doesn't cover — so a wrong narrow degrades to "no typed hint for the correct type's fields this turn, plus some irrelevant ones," never to "the model cannot express the correct write." Write validation still enforces the real schema at the write boundary regardless of what this function returns (already documented in #2156). Embedding-based semantic matching (outcome (c)) is explicitly reserved for when (a)/(b) both prove inadequate — (a) is not inadequate here once the harm is bounded like this, so (c) isn't pursued.

Changes

  • packages/core/src/ops/skill_ops.rs: rewrote schema_named_in_query's doc comment to record the measured rates, the corpora, and the reasoning above instead of the prior "not guarded against here, needs its own measurement" placeholder.
  • Added two pinned tests: schema_named_in_query_measured_zero_false_positives_on_precedent_schema_names (+ a companion true-positive check) and schema_named_in_query_confirmed_false_positive_class_common_word_schema_names, encoding the corpora and results as a durable regression pin — a future change to the matcher has to deliberately update this record rather than silently drift from it.
  • Incidental cargo fmt fixes to packages/agent/src/local_agent/routing.rs and packages/agent/tests/prompt_assembly_snapshot.rs, picked up by quality:fix (pre-existing formatting drift, unrelated to this change).

Testing

  • cargo test -p nodespace-core --lib — 1175 passed.
  • cargo test -p nodespace-agent --lib local_agent::routing and --test prompt_assembly_snapshot — unaffected by the fmt-only changes.
  • bun run quality:fix clean (cargo clippy --all-targets -D warnings -D clippy::unused-async clean workspace-wide).
  • bun run test:all passed.
  • Full pre-push gate passed on push.

🤖 Generated with Claude Code

… 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.
…rtion

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

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review's one should-fix finding (the 33/1508 aggregate for the risky-name corpus was only reported in prose, not pinned by a loop-based assertion). Added risky_schema_names() and schema_named_in_query_measured_false_positive_rate_on_risky_common_word_names, which loops the 29 risky names pairwise against the 52-query corpus and asserts the exact aggregate (33, 1508) — matching the isolated-schema methodology the doc comment already claimed. Verified the assertion passes against the real mentions_phrase/schema_named_in_query code (not just the earlier Python reimplementation). All other review findings were non-blocking limitations, recorded for a possible future follow-up rather than required here.

Local verification after the fixup commit:

  • cargo test -p nodespace-core --lib — 1176 passed, 0 failed.
  • cargo fmt -p nodespace-core -- --check — clean.
  • cargo clippy -p nodespace-core --lib -- -D warnings — clean.
  • Pre-push gate passed on both pushes (ed60045, 4e25201).

Merging.

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.

schema_named_in_query: a lexical false-positive narrows to a confidently WRONG type instead of the old broad fallback

1 participant