Repository navigation
Measure schema_named_in_query's lexical false-positive rate; document leave-as-is decision - #2177
Conversation
… 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.
|
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 Local verification after the fixup commit:
Merging. |
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 namedNote), narrowingschema_metadatato 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_queryfunctions (now pinned as Rust tests, not just an ad hoc script):ticket,adr,release,release_plan,venue,invoice,equipment(drawn frompackages/agent/goldens/*.toml, this module's own tests, and theVenue/Invoiceexamples in ADR-063 andschema-management.md).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 frompackages/agent/goldens/*.toml(this project's own dev-workflow query corpus) plus a hand-built everyday-PKM-assistant corpus.Results:
Notenarrows 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
Logschema 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 inmentions_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 setsadditionalProperties: falseonfield_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: rewroteschema_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.schema_named_in_query_measured_zero_false_positives_on_precedent_schema_names(+ a companion true-positive check) andschema_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.cargo fmtfixes topackages/agent/src/local_agent/routing.rsandpackages/agent/tests/prompt_assembly_snapshot.rs, picked up byquality: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::routingand--test prompt_assembly_snapshot— unaffected by the fmt-only changes.bun run quality:fixclean (cargo clippy --all-targets -D warnings -D clippy::unused-asyncclean workspace-wide).bun run test:allpassed.🤖 Generated with Claude Code