--- id: "bug-1147" status: "fixed" status_updated: "2026-09-24" status_note: "" component: "controller" severity: "unknown" timestamp: "2026-06-26T03:46:38.904419+00:00" last_seen: "2026-09-19T09:00:00Z" occurrences: 1 files: ["src/controller/persist.c:1374 (trim_wal_segments)"] tags: ["durability", "permanent-gap", "stale-report", "trim", "bug-828", "raft-drive-async", "latent", "catch-up", "wal", "snapshot", "bug-795"] related: ["bug-795", "bug-828", "bug-1060"] legacy: true --- # bug-1147: WAL trim_wal_segments deletes any closed segment regardless of standby catch-up cursor →… ## Description WAL trim_wal_segments deletes any closed segment regardless of standby catch-up cursor → lagging/empty-rejoin standby loses its needed log range with no snapshot backfill (permanent committed-prefix gap) ## Environment _Not recorded (migrated from buglog.json)._ ## Reproduction _Not recorded (migrated from buglog.json)._ ## Root cause trim_wal_segments bounds deletion ONLY by active_seg_lsn (the currently-open segment): `if (seg_start_lsn < active_seg_lsn) unlink()`. It consults no standby acked_lsn, no committed_lsn, no in-flight snapshot boundary. Strategy-A (cursor-bounded retention) discipline is absent. Strategy-B (entity-bearing snapshot install) is also not live — write_snapshot (persist.c:1247) writes only a 16-byte P0 sentinel, not materialized state. So a standby that lags by more than ~one open segment (down across segment rolls, slow link, >64MB lag, or empty rejoin from cursor=0) hits a log range that exists nowhere and cannot catch up. ## Fix FIXED (verified 2026-07-02): src/controller/persist.c trim_wal_segments() computes `floor = repl_trim_lsn(&p->repl, active_seg_lsn, p->config.snap_interval_s)` (min of active segment, all standby acked_lsn, disconnected-slot guards) and only unlinks segments below that floor — comment inline explicitly cites 'bug-1147 guard'. Landed under raft-drive-async task 3.2 (all leaf tasks complete). ## Verification _Not recorded (migrated from buglog.json)._ ## References - Related: bug-795, bug-828, bug-1060