Repository navigation
fix(knowledge): read the context search's config off the event loop - #22222
Conversation
search_for_context stat'ed and read the gateway's config.json inside the coroutine. #22084's fs gate flags that call; its baseline row named handlers/knowledge.py, but #22073 had already moved search_for_context into knowledge_agent_context.py, so main's ratchet lane reads one new offender plus one stale row (red since 28ee969). The read now runs in _read_knowledge_config on asyncio.to_thread (the path is the gateway's own, not the request's). The stale knowledge.py row is pruned with --update-baseline, and test_knowledge_onloop_fs.py drops the on-loop allowance for that call and proves the read leaves the loop thread. Refs #22209
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] ba4c6a4 Description read[DESCRIPTION-READ] 5f3f396e89ba952f262ab50ecd88247bd5861c7bbdceed04338577927208f80d That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check that the ratchet lane is green on a fresh rebase. The baseline is path-keyed, and the race that caused this could happen again. What this change shipsInventory (5 items) — 5 justifiedIntent: get main's ratchet lane green again by moving the chat context search's
[FIRST-PRINCIPLES-REVIEWED] ba4c6a4 Description read[DESCRIPTION-READ] 6d8e6f1e2fda59242f064df224cd4bd745e029f6a0a9c42a40286e0129444d2d That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
bolichen97
left a comment
There was a problem hiding this comment.
Looks good to ship. One maintainer check remains before approval: the required checks on this head.
Head reviewed: 46d2e0d. Bots read: Design PASS, First Principles PASS, UX skipped, Opus no blocking findings, GPT no blocking findings. Readiness is action required.
What I checked:
- The diff matches the description.
_read_knowledge_config()keeps every fallback of the old inline read: a missing, unreadable, malformed or wrong-typed file or block still gives{}. - The path comes from
data_home(), not from the request. So the default executor throughasyncio.to_threadis the correct lane, not the bounded probe pool. - The facade manifest entry is needed. The facade mirror makes
monkeypatch.setattr(kh, "data_home", ...)reach the owner module, so the new test patches the real reader. - The baseline edit only removes one row. No count goes up and no row is added.
- I ran these at this head:
test_knowledge_onloop_fs.py,test_facade_mirror_guards.pyandtest_knowledge_handlers_facade.py(84 passed). I also rancheck_sync_io_in_async.pyon the whole tree (pass, 138 known calls in 57 files). - I put the old inline read back and ran the new test again. It fails with
[('exists', 'MainThread')], and the static ratchet test also fails. So both tests go red if the fix regresses.
Why I do not approve yet: the backend test shards were skipped on this head because the Fast Gate is red. The Coverage Gate fails closed for the same reason, and the Harness Parity Gate shows the known allowlist failure from main. None of these come from this diff. When main is green again and readiness shows passed on this head, this is ready to approve and merge.
No must-fix or should-fix findings.
bolichen97
left a comment
There was a problem hiding this comment.
Approving at head ba4c6a4.
This head only merges main into the branch. The PR's own patch is byte-identical to the one I reviewed at 46d2e0d (same four files, same 172-line diff), so my earlier review still holds: 0 findings, and both new tests fail if the old on-loop config read is put back.
Gates checked on this head:
- Readiness is
passed. - CI is green, including all eight Linux backend shards, all eight Windows backend shards, Coverage Combine and Coverage Gate. These were the checks that were red or skipped before.
- Harness Parity Gate, Static Ratchet Gate and the AI review lanes (Design, First Principles, Opus, GPT) all pass, with no blocking finding.
- The branch is mergeable into main. No security denylist path is touched, and the
.github/change only removes one row from a baseline data file.
Problem / Motivation
Goal: Main's ratchet lane goes green again by moving the chat context search's
config.jsonread off the event loop.Main Ratchet Audit→Backend ratchet & baseline gateshas failed on every main push since28ee969f83(#22084, 07:09 PDT 10-19; first red run 39266424032, jobBackend ratchet & baseline gates), tracked by #22209. Only one step fails,Check for blocking IO inside async def, on the fs ledger:Every other gate in the lane passes. The same gate runs on pull requests, so each PR inherits this red.
Why it matters
The red hides any real drift a later push adds to that lane, and every open PR carries it. The flagged call itself is also a real stall:
search_for_contextstat'ed and readconfig.jsonon the loop, so a home on a mount that stopped answering would hold every endpoint until the kernel gave up.Not a goal
check_harness_parity.pyallowlist red, which test: clear main's four reds left by #21753, #21598 and later backend edits #22178 and fix(ci): drop the proven claude member-capabilities allowlist entry #22186 cover.What changed (motivation → approach → change)
handlers/knowledge.pyinto owners and movedsearch_for_contextintoknowledge_agent_context.py. ci(sync-io): gate filesystem syscalls inside async def #22084 (07:09 PDT) added the fs gate with a baseline built on an older base, where that call still sat inhandlers/knowledge.py. On the merged tree the call reads as a new offender and its old row as stale._read_knowledge_config(), whichsearch_for_contextawaits withasyncio.to_thread, as the other dashboard handlers that read the gateway's own config do. The path is the gateway's own (data_home()), never the request's, so the default executor is the lane the gate names, not the bounded request-path probe pool. Behaviour is unchanged: a missing, unreadable, malformed or wrong-typed file orknowledgeblock still reads as{}.handlers/knowledge.pyrow is removed by the gate's own--update-baseline(shrink-only: one line deleted, no count raised, no row or marker added).handlers/knowledge.py(the facade) lists the new helper in itsTYPE_CHECKINGmanifest, whichtest_facade_mirror_guards.pyrequires.Backwards compatibility
Compatible: the route, its query parameters, its response and its config fallbacks are unchanged; only the thread the config read runs on moves.
Removes nothing: the one deleted line is a baseline row for a file that no longer has the offence, and the test allowance dropped was the on-loop exception for this same call.
Tests
test_knowledge_onloop_fs.py::TestStaticRatchet::test_no_coroutine_touches_the_filesystem_on_the_loop: the("search_for_context", "exists")on-loop allowance is gone, so the ratchet now refuses that call. It fails on main's code (search_for_context:83 exists) and passes here.TestSearchForContext::test_config_read_runs_off_the_loop: serves the route against a realconfig.json(itsfetch_max_tokensreaches the response, so the read happened) and asserts the file is never touched on the loop's thread. It fails on main's code ([('exists', 'MainThread')]) and passes here.RATCHET_SCOPE_WHOLE_TREE=1, as the lane does:check_sync_io_in_async.py --testand the gate itself (pass, 138 known calls in 57 files), plus the lane's black, file-line-cap, subprocess-encoding, acp-frame-host-data, agent-sdk-boundary, cwd-relative-reads and lockdown gates and its census + config-baseline tests (all pass).test_knowledge_onloop_fs,test_sync_io_in_async_gate,test_knowledge_handlers_facade,test_facade_mirror_guards,test_knowledge_handlers_coverage*,test_cse_2026_08_05_fixes,test_no_config_dir_in_async,test_knowledge_cross_thread,test_knowledge_search_upgrade,test_campaign_facades_base_public_names,test_config_json_bom,test_json_object_body_guard,test_knowledge_owner_gate.Manual verification
N/A — unit coverage sufficient: the change only moves a read onto a worker thread, and the tests above prove both the thread and the read's result.
Related Issues
Refs #22209 (the audit workflow closes it on the next all-green main push). Cause: #22073 + #22084.
Pattern harvest
Rule candidate: review-prompt
Pattern: a PR that adds a path-keyed baseline must rebuild it on current main right before merge; a file split that lands first moves rows to new paths (here #22073 vs #22084).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.