Keep recovered AOF tails at committed transaction boundaries

perfloop-oss/redis · Uncatalogued correctness

https://perfloop.ai/t/oss/case_pwvxweczef

Verdict

VERIFIED · settled 2026-11-05 · pull request opened as redis/redis#16178

What happened: The check fails before this change and passes with it.

Hypothesis

AOF recovery can start successfully while retaining an unfinished transaction in the log. Memory excludes that transaction, but the retained bytes still contain MULTI. A normal write accepted after recovery can then disappear on the next restart. Crash incidence and performance cost are unknown.

In loadSingleAppendOnlyFile, valid_up_to advances after parsed commands, including commands queued under CLIENT_MULTI. Only the clean-EOF block at lines 2035–2044 restores valid_before_multi. Short reads jump directly to uxeof, and recoverable format errors truncate directly in fmterr. Both can retain a transaction that freeClient subsequently discards from memory.

The native checkProperty run for prop_8z4ws5p2h3 at revision 41888396080aab24ad5218f2e45e66158e24884b ran bash tests/integration/aof-recovery-property/run-transaction.sh and exited 1 after 20 inputs, stopping at the first violation in each fault family. An incremental file containing INCR committed, MULTI, and one byte of the next RESP command retained MULTI after short-read recovery. Replacing that final byte with a format-error line produced the same result with aof-load-corrupt-tail-max-size 4096. In each case INCR after replied 1 after recovery, but GET after was absent at the second startup. The test used appendfsync always, disabled rewrites and RDB saves, and checked the exact retained bytes. Clean EOF inside MULTI and a completed EXEC passed as controls. The run returned two exact replay inputs for retention on the property node; its earlier invocation had a test-assert arity error and supplied no counterexample evidence.

The benefiting operation is startup from an interrupted final incremental AOF. Short-read recovery uses aof-load-truncated yes; format-error recovery additionally needs a nonzero corrupt-tail limit. The source documents interrupted tails as a supported recovery condition. This is a consistency repair, not optional security hardening. It should need only checkpoint/exit-state coordination within this loader, not a new persistence format or transaction executor.

The next Case check is to replay the two stored inputs, then cover queued transaction commands, partial EXEC, complete EXEC, clean EOF and recovery-disabled controls. Confirmation requires the recovered keys and retained prefix to agree and the subsequent ordinary append to survive another startup. A retained open transaction, lost committed data or lost later append rejects the repair.

Current upstream implementation https://github.com/redis/redis/pull/16128 refuses AOF rewrite when a forced flush leaves buffered writes; it does not change loader transaction checkpoints or these recovery exits. https://github.com/redis/redis/pull/15932 changes post-rename manifest error handling, also a different mechanism. The older open-PR inventory is still being followed, so these inspected changes are not a claim of repository-wide upstream clearance. Prior finding hyp_jbdrzx0fgr changes checkpoint representation and compaction rather than this existing-format replay invariant.

Change to test: Use a transaction-safe committed boundary for durable truncation on every successful recovery exit, not only clean EOF. Preserve completed transactions and the configured recovery-failure policy, and establish that a normal append after recovery remains replayable on another startup.

Where it lives

perfloop-oss/redis · src/server.c

Evidence

The check fails before this change and passes with it: `For interrupted final AOFs with a committed RESP or RDB prefix followed by an unfinished MULTI/EXEC, enabled short-read recovery, or corrupt-tail recovery with all discarded bytes strictly below the configured limit, retains exactly the committed prefix and its keys; a subsequent acknowledged append survives restart. Complete EXECs remain committed, and disabled recovery or a rollback at or above the corrupt-tail limit refuses startup without changing the file.`

Checks: 2 of 2 passed. Verification: no defect found.

Timeline