fix(explore): merge the catalog artifact in its own mbid encoding
CI / check (push) Skipped
CI / e2e (push) Skipped
CI / check (pull_request) Successful in 4m4s
CI / e2e (pull_request) Successful in 14m14s

The prebuilt catalog never merged. `mergeArtifactRows` positions itself
with `WHERE mbid > ? ORDER BY mbid LIMIT 1 OFFSET ?` against the
attached artifact, and it bound that cursor as a Go `string` while
`cmd/indexexport` publishes `explore_index.mbid` as 16 raw bytes — the
storage change that took the table from 677 MB to 389 MB.

SQLite does not coerce between TEXT and BLOB and orders every blob after
every text value, so against a byte column the predicate was not wrong
but unconditional: `mbid > <text>` matched the whole artifact, so the
bound the walk looked up was the same row every time and the cursor
never advanced, and `mbid <= <text>` matched nothing, so no batch
merged. No error, no rows, no state change — a fresh install sat at "0
of 1,077,893 rows" burning a core indefinitely, which is what it did
here for a day, while Explore showed only the rows the library scan and
the lazy artist enrichment had produced and popularity for none of the
catalog.

The cursor is now an `artifactKey`, typed to the encoding
`artifactStoresText` reports for the file it is attached to, so the
comparison is made in the same type as the column it is made against.
Two things guard the class rather than the instance: a nil key binds as
an empty value instead of SQL NULL, because `mbid > NULL` agrees with
nothing and would import nothing just as silently; and the walk returns
an error when its bound does not strictly advance, because the failure
here is silence and the next one should be a failed job with a reason.

It was never caught because the fixture that guards the walk writes the
old text encoding, and the only compact fixture is a single row — below
`artifactMergeBatch`, so the bound query never ran at all. The walk is
now covered on both encodings, across several batch boundaries.

Closes #258
This commit is contained in:
2026-09-25 10:18:51 -04:00
parent 62c1a95ead
commit d4ea14ca5c
3 changed files with 300 additions and 73 deletions
+16
View File
@@ -845,6 +845,22 @@ that is quietly empty.
top-N, exact match, FTS search, popularity batch, the CAA map — and
asserts each returns something with a dashed id. A missed conversion
site shows up there and essentially nowhere else.
- **A comparison is typed on *both* sides, and a parameter is the half
that gets forgotten.** The paragraph above is about a literal; the
artifact merge positioned its batch walk with a Go `string` cursor
against the artifact's byte column, and SQLite answered rather than
complained: `mbid > ?` with a text key is true of every row, so the
bound the walk looked up was the same every time and the cursor
never advanced, while `mbid <= ?` is false of every row, so no batch
merged at all. The import looped indefinitely at 100% CPU behind a
progress bar reading "0 of 1,077,893 rows", merged nothing and
raised nothing (#258). Nothing caught it because the fixture that
guards the walk writes the old text form and the only compact one is
a single row — below `artifactMergeBatch`, so the bound query never
ran. `artifactKey` types the cursor to the artifact's own encoding
now, and the walk fails loudly when its bound does not strictly
advance, because the failure mode here is silence rather than a
wrong answer.
**The artifact is read in either encoding.** A published artifact
carries whichever form the exporter that built it used, and there is one