#434 follow-ups: typeahead combobox polish + source limitations #578

Closed
opened 2026-07-23 21:03:25 +02:00 by timothy · 4 comments
Owner

Deferred non-blocking items from the #434/#435/#438 bundle (PR #577). All low priority.

#434 typeahead combobox polish

  • Empty-query mount fetch: the combobox issues an empty-q request on mount for every text rule row (N rows → N requests). Bounded server-side by limit=50, but chattier than the SearchPicker precedent, which skips empty queries. Consider fetch-on-focus instead of fetch-on-mount.
  • No unmount guard: the combobox's in-flight promise has a seqRef stale-response guard but no "is-mounted" check, so a fetch resolving after unmount can setState (benign React dev-mode warning). Inherited verbatim from SearchPicker — worth a shared isMountedRef if that component is ever revisited.

#434 typeahead source limitation

  • artist covers entity artists only: GetSearchFieldValuesHandler sources artist from ArtistMetadata.Title. Free-text artist credits on music videos (MusicVideoArtist.Name) and songs (SongMetadata.Artists, a value-converted IList<string>) are searchable but not offered as typeahead suggestions. album_artist (also a value-converted list column) is excluded → 404 for the same reason. Extend if music-library typeahead completeness is wanted.

Test-harness nit

  • web/src/builder/rules/roundtrip.test.ts LCG pick() divides by 0xffffffff, which can return exactly 1.0 → arr[Math.floor(1.0*len)] indexes one past the end (undefined). Pre-existing; deterministic-seeded so currently green, but a latent flake on a future seed change. Fix: divide by 0x100000000.

None of these affect correctness of the shipped feature (free-text fallback covers the combobox cases; the round-trip test passes deterministically).


Done-when

Covers all four items this issue describes — the frontend polish and the backend suggestion-source gap. Delivered across two PRs: the three frontend items in #678 (merged), the backend source in #676.

  • The combobox no longer issues an empty-q fetch per row on mount (fetch-on-focus, matching the SearchPicker precedent) — #678, merged
  • A resolved fetch cannot setState after unmount (is-mounted guard, shared with SearchPicker rather than duplicated) — #678, merged; shared useIsMountedRef in web/src/hooks.ts
  • roundtrip.test.ts's LCG pick() divides by 0x100000000, so it can no longer index one past the end — #678, merged; the boundary test drives the real lcg into the state whose next step is 0xffffffff (seed 653637408), rather than recomputing the formula
  • artist typeahead suggestions include free-text credits from music videos (MusicVideoArtist.Name) and songs (SongMetadata.Artists), not just entity artists — #676
  • album_artist either returns suggestions or its 404 is a deliberate, documented response for list-valued fields — #676: returns 200; additive under api.versioning-v1
  • The value-converted-list-column suggestion source is bounded (no unbounded table scan / no in-memory materialization of the whole songs table), verified by a test that pins the query shape — #676; see the caveat below on what "bounded" means
  • A decision record extends or amends api.search-field-values to cover list-valued fields — #676: superseded by api.search-field-values-sources
  • Adversarial review passed — six rounds on #676, nine on #678

Resolution notes

The columns weren't what the issue assumed. SongMetadata.Artists/AlbumArtists are not HasConversion value-converted lists — they are EF9 primitive collections: one JSON array per row in a single TEXT/longtext column. Verified by probe against both providers (SQLite: "Translating this query requires the SQL APPLY operation"; Pomelo: "Primitive collections support has not been enabled"). The practical consequence is the same — no server-side DISTINCT over elements — but the mechanism differs from the issue text.

"Bounded" took five attempts, each of which looked obviously correct:

Attempt Bounded Why wrong
1–2 the result (LIMIT 1000) a widened prefix starves the budget with non-matching rows
3 candidates returned LIMIT caps output; a no-match query evaluates every eligible row first, so the counter recorded zero
4 keyspace width keyspace ≠ rows — one row at Id=20001 behind a 20,000-Id gap returned [] having inspected nothing
5 actual rows —

The fix is a deletion: the page query is now a bare primary-key range with no residual predicate — no LIKE, no LOWER, not even IS NOT NULL. LIMIT only bounds work when there is nothing to discard; the cursor is a seekable ordering-key predicate that positions the scan without discarding, so LIMIT n yields n rows and a short page can only mean exhaustion.

That deletion removed an entire family of defects with it: the JSON-escape reasoning, a verbatim-ASCII narrowing rule, an exhaustive Unicode sweep proving it sound, and a "may over-match, never under-match" invariant that turned out to be conditional on something untrue.

It also fixed the original defect properly. The first implementation JSON-encoded the whole prefix, so q=é built %"é% against a stored Édith — LOWER() folds the ASCII escape text, not the codepoint. Every accented artist was unsuggestable, and the decision record had claimed the opposite.

What is guaranteed: at most 20,000 logical rows returned/materialized, ≤10 round trips (11 for artist). Explicitly not guaranteed, and struck through in the record because it was asserted and then retracted: bounded physical work, bounded bytes, exact index-entry counts. MySQL purge lag keeps deleted clustered-index records traversable and TEXT spills to overflow pages, so a row count implies neither. The 392 KiB measurement is one data point on one library averaging ~20 B/row.

Accepted, pinned loss: a match past row 20,000 isn't found — now depending only on row position, no longer on prefix shape, deletion history or Id distribution.

Follow-ups: #668 (accented values still missed on the EF-sourced fields — a provider-divergent defect, since SQLite's LOWER() is ASCII-only and MySQL's is not), #669 (a normalized SongArtist join table, rejected here on blast radius), #674 (the decisions validator stays green on frontmatter PyYAML rejects — hit twice this session).

Deferred non-blocking items from the #434/#435/#438 bundle (PR #577). All low priority. ### #434 typeahead combobox polish - **Empty-query mount fetch**: the combobox issues an empty-`q` request on mount for every text rule row (N rows → N requests). Bounded server-side by `limit=50`, but chattier than the `SearchPicker` precedent, which skips empty queries. Consider fetch-on-focus instead of fetch-on-mount. - **No unmount guard**: the combobox's in-flight promise has a `seqRef` stale-response guard but no "is-mounted" check, so a fetch resolving after unmount can `setState` (benign React dev-mode warning). Inherited verbatim from `SearchPicker` — worth a shared `isMountedRef` if that component is ever revisited. ### #434 typeahead source limitation - **`artist` covers entity artists only**: `GetSearchFieldValuesHandler` sources `artist` from `ArtistMetadata.Title`. Free-text artist credits on music videos (`MusicVideoArtist.Name`) and songs (`SongMetadata.Artists`, a value-converted `IList<string>`) are searchable but not offered as typeahead suggestions. `album_artist` (also a value-converted list column) is excluded → 404 for the same reason. Extend if music-library typeahead completeness is wanted. ### Test-harness nit - `web/src/builder/rules/roundtrip.test.ts` LCG `pick()` divides by `0xffffffff`, which can return exactly `1.0` → `arr[Math.floor(1.0*len)]` indexes one past the end (`undefined`). Pre-existing; deterministic-seeded so currently green, but a latent flake on a future seed change. Fix: divide by `0x100000000`. None of these affect correctness of the shipped feature (free-text fallback covers the combobox cases; the round-trip test passes deterministically). --- ## Done-when Covers all four items this issue describes — the frontend polish and the backend suggestion-source gap. **Delivered across two PRs**: the three frontend items in **#678** (merged), the backend source in **#676**. - [x] The combobox no longer issues an empty-`q` fetch per row on mount (fetch-on-focus, matching the `SearchPicker` precedent) — *#678, merged* - [x] A resolved fetch cannot `setState` after unmount (is-mounted guard, shared with `SearchPicker` rather than duplicated) — *#678, merged; shared `useIsMountedRef` in `web/src/hooks.ts`* - [x] `roundtrip.test.ts`'s LCG `pick()` divides by `0x100000000`, so it can no longer index one past the end — *#678, merged; the boundary test drives the real `lcg` into the state whose next step is `0xffffffff` (seed 653637408), rather than recomputing the formula* - [x] `artist` typeahead suggestions include free-text credits from music videos (`MusicVideoArtist.Name`) and songs (`SongMetadata.Artists`), not just entity artists — *#676* - [x] `album_artist` either returns suggestions or its 404 is a deliberate, documented response for list-valued fields — *#676: returns 200; additive under `api.versioning-v1`* - [x] The value-converted-list-column suggestion source is bounded (no unbounded table scan / no in-memory materialization of the whole songs table), verified by a test that pins the query shape — *#676; see the caveat below on what "bounded" means* - [x] A decision record extends or amends `api.search-field-values` to cover list-valued fields — *#676: superseded by `api.search-field-values-sources`* - [x] Adversarial review passed — *six rounds on #676, nine on #678* --- ## Resolution notes **The columns weren't what the issue assumed.** `SongMetadata.Artists`/`AlbumArtists` are not `HasConversion` value-converted lists — they are EF9 **primitive collections**: one JSON array per row in a single `TEXT`/`longtext` column. Verified by probe against both providers (SQLite: *"Translating this query requires the SQL APPLY operation"*; Pomelo: *"Primitive collections support has not been enabled"*). The practical consequence is the same — no server-side `DISTINCT` over elements — but the mechanism differs from the issue text. **"Bounded" took five attempts, each of which looked obviously correct:** | Attempt | Bounded | Why wrong | |---|---|---| | 1–2 | the **result** (`LIMIT 1000`) | a widened prefix starves the budget with non-matching rows | | 3 | **candidates returned** | `LIMIT` caps output; a no-match query evaluates every eligible row first, so the counter recorded **zero** | | 4 | **keyspace width** | keyspace ≠ rows — one row at `Id=20001` behind a 20,000-Id gap returned `[]` having inspected nothing | | 5 | **actual rows** | — | The fix is a **deletion**: the page query is now a bare primary-key range with **no residual predicate** — no `LIKE`, no `LOWER`, not even `IS NOT NULL`. `LIMIT` only bounds work when there is nothing to discard; the cursor is a *seekable ordering-key* predicate that positions the scan without discarding, so `LIMIT n` yields n rows and a short page can only mean exhaustion. That deletion removed an entire family of defects with it: the JSON-escape reasoning, a verbatim-ASCII narrowing rule, an exhaustive Unicode sweep proving it sound, and a "may over-match, never under-match" invariant that turned out to be conditional on something untrue. **It also fixed the original defect properly.** The first implementation JSON-encoded the whole prefix, so `q=é` built `%"é%` against a stored `Édith` — `LOWER()` folds the ASCII *escape text*, not the codepoint. Every accented artist was unsuggestable, and the decision record had claimed the opposite. **What is guaranteed:** at most 20,000 **logical rows** returned/materialized, ≤10 round trips (11 for `artist`). Explicitly **not** guaranteed, and struck through in the record because it was asserted and then retracted: bounded physical work, bounded bytes, exact index-entry counts. MySQL purge lag keeps deleted clustered-index records traversable and `TEXT` spills to overflow pages, so a row count implies neither. The 392 KiB measurement is one data point on one library averaging ~20 B/row. **Accepted, pinned loss:** a match past row 20,000 isn't found — now depending only on row position, no longer on prefix shape, deletion history or `Id` distribution. Follow-ups: **#668** (accented values still missed on the EF-sourced fields — a provider-divergent defect, since SQLite's `LOWER()` is ASCII-only and MySQL's is not), **#669** (a normalized `SongArtist` join table, rejected here on blast radius), **#674** (the decisions validator stays green on frontmatter PyYAML rejects — hit twice this session).
timothy added the frontendpriority: low labels 2026-07-23 21:03:51 +02:00
timothy added the in-progress label 2026-07-26 22:57:13 +02:00
Author
Owner

Claiming — folded into this session's #650 + #651 + #578 frontend bundle.

Picked up because #651 (searchable library-browse pickers) lands in the same combobox/SearchPicker code, making the fetch-on-focus and unmount-guard items cheap to do in the same pass. The roundtrip.test.ts LCG divisor nit rides along.

Claiming — folded into this session's **#650 + #651 + #578** `frontend` bundle. Picked up because #651 (searchable library-browse pickers) lands in the same combobox/`SearchPicker` code, making the fetch-on-focus and unmount-guard items cheap to do in the same pass. The `roundtrip.test.ts` LCG divisor nit rides along.
Author
Owner

Done-when box 4 satisfied: the artist / album_artist typeahead source limitation is split out to #662 (api, priority: low).

It turned out to be more than a "add the missing columns" item — api.search-field-values deliberately sources distinct whole values from the database rather than the Lucene term dictionary, and a value-converted IList<string> (SongMetadata.Artists, album_artist) can't be SELECT DISTINCT-ed server-side because the conversion happens client-side in EF. So #662 carries the actual design question, including "document the 404 as deliberate" as a legitimate outcome.

The remaining three #578 items (fetch-on-focus, unmount guard, LCG divisor) stay in this session's #651 branch.

Done-when box 4 satisfied: the `artist` / `album_artist` typeahead source limitation is split out to **#662** (`api`, `priority: low`). It turned out to be more than a "add the missing columns" item — `api.search-field-values` deliberately sources distinct **whole** values from the database rather than the Lucene term dictionary, and a value-converted `IList<string>` (`SongMetadata.Artists`, `album_artist`) can't be `SELECT DISTINCT`-ed server-side because the conversion happens client-side in EF. So #662 carries the actual design question, including "document the 404 as deliberate" as a legitimate outcome. The remaining three #578 items (fetch-on-focus, unmount guard, LCG divisor) stay in this session's #651 branch.
Author
Owner

Correction to my previous comment: #662 is closed and folded back in here. The Done-when above now covers all four items this issue describes, including the artist / album_artist suggestion-source gap.

I had split the backend item out to keep the PR frontend-only. That was wrong — it would have let this issue close with most of its described contents unaddressed. The scope is what the issue describes, not what happened to be convenient for one branch.

The backend slice runs in its own worktree alongside the frontend work.

Correction to my previous comment: **#662 is closed and folded back in here.** The Done-when above now covers all four items this issue describes, including the `artist` / `album_artist` suggestion-source gap. I had split the backend item out to keep the PR frontend-only. That was wrong — it would have let this issue close with most of its described contents unaddressed. The scope is what the issue describes, not what happened to be convenient for one branch. The backend slice runs in its own worktree alongside the frontend work.
Author
Owner

Closing record

Outcome: All four items delivered across two PRs — the three frontend items in #678 (fetch-on-focus, a shared useIsMountedRef, the LCG divisor) and the backend suggestion source in #676 (artist now covers MusicVideoArtist.Name and SongMetadata.Artists; album_artist returns 200 instead of 404).

Root cause: The artist field sourced only ArtistMetadata.Title. The two missing sources are shaped differently: MusicVideoArtist is a real table (a plain Concat), while SongMetadata.Artists/AlbumArtists are EF9 primitive collections — one JSON array per row in a single TEXT column that neither provider can project server-side. The issue described them as value-converted lists; that was wrong about the mechanism, right about the consequence.

Decisions/conventions changed: api.search-field-values-sources supersedes api.search-field-values (archived with its original prose restored). The base endpoint contract carries over; what reverses is the "no distinct-value source" call for the list-valued music fields.

Reusable knowledge:

  • "Bounded" took five attempts, each obviously correct at the time: the result (LIMIT 1000) → candidates returned → keyspace width → actual rows. The lesson is that LIMIT bounds survivors of a predicate, never work: a no-match query must evaluate every eligible row before it can return an empty page. The fix was a deletion — the page query is now a bare PK range with no residual predicate at all, and a short page can finally only mean exhaustion.
  • Deleting the predicate deleted a whole family of defects with it: the JSON-escape reasoning, a verbatim-ASCII narrowing rule, an exhaustive Unicode sweep proving it sound, and a "may over-match, never under-match" invariant that turned out conditional on something untrue. Five tests removed because their subject ceased to exist.
  • Lowercasing a \uXXXX escape cannot case-fold the codepoint it represents. The first implementation JSON-encoded the whole prefix, so q=é searched for é against a stored É — every accented artist silently unsuggestable, in a music library.
  • A claim about a bound needs the same scrutiny as the bound. "Exactly n index entries" survived a round because it sounded like a consequence of the code; MySQL purge lag and TEXT overflow pages both break it. Retracted in-record with strike-through rather than quietly reworded.
  • A "sweep complete" claim is the expensive kind of wrong. One round reported every stale hit classified; the retracted wording survived in nine places including the record's own title and rule: — the string the generated catalog copies verbatim. The term list had been built from the deleted mechanism's vocabulary and never included the retracted claim's own words.

Verification: dotnet test ErsatzTV.Tests 1928 passed / 0 failed / 2 skipped · Architecture.Tests 7 · decisions_validate.py OK · scripts/tests 325 · BOM-free on all touched .cs · format gate exit 0 · no OpenAPI regeneration needed (the endpoint description already claimed only bounded song rows). Six cold review rounds on #676, nine on #678; every new test mutation-verified. Verified independently: all eight retracted-claim terms at zero non-struck hits against a live control, and the catalog containing the record's rule: verbatim.

Deferred: #668 (accented values still missed on the EF-sourced fields — provider-divergent, since SQLite's LOWER() is ASCII-only and MySQL's is not), #669 (a normalized SongArtist join table — rejected here on blast radius; the leading-wildcard scan is gone but the 20,000-row ceiling remains), #674 (decisions_validate.py stays green on frontmatter PyYAML rejects — hit twice this session by two agents independently).

Docs updated: docs/api-conventions.md (bounded-best-effort subsection; the seekable-cursor vs residual-predicate distinction as a generalizable rule), docs/spa-conventions.md §12 and §3b, docs/decisions.md index, the new records/api/search-field-values-sources.md + archive/api/search-field-values.md, catalog regenerated.

## Closing record **Outcome:** All four items delivered across two PRs — the three frontend items in **#678** (fetch-on-focus, a shared `useIsMountedRef`, the LCG divisor) and the backend suggestion source in **#676** (`artist` now covers `MusicVideoArtist.Name` and `SongMetadata.Artists`; `album_artist` returns 200 instead of 404). **Root cause:** The `artist` field sourced only `ArtistMetadata.Title`. The two missing sources are shaped differently: `MusicVideoArtist` is a real table (a plain `Concat`), while `SongMetadata.Artists`/`AlbumArtists` are EF9 **primitive collections** — one JSON array per row in a single `TEXT` column that neither provider can project server-side. The issue described them as value-converted lists; that was wrong about the mechanism, right about the consequence. **Decisions/conventions changed:** `api.search-field-values-sources` **supersedes** `api.search-field-values` (archived with its original prose restored). The base endpoint contract carries over; what reverses is the "no distinct-value source" call for the list-valued music fields. **Reusable knowledge:** - **"Bounded" took five attempts, each obviously correct at the time**: the result (`LIMIT 1000`) → candidates returned → keyspace width → actual rows. The lesson is that `LIMIT` bounds *survivors of a predicate*, never *work*: a no-match query must evaluate every eligible row before it can return an empty page. The fix was a **deletion** — the page query is now a bare PK range with no residual predicate at all, and a short page can finally only mean exhaustion. - **Deleting the predicate deleted a whole family of defects with it**: the JSON-escape reasoning, a verbatim-ASCII narrowing rule, an exhaustive Unicode sweep proving it sound, and a "may over-match, never under-match" invariant that turned out conditional on something untrue. Five tests removed because their subject ceased to exist. - **Lowercasing a `\uXXXX` escape cannot case-fold the codepoint it represents.** The first implementation JSON-encoded the whole prefix, so `q=é` searched for `é` against a stored `É` — every accented artist silently unsuggestable, in a *music* library. - **A claim about a bound needs the same scrutiny as the bound.** "Exactly n index entries" survived a round because it sounded like a consequence of the code; MySQL purge lag and `TEXT` overflow pages both break it. Retracted in-record with strike-through rather than quietly reworded. - **A "sweep complete" claim is the expensive kind of wrong.** One round reported every stale hit classified; the retracted wording survived in nine places including the record's own **title** and **`rule:`** — the string the generated catalog copies verbatim. The term list had been built from the *deleted mechanism's* vocabulary and never included the *retracted claim's own words*. **Verification:** `dotnet test ErsatzTV.Tests` 1928 passed / 0 failed / 2 skipped · Architecture.Tests 7 · `decisions_validate.py` OK · `scripts/tests` 325 · BOM-free on all touched `.cs` · format gate exit 0 · no OpenAPI regeneration needed (the endpoint description already claimed only bounded song *rows*). Six cold review rounds on #676, nine on #678; every new test mutation-verified. Verified independently: all eight retracted-claim terms at zero non-struck hits against a live control, and the catalog containing the record's `rule:` verbatim. **Deferred:** **#668** (accented values still missed on the EF-sourced fields — provider-divergent, since SQLite's `LOWER()` is ASCII-only and MySQL's is not), **#669** (a normalized `SongArtist` join table — rejected here on blast radius; the leading-wildcard scan is gone but the 20,000-row ceiling remains), **#674** (`decisions_validate.py` stays green on frontmatter PyYAML rejects — hit twice this session by two agents independently). **Docs updated:** `docs/api-conventions.md` (bounded-best-effort subsection; the seekable-cursor vs residual-predicate distinction as a generalizable rule), `docs/spa-conventions.md` §12 and §3b, `docs/decisions.md` index, the new `records/api/search-field-values-sources.md` + `archive/api/search-field-values.md`, catalog regenerated.
timothy removed the in-progress label 2026-07-27 08:11:06 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#578