fix(experts): scope-filter claims before ranking entities - #715
Merged
plind-junior merged 4 commits intoJul 31, 2026
Merged
Conversation
rank_experts aggregated evidence density over every claim in the kb with no viewer/scope filtering at all, unlike every sibling claim-aggregating read surface (context.py, graph.py, digest.py, health.py, compile.py, and themes.detect_themes, the closest shape-wise sibling). a project- or agent-scoped claim the caller cannot otherwise retrieve still inflated claim_count, citation_count and score, and could surface verbatim in top_claim_ids - handing the caller a claim id it cannot fetch. filter claims through scoping.is_visible before they're eligible to contribute, defaulting viewer to scoping.viewer_from(...) when the caller passes none - matching detect_themes exactly. score after filtering rather than only scrubbing the id list afterward: a post-filter id scrub would still leave an entity whose evidence is mostly private outranking one the viewer can actually read. route the fts candidate fetch through scoped_fetch_limit so a mostly-out-of-scope kb doesn't starve the candidate pool before the filter runs, the same failure mode detect_themes already guards against. Fixes vouchdev#714
a6c6862 (vouchdev#686) fixed capture.load_config's min_observations and dedup_window_seconds to fall back to their defaults on a malformed config value via the coerce_numeric() helper, instead of raising ValueError straight out of load_config. 47eaf56 (vouchdev#645, realtime opt-in) branched off the pre-fix capture.py and reintroduced the bare int()/float() calls when it merged into test - the coerce_numeric import survived (nothing else referenced it), but the two call sites it fed didn't, silently reverting the fix and breaking ruff's unused-import gate for every PR built on top of `test`. restore the coerce_numeric() calls, matching recall.load_config's still-intact equivalent. unrelated to this PR's own change (experts.py viewer scoping); needed only to get CI green on top of a currently-broken `test`.
changelog union only; no source conflict.
changelog union only; no source conflict.
Contributor
|
diff coverage: n/a — this PR changes no python under |
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.
What changed
rank_expertsnow takes an optionalviewer: ViewerContext | None = None(defaulting to
scoping.viewer_from(config_path=store.config_path)) andfilters every claim through
scoping.is_visible(claim.scope, viewer)before it's eligible to contribute to an entity's ranking. The FTS
candidate fetch is routed through
scoping.scoped_fetch_limitso amostly-out-of-scope KB doesn't starve the candidate pool before the
filter runs.
Why
rank_expertsaggregated evidence density over every claim in the KB withno viewer/scope filtering at all — the one claim-aggregating read surface
that never got it. Every sibling (
context.py,graph.py,digest.py,health.py,compile.py, and especiallythemes.detect_themes, theclosest shape-wise sibling) already excludes claims the viewer can't
retrieve. A
project- oragent-scoped claim the caller cannot otherwisefetch still inflated
claim_count,citation_count, andscore, andcould surface verbatim in
top_claim_ids— handing the caller a claim idit has no access to. Filtering before aggregating (not just scrubbing the
id list afterward) matters:
claim_count,citation_count, andscoreare all computed over the same set, so post-filtering only the ids would
still leave an entity whose evidence is mostly private outranking one the
viewer can actually read.
Confirmed with a repro: an entity with 3 project-scoped claims (a project
the caller isn't in) plus 1 public claim reports
claim_count: 4andlists all 3 private claim ids in
top_claim_ids, regardless of caller —rank_expertshad no viewer parameter to even attempt scoping with.Fixes #714
What might break
Nothing for users with an existing
.vouch/directory — no on-disk shape,object model, or CLI/MCP/JSONL surface signature change (
vieweris aninternal, optional, keyword-only parameter with a config-resolved default,
mirroring
detect_themes's exact contract; none of the three surfacespass it explicitly yet, so every existing caller keeps working unchanged).
Behaviorally: a KB with more than one project/agent scope in use will see
kb.expertsresults narrow to what the caller can actually retrieve,which is the intended, documented behavior for every other read surface —
this was the one surface where it was missing.
VEP
Not applicable — no object model,
kb.*method signature, on-disklayout, bundle format, or audit-log shape change. An internal
scope-filtering correctness fix inside a read-only aggregation.
Tests
make check-equivalent: ruff clean (src+tests); mypyclean on
experts.py; alltests/test_experts.pycases pass(9 pre-existing + 1 new)
test_scopes_ranking_to_the_viewerCHANGELOG.mdupdated under## [Unreleased]