Skip to content

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

Closed

Description

@mstomar125

Context

core#2148 (#2156) added `schema_named_in_query` in `packages/core/src/ops/skill_ops.rs`: when a request's query text names exactly one non-core schema by id or display name (a purely mechanical, word-boundary string match), `find_skills`' unscoped fallback scopes `schema_metadata` to just that one type instead of the previous top-5 list.

The risk, flagged in review of #2156

The old unscoped fallback was imprecise but safe-by-breadth: it always included every plausible non-core type (up to 5), so the correct type was very likely present even when the fallback couldn't narrow further.

The new mechanism can be confidently wrong instead: if a user-defined schema's id or display name happens to also be a common English word or phrase — e.g. a schema literally named `Note` — a query like "please note that the meeting moved to 3pm" would lexically match that schema and narrow `schema_metadata` to it alone, potentially excluding the type the request actually concerns. Confidently-wrong-and-narrow is a different, arguably worse, failure mode than vaguely-broad.

This is a known, accepted tradeoff for #2156 (bounded blast radius — see that PR's discussion: it only affects one prompt-assist channel's precision, not write-path validation, which still enforces the real schema server-side), not a regression that blocked merge. Filed as a deliberate follow-up rather than fixed ad hoc, since a fix requires either:

  • measurement-backed guardrails (e.g. excluding common English words/stopwords from lexical matching — needs testing against real usage to avoid suppressing true positives), or
  • switching to (or blending with) the embedding-based semantic search infrastructure already used for skill matching (`semantic_search_nodes` over `node_type = "schema"`, structurally available per Scope find_skills' unscoped schema_metadata fallback to a query-named type #2156's PR description but deliberately not used to keep that PR minimal and measurement-free)

Both directions need their own measurement per ADR-038/064 methodology, which is why this is a separate, unblocked-from-#2156 issue rather than scope creep on it.

What's needed

  • Decide whether to add a lightweight, defensible guard (e.g. a minimum-length or common-word exclusion list) to `mentions_phrase`/`schema_named_in_query`, or move the narrowing pass to embedding-based schema search (reusing the same infra `find_skills` already uses for skill matching), or leave as-is with the tradeoff formally documented (already partially done in Scope find_skills' unscoped schema_metadata fallback to a query-named type #2156's code comments) if the practical risk is judged low enough (schema names are typically domain-specific nouns, not common verbs/phrases).
  • If pursuing a guard or embedding-based approach, measure using representative dev-domain schema names/queries (per the corpus's existing golden methodology) rather than guessing at a threshold or word list.
  • No behavior change is required to close this issue if the deliberate decision is "leave as documented" — but that decision should be made explicitly, not by default neglect.

Not in scope

Redesigning `find_skills`' retrieval pipeline wholesale, or building new embedding infrastructure beyond what already exists for skill/schema-type search.

Activity

  1. mstomar125 commented on Aug 20, 2026

    @mstomar125
    ContributorAuthor

    Closed via #2177 (squash-merged d20ee3b). No production behavior changed — this was a measurement-then-decide issue, same shape as #2159's negative result for #2147.

    What was measured

    Built two corpora and ran them against the real mentions_phrase/schema_named_in_query code (now pinned as Rust tests in packages/core/src/ops/skill_ops.rs, not an ad hoc script):

    1. Precedent schema names — every non-core schema id/display-name with actual precedent anywhere in this codebase (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/schema-management.md).
    2. Risky common-word names — 29 plausible-but-unprecedented names a NodeSpace user could realistically 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 plus a hand-built everyday-PKM-assistant corpus).

    Results (pinned by Rust test assertions, verified independently by the adversarial reviewer via a fresh checkout + toolchain):

    • 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%) — real and reproducible, including the review's own worked example almost verbatim ("please note that the meeting moved to 3pm" narrows a schema named Note).

    Decision: (a) leave as-is, formally documented

    No lexical guard (length floor, stopword list) was added, because none survives the measurement: every one of the 29 risky words is also the exact word a genuine true-positive query for that same type would use (verified — 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 available to mentions_phrase that separates the two cases, so a guard would suppress true positives at the same rate as false ones — exactly the failure mode the issue warned against, now confirmed rather than assumed.

    The narrowing is left as-is because the failure mode is bounded even in the worst case: with_declared_field_values never sets additionalProperties: false on field_values, and the tool's own description 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 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). Outcome (c), embedding-based semantic matching, is reserved for when (a)/(b) both prove inadequate — (a) is not inadequate once the harm is bounded like this, so (c) was not pursued.

    The doc comment on schema_named_in_query now records the measured rates, corpora, and this reasoning directly, and two Rust tests pin the aggregate results as durable regression checks — a future change to the matcher has to deliberately update this record rather than silently drift from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions