A failed fold must never advance the cursor: silent, permanent index loss
Observed twice now:
- as "2 branches on the timeline" when a check-in went missing; - again on 2026-08-19, when a schema change made every ticket fold fail with "no such column". Folds errored for minutes, the cursor advanced, and `ticket_change` went to 0 rows on a store that holds thousands. The failure was loud in the log and completely invisible in the data.
### Required
**A failed fold must not advance the cursor.** Retry with backoff; if an artifact keeps failing, stop the pipeline for that repository and alarm. A stalled indexer that says so is strictly better than a silently incomplete one that looks healthy — the store is always correct, so stopping loses nothing but time.
### Also needed
- A post-fold completeness invariant: artifacts the store holds versus artifacts the index accounts for, checked per round, alarming on divergence. `lostArtifacts` already does this for dangling parents; generalise it rather than adding a second mechanism. - The check belongs in the serving path, not only in the harness. The disposability test proves a rebuild is faithful; nothing currently proves the RUNNING index is.
Related: #d725bd29c5 (tk: artifacts the store holds are missing and a rebuild does not repair it) is very likely the same root cause.
Fixed in 02f05e42.
The invariant, enforced structurally: watch no longer saves the
publisher cursor — it returns a save closure, and round invokes it
only after the final fold succeeds. A failed fold now costs one
re-read-and-republish of the same tail next round (idempotent folds
absorb it); it can no longer cost artifacts. TestFailedFoldDoesNotAdvanceCursor
reproduces the incident shape (fold failing the way the schema bug made
it fail) and pins the cursor in place.
Stop and alarm: after 3 consecutive failures the pipeline STALLS —
one loud log line with the cause, stalled + retryAt on the health
surface and a red badge on /fleet, and exponential backoff (30s
doubling, capped 10m). Backoff rather than a latch: the store is intact
and the cursor held, so when the cause is fixed the next attempt heals
with no operator ceremony. quarry reindex bypasses the stall
deliberately. While stalled, Sync returns ErrStalled; the poller
does not re-log it, and a write op treats it as lag rather than failing
a write the store already recorded.
TestStallBacksOffAlarmsAndRecovers drives the full arc: fail, stall,
refuse, heal.
Found while testing: a round after a failed fold blocks in the
drain loop up to the consumer's AckWait (30s) waiting for redelivery.
The wait is honest — breaking early would let the cursor save with
messages unfolded — so it is now an explicit, configurable knob
(ackWait) rather than an accident of NATS defaults.
Remaining (not blocking closure): the generalized per-round
completeness invariant. lostArtifacts already probes dangling parents
each round and feeds Gaps on /fleet; widening it beyond parent edges is
follow-on work, tracked alongside #d725bd29c5 where the question is
live.