Repository navigation
Description
What happens
A run that ends with tables still undescribed - an LLM rate limit, a dropped database connection, anything that leaves nulls - stores that result as a completed stage, keyed on the stage hash.
Every later ktx ingest whose hash matches finds the completed row, hands the gap straight back, finishes in seconds and prints a clean tick. The gap becomes permanent. --stages descriptions is the only escape, and nothing tells you that you need it.
Where it comes from
packages/cli/src/context/scan/local-enrichment.ts - the stage runner stores and replays a stage result on stage-hash equality alone, with no check that the result is actually complete. resumedStages is pushed only in the short-circuit branch, so its presence in the run report is the giveaway.
Why it is easy to miss
Enrichment warnings are written to the run's scan-report.json (its warnings array), not to warnings.json - that file is written by the structural scan and stays empty regardless. Tables that were never attempted raise no enrichment_failed of their own either, so even the warnings array can look clean.
Evidence
Observed on a 349-table project:
- two rows cached as
status=completed, each carrying 217/349 descriptions and 132 nulls - the scan report showed
resumedStages: ["descriptions", ...] - a plain
ktx ingesttook 13 seconds and reported success, with 132 descriptions still missing ktx ingest --stages descriptionswas the only way to fill them
Reproduce
- Start an ingest and have the LLM fail partway (rate limit, or point it at an unreachable endpoint after some tables succeed)
- Let the run finish - it reports success
- Run
ktx ingestagain: it completes in seconds, still missing those descriptions, and says nothing
Suggested fix
Give the stage runner an optional cacheable(output) predicate and apply it on both sides:
- write - a result that fails the predicate is returned but never stored, so a gap cannot be cached in the first place
- read - a completed row that fails the predicate is treated as a miss, so rows written before the fix (or by another machine) stop being replayed and the project heals itself on the next run instead of needing a manual flag
For descriptions the predicate is output.every((update) => isEnrichedDescriptionUpdate(update)). generateDescriptions already returns the full table set in snapshot order - recovered, freshly enriched, or a null update for anything still missing - so a single gap fails it. The stage then re-enters compute(), and with per-table resume (#348) only the missing tables reach the LLM.
A warning naming the count would also stop an incomplete run from passing silently:
{ "code": "descriptions_incomplete",
"message": "43 of 349 tables have no AI description. This result was not cached, so re-running `ktx ingest` once the LLM is available will describe only those tables.",
"metadata": { "undescribed": 43, "total": 349 } }Trade-off worth knowing
While any table is undescribed the stage is not cacheable, so every run re-enters it. That costs one cheap re-entry, not regeneration - per-table hashes mean only the missing tables are sent. A table that can never be described keeps the stage uncacheable indefinitely, which is what the warning is for.
Activity