fix(sync): a Liquid section or snippet reference links its file when the file appears later
Summary
codegraph sync and the file watcher now link a Shopify section or snippet to the files that name it when it is added after them, or comes back after being deleted. Before, the reference stayed unlinked until a file naming it changed or the project was re-indexed, even in a repository with a single theme. Found while working on #2396 and seen identically on main c513f147 and on #2396's branch. Reproduced here on main f797b8ca, with #2396 merged.
Cause
A failed ref is parked under name_tail (#1240). A sync retries the failed refs whose tail is a node name in the changed files, and those names include each file's own node (404.liquid). The Liquid extractor records {% render 'price' %}, {% include %}, {% section %} and a JSON template's section type as references refs named snippets/price.liquid / sections/404.liquid. referenceNameTail takes the text after the last ./:, so every one of them was parked as liquid, the extension, which no node is named. #2392 fixed the same gap for imports only.
How
- File-name tail (
src/db/reference-tail.ts): areferencesref whose name is a path ending in a file name with an extension is parked under that file name:snippets/price.liquid→price.liquid,snippets/icon.logo.liquid→icon.logo.liquid. Path matching looks the file up by exactly that name (getNodesByName(last segment), inmatchByFilePathand #2396'smatchShopifyThemeFile). - No new lookup. The existing symbol retry finds these rows, since
getNodeNamesByFiles(changedFilePaths)already returns the new file's own node name. The query is unchanged and still goes throughidx_unresolved_failed_tail. Before this change no tail contained a dot, so file names passed in that list never matched anything. Outside Liquid repos the lookup does exactly what it did before. - Only
referencesrefs. Acallsref can contain/and end in something extension-like:assert.logfile("logs/error.log").has.line(kong),(rss_kb / 1024.0).to_i(redis), and Kotlin/Java/PHP/Swift chains with URL arguments or//comments. Those keep their symbol tail. The last segment must also look like a file name, so Erlangf/2and route refs likeimport:./x.component#Namekeep their current tails. - Schema v13 rewrites the tails an older version parked:
failed+references+ nameLIKE '%/%.%'. It is idempotent and needs no new index.
Which refs this touches
I surveyed 105 index DBs from earlier validation kits: 57 cgui repos covering about 30 languages, plus vscode, django, redis, prometheus, kong, roact, serilog, riverpod, excalidraw, dawn, syncify, liquidjs and theme-tools. The only failed non-import refs with a / and an extension-like ending were:
- Liquid
references(95 rows) callschains in Java, Kotlin, Lua, PHP, Ruby, Swift, C#, C++ and Scala, which are excluded by kind
Running the v13 rewrite over all 105 DBs touches exactly those 95 Liquid rows and nothing else.
In code, React's lazy-import:./pages/About.tsx (explicit extension) is the only other references emitter whose name can end in a file name. It now waits under About.tsx too.
I checked this with a probe: a data router whose lazy module is added after the router was indexed.
- After sync on main, the route links nothing.
- With the fix,
/about → Aboutlinks, as a fresh index does. - A spec without an extension (
./pages/Team) keeps its old tail and still needs a fresh index. See Limits.
Validation
Tests. The new ones fail on main and pass with the fix:
extraction.test.ts› Liquid Shopify JSON template section resolution › links a section or snippet that appears after the files naming it covers:- a root theme's JSON-template section and rendered snippet
- a folder theme whose 404 section only another theme had (#2396)
- Liquid outside any theme
- the synced links equal a fresh index of the same files, in a second folder. Indexing again over the same index would skip the unchanged files that name the new ones, so it is not a real comparison.
- delete → restore
sync-path-reference-retry.test.tscovers the tail rule, an index parked by an older version (v12 tails + version, reopened, synced) and the v13 migration (rewrite plus idempotent replay).
On the merged tree, tsc is clean and the 13 related suites pass, 987/987. The full suite had 26 failures under the box's parallel load, all 5 s/60 s timeouts or EBUSY rmdir. All but one pass on a serial rerun, and that last one (git-index-currency) passes alone, 13/13.
The issue's repro (built dist): on main it prints [] [], with tails liquid/liquid. With the fix it prints ["sections/404.liquid"] ["snippets/price.liquid"], with tails 404.liquid/price.liquid. Delete → sync → restore → sync relinks. The live file watcher (cg.watch()) gives the same result: main indexes the two new files but links neither; the fix links both.
Fresh codegraph init -y, main vs fix. I ran this twice: at f797b8ca, and again after merging main at 02d22aeb with identical results. Compared with scripts/dump-graph.mjs:
| Repo | Nodes / edges / files | Refs |
|---|---|---|
| Shopify/dawn 258f00f | byte-identical | byte-identical |
| expressjs/express 9efc29e (control) | byte-identical | byte-identical |
| harttle/liquidjs 920166e | identical | 8 rows: name_tail liquid → file name, nothing else |
| Shopify/theme-tools a12b83d | identical | 72 rows: same |
| panoply/syncify 98d75fd | identical | 10 rows: same |
An index built by an older version.
- Indexed dawn with main's CLI (schema 12) while 4 files were missing:
snippets/loading-spinner.liquid(22 render sites),snippets/price.liquid,sections/main-404.liquid(JSON template) andsections/main-password-header.liquid({% section %}tag). That parks 30 refs, all with tailliquid. - Restored the files and ran
codegraph syncwith main's CLI. The schema stays 12, and the dump has 30referencesedges fewer than a fresh index (1941 vs 1971). - Ran the same
codegraph syncwith the fix's CLI instead. It migrates to schema 13, and the dump is byte-identical to a fresh index of dawn.
Migration cost. On vscode's index (1.9 GB, 828k parked refs, 0 rows to rewrite), v13 takes about 380 ms once (3 runs: 376/381/399 ms). It walks the failed set through idx_unresolved_status. v12 costs about 430 ms on the same DB.
Limits
- A section or snippet an earlier version already failed to link before the upgrade is fixed by a re-index, or by any change to that section or snippet file. A sync with nothing changed doesn't revisit it. The CHANGELOG bullet says to re-index.
- The existing 500-per-name retry ceiling now applies per file name. A file that more than 500 failed references name (dawn's busiest snippet has 22) would still need a re-index.
- Route refs that name a module without an extension (React
lazy-import:./x, Vue/Angularimport:./x#Name) still park under a tail no file is named. That is the same family as this fix, but they resolve through their own import-path logic, so I left them out of this change.
🤖 Generated with Claude Code