Findings (read-only on the flagship; nothing written, restarted or snapshotted).
Root cause: the replica lost WAL frames because CARLOS kills litestream's read lock at every replication start. litestream opens its long-running read transaction (the lock that stops anyone else restarting the WAL over frames it has not read yet) in its first Sync, with BeginTx(ctx) on that call's context (litestream 0.5.14 db.go:1132). That first Sync is ours: internal/lease/continuity.go:402-406 (firstSync, reached from lease.go:476) runs it under context.WithTimeout and cancels it on return. database/sql rolls a transaction back when its context ends, so the lock dies about 60 ms into every wake, restart or deploy, while litestream still believes it holds it. Until litestream's next own checkpoint (here 3 minutes), the app's SQLite autocheckpoint (default 1000 pages; Rastrillo sets none) can backfill and restart the WAL. Frames committed after litestream's last read (it polls every 10 s, lease.go:108) are overwritten, and litestream's own check is fooled because the new WAL is shorter than its old position. The live database has those pages (they were checkpointed into it); the replica never will.
Evidence.
- Store,
carlos-data-ie-271376211898/instances/equipo-staging.bds.oncarlos.com/(root layout, versioned, so the deleted L0s are still readable). L0s are contiguous, one version per key, none short. I decoded every LTX header from 09:00 to 10:02: every WAL restart is litestream's own (a 1-frame L0 at offset 32 within 20 ms of the previous file) except two.2f3c1(09:18:50.5Z, 94 pages, offset 32, new salt) follows2f3c0, which ended at WAL byte 4,025,272 (977 frames, just under 1000), and the same thing happens again at2f3c7(09:19:50.5Z). litestream's first own checkpoint after the 09:17:50 wake is 09:20:50. - Rebuilt the replica locally as it stood at 09:52: restores to
2f3c0(193472) pass the integrity check,2f3c1(193473) is the first that fails (Tree 249 page 12310: btreeInitPage() returns error code 11, the same errors you saw). Page 249 in2f3c1points at pages 12306-12323 and 12368, which are in no LTX after2f3bc: they were written in the lost frames. - Box journal (SSM, read-only grep): 09:17:49 hibernated, 09:17:50 woke ("lease 100ms, restore 29ms, protect 9ms, spawn 1.037s, replicate 63ms"). No litestream errors.
/etc/litestream.ymldoes not list the app, so there is no second replicator. - Production
equipo, 11-19: platform log shows a wake at 14:10:31Z (new release), and the L0 headers show a foreign WAL restart at 14:10:41.4Z (216a0, prev end 1,602,712). Same mechanism, 10 s after a wake. It later read clean because the nightly level-9 snapshot is taken from the live database. - Reproduced with a plain SQLite app against litestream 0.5.14: the same writes restore clean when the first Sync's context stays open, and come back broken when it is cancelled.
"decode header: EOF" is a second bug that hid the first. ltx v0.5.1's Compactor drops an input's header error (compactor.go:84-87 returns nil), so any file open or read that fails mid-restore reads as decode header: EOF. The 09:48-09:52 latest plan was about 345 files. Locally the same plan gives the integrity failure, and gives exactly decode header: EOF if file opens fail (I forced it with ulimit -n 256). Your CLI's door download most likely hit a refusal that the ltx bug turned into EOF; the exact cause is lost. The latest copy now (about 110 files) reports the integrity failure instead.
Why nothing noticed. litestream writes LTX with no checksums (HeaderFlagNoChecksum; every header here has pre/post checksum 0), so nothing on the write side can see a gap. Its check treated the restart as normal and logged nothing. The live app is healthy. The 03:00Z drill (control/verify/annie-welding.json, equipo-staging passed today at 03:2x) restores only the latest copy, and the 00:00Z level-9 snapshot heals that first. The damage only survives in the --at history, which nothing checks.
Blast radius. Every instance replicated by the activator's embedded litestream, on every box and both consoles' regions, after any wake, restart, deploy or config change, if the app writes more than about 1000 pages before litestream's next checkpoint. Migrations at deploy and test suites are the likely triggers; quiet apps are not exposed. The latest copy heals at the next daily snapshot; --at points in between stay broken until the 7-day retention removes them. A cheap read-only check: for each instances/<host>/0000/, list object versions (7 days are kept) and fetch only the first 100 bytes of each L0 (the LTX header, no tenant data). Flag any salt change whose next file is not litestream's 1-frame checkpoint L0 at offset 32 within 1 s. Each flag is a point where frames may have been lost; confirm with carlos db query --at. Cost is one ranged GET per L0, about $0.02 per busy app per week. I have the script; tell me if you want it run across the flagship.
Fix (code). Branch replica-read-lock-1443, 0d9047c5, not merged. firstSync runs the first Sync under a context that ends only if the start fails, and keeps its 30 s timeout around it. TestFirstSyncKeepsTheWALPinned (internal/lease) fails on main and passes on the branch, and go test ./internal/lease passes. Census: the internal/lease envelope is re-pinned with no unit changed; it needs the other-family review on #280. Upstream fixed the same bug in litestream 0.5.18 (acquireReadLock uses context.WithoutCancel). ltx 0.5.2, which comes with it, returns the swallowed header error. That bump also covers the case this branch leaves open: litestream checkpointing inside one of our short-context SyncAndWait calls on an awake instance. It is a follow-up because three tests depend on 0.5.14 behaviour (TestGenerationRefusedSnapshotReleasesWAL, TestRestoreToRetriesTheWholeRestoreOnce, TestRestoreToHoldsOneStreamAtATime). Note that go get also pulls pierrec/lz4 v4.1.23, which is retracted for dropping data; pin v4.1.34.
Alert/check proposal. (1) Agent tripwire: after each sync, read the header of the newest local L0. If the salt changed at offset 32 and it was not litestream's own checkpoint, write a snapshot at once (writeSnapshot already exists in continuity.go) and raise replica_wal_restart@<host>. That heals the latest copy and the alert names the window. (2) Drill: also restore the chain the newest snapshot replaced, to that snapshot's TXID, so damage the 00:00Z snapshot hides still fails a drill.
Recovery for equipo-staging (for your go; I did nothing). No command forces a snapshot today: a clean carlos restart proves continuity and writes none. The safe step needs no write. The store's next level-9 snapshot is taken from the live database and is due 2026-11-27 00:00Z (or at the first wake after that if the app is asleep). It replaces the damaged chain for latest reads. After 00:01Z, check with carlos db query --app equipo-staging --account oficina --sql "select 1", which should pass its integrity check. Until then, do not move equipo-staging or restore it from its replica. Do not run the suite straight after a restart until the fix is rolled. --at reads from 09:18:50Z up to that snapshot will stay broken until 2026-12-03.