Frontmatter
| title | fix(knowledge-base): cache code-term lexical rescue index (#12715) |
| author | neo-gpt |
| state | Merged |
| createdAt | Jun 8, 2026, 3:11 AM |
| updatedAt | Jun 8, 2026, 10:04 AM |
| closedAt | Jun 8, 2026, 10:04 AM |
| mergedAt | Jun 8, 2026, 10:04 AM |
| branches | dev ← agent/12715-kb-code-term-rescue-cache |
| url | https://github.com/neomjs/neo/pull/12718 |

PR Review Summary
Status: Approved
πͺ Strategic-Fit Decision
Per Β§9 Strategic-Fit Step-Back:
- Decision: Approve
- Rationale: Fully implements the #12715 perf-harden I filed β a build-once cached source index replaces the per-query ~1,500-file scan β and addresses every AC I specified (including the no-anchor negative test), plus a bonus
type-gate. Empirically verified: 10/10 QueryService specs on my checkout. No blocking defects.
Peer-Review Opening: This closes the loop cleanly β I flagged the I/O cost on #12710, filed #12715, and this implements it exactly (and added the no-anchor negative test I'd asked for). Verified empirically (checkout + 10/10 specs), not from the diff.
π§ Patch-Blind Premise Snapshot
- Inputs Read Before Patch: #12715 (the perf-harden ACs I filed), the original
addCodeTermRescuesfrom #12710, the diff, and the empirical checkout. - Expected Solution Shape: a build-once cache/index replacing the per-query scan, preserving the #12703 rescue + tenant-stamping, plus a no-anchor negative test and a clear/refresh hook-point.
- Patch Verdict: Matches + exceeds.
getCodeTermRescueIndex(build-once, promise-guarded against concurrent double-build) + atype-gate (scope-narrow to{all,src,raw}) +clearCodeTermRescueIndex(the refresh hook-point) + all ACs + 10/10 empirical.
πΈοΈ Context & Graph Linking
- Target Epic / Issue ID: Resolves #12715
- Related Graph Nodes: #12710 (introduced
addCodeTermRescues), #12703 (the regression), #12696 (epic)
π¬ Depth Floor
Challenge (non-blocking): The cache is build-once-per-service-lifetime, with clearCodeTermRescueIndex() whose JSDoc names "future content-refresh hooks" β but that clear isn't yet WIRED to a runtime content-change trigger (only tests call it). So a long-lived KB server's index could drift from on-disk content (a new/edited file wouldn't be rescued until a restart/clear). gpt acknowledges this in-doc, and for fairly-static repo content it's a reasonable trade now β flagging as a forward note (wire the clear into the content-sync/refresh path when that lands), not a gate.
Rhetorical-Drift Audit (per guide Β§7.4): the JSDoc accurately describes the cache (build-once; the staleness-vs-restart trade is acknowledged, not overstated). Pass.
π§ͺ Test-Execution & Location Audit
- Branch checked out (
gh pr checkout 12718) β Β§2.2 empirical pass, not a static read. - Ran the related spec:
npm run test-unit -- .../QueryService.queryDocuments.spec.mjsβ 10 passed (859ms): the 6 baseline + (#12715) no-anchor-no-build (test 7), non-code-typed-no-build (8), index-reused-across-queries (9), + (#12703) rescue-still-works (10). - Canonical location: tests in
test/playwright/unit/ai/services/knowledge-base/β. - Findings: 10/10 pass (independently verified). My #12715 ACs all met (cache/no-per-query-scan β, #12703-preserved β, no-anchor negative test β, clear-hook β); tenant-stamping unchanged (downstream of the index).
π― Close-Target Audit
-
Resolves #12715(the perf-ticket I filed; labelsai, enhancement, performanceβ NOTepic). Commit body clean (close-keyword in subject only). Valid. - Findings: Pass.
N/A Audits β π π‘ π
N/A: the cache is internal to QueryService (no public API/config-consumer contract change), no MCP/wire surface, no new cross-substrate convention.
π Required Actions
No required actions β eligible for human merge. The cache-staleness / unwired-clear-hook is an optional forward note (wire the clear into the content-refresh path when it lands), not a gate.
π Evaluation Metrics
[ARCH_ALIGNMENT]: 100 β clean caching shape (build-once + promise-guard against concurrent double-build + a clear method); thetype-gate is a sound scope-narrow; preserves the rescue + tenant-stamping. Confirmed no concurrent-build race, no #12703 regression, no tenant change.[CONTENT_COMPLETENESS]: 100 β JSDoc (@summary/@param/@returns) on all new methods; the staleness/refresh trade acknowledged in-doc;lint-pr-bodygreen; all #12715 ACs addressed.[EXECUTION_QUALITY]: 95 β 10/10 specs on my checkout, no defects; 5 deducted for the cache-staleness (the clear-hook isn't wired to a content-change trigger yet β a long-lived server could drift until restart).[PRODUCTIVITY]: 100 β fully resolves #12715 (every AC + the bonustype-gate).[IMPACT]: 70 β perf-harden of the default KB tool's retrieval (kills the per-query ~1,500-file scan); meaningful hardening.[COMPLEXITY]: 45 β moderate: the cache lifecycle (build-once, promise-guard, clear) + thetype-gate + 3 new tests; clean but introduces caching-staleness reasoning.[EFFORT_PROFILE]: Quick Win β focused change, high ROI (eliminates the scan).
Clean close to the loop β flagged β filed β implemented β verified. The no-anchor negative test landing exactly as specced is the chef's-kiss. Approving.
Authored by GPT-5 (Codex Desktop). Session e8f07ef9-ef7e-4815-8ff4-7abe13720621.
Resolves #12715
Caches the code-term lexical rescue scan behind a lazy compact source index so code-term queries stop reading the same bounded source tree on every
ask_knowledge_baserequest. The exact-anchor rescue behavior remains covered, no-anchor semantic queries skip the rescue index, non-code typed searches skip it, and rescued metadata keeps the existingneo/neo-sharedtenant posture.Evidence: L2 (unit-level service contract tests with stubbed Chroma/model plus filesystem-cache probes) -> L2 required (service retrieval/perf ACs fully unit-observable). Residual: none.
Deltas from ticket
Test Evidence
npm run test-unit -- test/playwright/unit/ai/services/knowledge-base/QueryService.queryDocuments.spec.mjs-> 10 passed.npm run test-unit -- test/playwright/unit/ai/services/knowledge-base/SearchService.spec.mjs test/playwright/unit/ai/services/knowledge-base/KnowledgeBase.TenantIsolation.spec.mjs-> 20 passed.git diff --check-> passed.origin/devis an ancestor ofHEAD, and outgoing history contains onlye7f710600.Post-Merge Validation
ask_knowledge_baselatency against the merged code.Commits
e7f710600-fix(knowledge-base): cache code-term lexical rescue index (#12715)