You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(knowledge): hold the research quarantine on relation expansion and the category graph path (#16665) - #21956
Single-issue rationale: the four gaps are the remaining AC3 items of #16665 and share one helper; no other issue touches these files.
Thinking Path
AC3: the research quarantine holds on every route that has it. Four gaps remained. Two read facts straight from Redis hashes (metadata is a JSON string), so they never pass the KB.search gate and need the canonical predicate applied by hand; one is a trace; one is a missing behavioural test.
What Changed
Gap
Change
1. /multi-source/search related facts
_related_fact_is_accessible (api/knowledge_search_aggregator.py) now also withholds a quarantined target/source fact. It is the one gate for _expand_fact_relations and the /context citation path.
2. /multi-source/graph category path
get_facts_in_category (knowledge/categories.py) drops quarantined facts at the single choke point. Its callers are the graph route and the categories route; neither needs quarantined facts, so no include_quarantined opt-out is added.
3. rag_legskb_adapter.search
Trace: services/rag_legs.pyself.kb_adapter.search -> services/knowledge_base_adapter.pyself.kb.search(...) (both the V1 and V2 branches) -> KnowledgeBase.search in knowledge/search.py, which ends in gate_response. It reaches the gate, so no code change. The existing matrix test used a fake that gated itself, so a new test runs the real SearchMixin.search through the adapter.
4. /query (kb_librarian)
Behavioural route-level test added.
Shared helper: is_quarantined_hash / drop_quarantined_hashes in knowledge/quarantine.py wrap the existing is_quarantined for raw hashes, parsing metadata with the existing _decode_redis_hash codec. No second predicate.
Tests: api/knowledge_quarantine_gaps_16665_test.py (gaps 1 and 2, with a sensitivity control), api/knowledge_rag_matrix_16665_test.py (gap 3), api/kb_read_routes_visibility_16665_test.py (gap 4). tools/lint/check_no_kb_aioredis_access.py allowlists the new test fake, which needs the Redis-present guard.
Line counts, this branch vs origin/main: api/knowledge_search_aggregator.py 899 vs 899; knowledge/categories.py 963 vs 965.
Known limit: get_facts_in_category filters the page after pagination, so total_count and has_more still count quarantined ids and a page may be short. The graph route already tolerates short batches. Tracked in #21957 (exact count needs a quarantine-aware index).
Verification
Tests not run locally (owner rule: CI gates). ruff check clean on changed files apart from two E402 findings already on main in the aggregator; black --check --line-length=120 clean. CI result to follow.
Model Used
Claude Sonnet 5.5
Summary by CodeRabbit
Bug Fixes
Quarantined facts are excluded from category listings, graph-based results and related-fact search results.
Search and context responses continue to include accessible, non-quarantined facts, including shared facts.
Quarantine filtering is consistent across knowledge browsing and search, so quarantined information is not shown in results for standard or administrative accounts.
No actionable comments were generated in the recent review.
Walkthrough
The change adds quarantine checks for category facts and related facts reached through graph expansion. Tests cover category paths, multi-source search, librarian, advanced search and context routes.
New helpers detect quarantined Redis hashes and remove them from collections. Category retrieval applies this filter. Tests cover category listings and graph paths, including a control case without quarantine metadata.
Filter related facts autobot-backend/api/knowledge_search_aggregator.py, autobot-backend/api/knowledge_quarantine_gaps_16665_test.py
Related facts are rejected when quarantined, in addition to being rejected when missing. Tests cover quarantined related facts and an open target reached from a quarantined source.
Tests cover the librarian, advanced search and context routes. They verify that quarantined facts are absent when the gate is active and present in a gate-bypass sensitivity case. The lint allowlist includes the new quarantine test file.
Merge Risk: Minimal · previous review 387cb
This change withholds quarantined research facts from related-fact results and from category listings and graph paths. No outstanding merge-blocking defects were found. Category counts may be slightly off until the follow-up issue lands.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: holding the research quarantine on relation expansion and the category graph path. The raw summary confirms related-fact filtering in knowledge_search_aggregator.py, q…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: holding the research quarantine on relation expansion and the category graph path. The raw summary confirms related-fact filtering in knowledge_search_aggregator.py, quarantine filtering in categories.py via drop_quarantined_hashes, and new helpers in quarantine.py. The title is specific and matches the changeset. The title's length (103 characters) is at the upper end of concise, but it is still readable and within the expected scope.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Notice: 28 open PRs — past the runaway threshold (25)
This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.
This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.
If the queue is draining normally, ignore this. Otherwise:
Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
Look for a loop opening near-identical PRs
Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
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
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.
Refs #16665
Single-issue rationale: the four gaps are the remaining AC3 items of #16665 and share one helper; no other issue touches these files.
Thinking Path
AC3: the research quarantine holds on every route that has it. Four gaps remained. Two read facts straight from Redis hashes (
metadatais a JSON string), so they never pass theKB.searchgate and need the canonical predicate applied by hand; one is a trace; one is a missing behavioural test.What Changed
/multi-source/searchrelated facts_related_fact_is_accessible(api/knowledge_search_aggregator.py) now also withholds a quarantined target/source fact. It is the one gate for_expand_fact_relationsand the/contextcitation path./multi-source/graphcategory pathget_facts_in_category(knowledge/categories.py) drops quarantined facts at the single choke point. Its callers are the graph route and the categories route; neither needs quarantined facts, so noinclude_quarantinedopt-out is added.rag_legskb_adapter.searchservices/rag_legs.pyself.kb_adapter.search->services/knowledge_base_adapter.pyself.kb.search(...)(both the V1 and V2 branches) ->KnowledgeBase.searchinknowledge/search.py, which ends ingate_response. It reaches the gate, so no code change. The existing matrix test used a fake that gated itself, so a new test runs the realSearchMixin.searchthrough the adapter./query(kb_librarian)Shared helper:
is_quarantined_hash/drop_quarantined_hashesinknowledge/quarantine.pywrap the existingis_quarantinedfor raw hashes, parsingmetadatawith the existing_decode_redis_hashcodec. No second predicate.Tests:
api/knowledge_quarantine_gaps_16665_test.py(gaps 1 and 2, with a sensitivity control),api/knowledge_rag_matrix_16665_test.py(gap 3),api/kb_read_routes_visibility_16665_test.py(gap 4).tools/lint/check_no_kb_aioredis_access.pyallowlists the new test fake, which needs the Redis-present guard.Line counts, this branch vs
origin/main:api/knowledge_search_aggregator.py899 vs 899;knowledge/categories.py963 vs 965.Known limit:
get_facts_in_categoryfilters the page after pagination, sototal_countandhas_morestill count quarantined ids and a page may be short. The graph route already tolerates short batches. Tracked in #21957 (exact count needs a quarantine-aware index).Verification
Tests not run locally (owner rule: CI gates).
ruff checkclean on changed files apart from two E402 findings already on main in the aggregator;black --check --line-length=120clean. CI result to follow.Model Used
Claude Sonnet 5.5
Summary by CodeRabbit