[Bug]: context-mode exclude_uris is exact-match only, but recallExcludeUris documents subtree semantics
Problem Statement
exclude_uris in a context-mode search request is matched exactly, so passing a directory URI to keep a whole noisy subtree out of the hits is a silent no-op.
openviking/retrieve/context_assembler/params.py—normalize_exclude_uris()builds a plainset[str]of the strings passed in.openviking/retrieve/context_assembler/gather.py—_build()drops a hit only viauri in excluded or base_uri in excluded.
Verified against a live 0.4.22 server (context mode, a query that matches skills):
| request | response |
|---|---|
no exclude_uris |
6411 bytes, 4 agent/skills mentions |
exclude_uris: ["viking://agent/skills", "viking://user/<space>/resources", ...] |
6412 bytes, the same 4 mentions — byte-identical apart from the echo |
exclude_uris: ["viking://agent/skills/daily-brief/SKILL.md"] (exact child URI) |
that entry is filtered out |
/api/v1/search/find and non-context /search/search reject the field outright (400), which is fine and documented — the gap is only the exact-match semantics inside context mode.
Why this bites the plugin
examples/memory-plugin-shared/lib/config-schema.mjs documents recallExcludeUris as:
Subtree URIs the recall search must never return. Without this there is no way to keep generated directory files (viking://user/<space>/skills, viking://user/<space>/resources, viking://agent/skills) out of the hits: they match like ordinary content and carry only boilerplate text.
So the knob's stated purpose is exactly the parent-directory use case the server silently ignores. (The API docs for exclude_uris itself describe it as a stateless dedup fallback — both readings are legitimate, but the plugin config promises subtrees.)
Proposed Solution
gather.py already has _is_under() in the same file (used by origin_for_uri). The exclude check could reuse it, e.g.:
if any(_is_under(uri, x) for x in excluded) or any(_is_under(base_uri, x) for x in excluded):
- exact-URI callers keep working (
_is_underincludes equality), - same-named sibling directories are not caught (the edge case #1170 called out for
ov grep --exclude-uri, which already established subtree semantics for exclusion), - and
_overfetch()already compensates for post-retrieval drops, so subtree excludes get the refill behavior too.
Related, smaller gap: examples/memory-plugin-shared/lib/agent-hook-runtime.mjs never reads cfg.recallExcludeUris into the recall options, so even with exact URIs the knob is currently a dead key for the hook runtime (only buildContextSearchBody would forward options.excludeUris if it were passed).
Alternatives Considered
Filtering prefixes on the entries client-side (in recall-core, after assembly and on the raw hits of the fallback path) works and is server-version-proof — that is our current workaround. But a server-side subtree match also restores the overfetch refill a client filter cannot do.
Environment
- Server: 0.4.22
- Plugin:
examples/memory-plugin-sharedas shipped with the agent-hook integration (zcode)
Happy to turn the gather.py suggestion into a PR if the direction sounds right.
One scope detail for the proposed _is_under change: the existing overfetch does not guarantee refill for a subtree. On current main 9d9bc85e, it requests want + min(len(excluded), want * 2), so one parent exclusion adds only one candidate regardless of the number of descendants.
I checked the real assemble_context() entry with a synthetic search that honors its requested top-N limit. For limit=2, with three higher-ranked noisy/*.md hits followed by two quiet/*.md hits:
| Exclusion | Retrieval limit | Current code | Only replacing equality with _is_under |
|---|---|---|---|
| Three exact noisy file URIs | 5 | Two quiet entries | Two quiet entries |
| One noisy parent URI | 3 | Two noisy entries | Empty entries; all three fetched hits excluded |
| Parent with trailing slash | 3 | Two noisy entries | Empty entries |
Same-name prefix sibling (noi) |
3 | Two noisy entries | Two noisy entries, preserved |
The prefix change restores suppression, but this bounded overfetch is separate from filling the requested width. That distinction should be part of the exclusion contract/validation before promising refill. No live index, HTTP server, or model calls in this check; the temporary control change was restored. The plugin wiring portion also has existing #5436.