Revision: 12 Last modified: 2026-12-04T14:04:16Z
Source: constitution/scripts/codegraph/runner_patches/resolve1.py (116 lines). A module driven by
fk_index_patch.py, not a command. Citations are resolve1.py:<line> unless another file is named. Machinery guide:
fk_index_patch.
Stock CodeGraph 1.6.0 ReferenceResolver.createContext().getAllFiles (lib/dist/resolution/index.js) runs
SELECT path FROM files ORDER BY path and maps the rows on every call. Several per-reference paths call it, most
importantly the vue framework's resolveComponent, reached for every calls reference with a PascalCase name in any
language once vue is detected (one .vue file anywhere suffices). On a 584,603-file index the source records ~350 ms per
call and 93.4% of resolve wall time (real-repository profile), i.e. O(#refs x #files) (docstring lines 3-11).
Fix (docstring lines 13-27; five anchors in two files):
getAllFilesreturnsthis.helixAllFilesMemo, filled on first use with the unchanged query result (sameORDER BY pathorder) andObject.freeze()d, so callers see one stable array and any in-place mutation throws instead of corrupting the memo (source states no stock caller mutates it, audited 2026-09-24).- The memo is dropped in
clearCaches(), the same invalidation point stock uses forknownFilesand other caches. - The memo is also dropped at the top of
initialize(), because stockinitialize()runsdetectFrameworks()before itsclearCaches(), anddetect()readsgetAllFiles(). - In
frameworks/vue.jsaWeakMapkeyed on the (identity-stable) file list caches the.vuesubset, soresolveComponentno longer walks every file per reference;filterpreserves order, so matches and tie-breaks are element-for-element what stock computed (lines 62-99).
Honest boundary (source lines 29-33): between two clearCaches() calls the list is a snapshot; stock re-queried. Every stock
path that changes the files table reaches clearCaches()/initialize() before resolving, and the resolver never writes
the files table.
Reads lib/dist/resolution/index.js and lib/dist/resolution/frameworks/vue.js. Python stdlib plus
runner_patches/common.py. Default-set patch (runner_patches/__init__.py:17), applied fourth. It is one of the three
patches codegraph_safe.sh uses by default (the registry default fkidx1,resolve1,resolve2 since 2026-11-06, CON-211).
Only through fk_index_patch.py:
python3 scripts/codegraph/fk_index_patch.py --patches resolve1 --dst <scratch dir>VERIFIED (ran: tests/test_resolve1.sh (drives fk_index_patch.py) with TMPDIR set to a scratch directory; saw: SUMMARY cases=7 failed=0, exit 0). The test builds a--patches resolve1runner under its own workdir from the installed stock package (~282 MB copy) and never touches the real cache (HELIX_CODEGRAPH_RUNNER_DIRis set to its workdir,test_resolve1.sh:45).VERIFIED (ran: resolve1.plan against stock 1.6.0 via fk_index_patch.plan_all; saw: APPLIED, files lib/dist/resolution/index.js and lib/dist/resolution/frameworks/vue.js, five anchors, detail memo_field helixAllFilesMemo, frozen true).
plan(view) (lines 102-116):
- Refuse
resolve1: source is ALREADY patched — --src must be the pristine packageifhelixAllFilesMemooccurs inresolution/index.jsorhelixVueSubsetCacheinvue.js(lines 103-105). - Five
replace_onceedits (lines 107-111):getAllFiles(memoized and frozen),clearCachesreset,initialize()entry reset, the vue helperhelixVueFiles, and the vue loopfor (const file of helixVueFiles(context.getAllFiles()))(which drops the per-fileendsWith('.vue')test because the subset is already filtered). - Any anchor that does not occur exactly once raises Refuse (
common.py), exit 2, no runner. There is no NOT_NEEDED path in this patch (no such branch in the source).
R1 getAllFiles() returns one frozen array per generation equal to the query result; R2 clearCaches() invalidates it;
R3 initialize() invalidates it before detectFrameworks(); R4 real getAllFilePaths() queries during a full index do
not grow with the number of references (bounded by R4_MAX, default 12); R5 the .vue subset is derived once per
file-list identity (the probe's reference is language: 'javascript': from CodeGraph 1.6.2 the vue resolver returns null
for any language outside VUE_SCRIPT_LANGUAGES before it scans, so the earlier cpp probe never reached the code under
test; R5 also requires vue_scan_1st > 0; measured 2026-11-05: patched runner 1st=335 2nd=0 PASS, stock 1.6.2 1st=335
2nd=335 FAIL); R5b a .vue file added after the first resolve, then clearCaches(), is found (the subset is
never served stale from an older list; added 2026-11-06 after review finding I2-1: the reviewer mutant that keys the
subset on one global key passed R2, R5 and R6, and fails R5b); R6 and R7 resolution output (sorted edge dump sha256) is byte-identical to the stock package on a
mixed-language fixture with vue and on a vue-free fixture. Companion files: test_resolve1_probe.js, _drive.js,
_count_hook.js, _dump.py, _fixture.py, _equiv_real.js; test_resolve1_mutations.sh applies single-edit mutants of
the patch (table in test_resolve1_mutate.py) and requires the named tests to turn red.
- Already-patched input:
VERIFIED (ran: plan on the patched text; saw: Refuse "source is ALREADY patched")(parent guide, Edge cases). - Any anchor absent or duplicated:
VERIFIED (parent guide: for every anchor of resolve1, removing or duplicating it in a copy of the real 1.6.0 files produced Refuse "anchor '<label>' occurs 0x|2x ... expected exactly 1"). - A code path that mutates the returned array now throws (
Object.freeze); the docstring says no stock caller does. - Files added to the
filestable between twoclearCaches()calls are not seen bygetAllFiles; this is the snapshot boundary above.
fk_index_patch, siblings fkidx1, lockfix1, datafrag1,
resolve2 (reads the same resolution/index.js), mcpro1, codegraph_safe.
2026-09-26: tests/test_resolve1.sh 7/7 PASS with a scratch TMPDIR; the real runner cache directory listing was unchanged
(1.6.0-fkidx1, 1.6.0-fkidx1-resolve1, 1.6.0-mcpro1). tests/test_resolve1_mutations.sh: SUMMARY cases=6 failed=0 (golden plus 5 mutants, each
required red and killed).