FAILURE MAP
← Case archive

FA-8046 / Undo and history / Open access

Undo stack transitions: Undo appends redo states in the wrong order · case 01

Undo appends redo states in the wrong order.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The undo future operation uses `future + [present]` where the contract requires `[present] + future`.

VERIFIED REPAIR

Implement the undo future operation as `[present] + future`.

Unsuccessful approach: Replacing the redo stack loses later states.

Case contract

Distinct edits push the old present and clear redo; undo and redo transfer one state while preserving order; no-op edits and unavailable traversal preserve history.

Why this case matters

A deterministic model of undo stack transitions; this isolates one interface invariant without requiring a browser.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(past, present, future, event, value):
    past, future = list(past), list(future)
    if event == 'edit' and value != present: return (past + [present], value, [])
    if event == 'undo' and past: return (past[:-1], past[-1], future + [present])
    if event == 'redo' and future: return (past + [present], future[0], future[1:])
    return (past, present, future)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('noop retains redo', solve(['a'], 'b', ['c'], 'edit', 'b'), (['a'], 'b', ['c']))
check('branch', solve(['a'], 'b', ['c'], 'edit', 'x'), (['a', 'b'], 'x', []))
check('undo', solve(['a','b'], 'c', ['d'], 'undo', None), (['a'], 'b', ['c', 'd']))
check('redo', solve(['a'], 'b', ['c','d'], 'redo', None), (['a', 'b'], 'c', ['d']))
check('empty undo', solve([], 'a', [], 'undo', None), ([], 'a', []))
check('empty redo', solve([], 'a', [], 'redo', None), ([], 'a', []))
check('parameterized history length', solve(list(range(N)), N, [], 'edit', N+1), (list(range(N+1)), N+1, []))
for repetition in range(N):
    check('repeat empty redo', solve([], 'a', [], 'redo', None), ([], 'a', []))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
noop retains redo[['a'], 'b', ['c']][['a'], 'b', ['c']]Passed
branch[['a', 'b'], 'x', []][['a', 'b'], 'x', []]Passed
undo[['a'], 'b', ['d', 'c']][['a'], 'b', ['c', 'd']]Failed
redo[['a', 'b'], 'c', ['d']][['a', 'b'], 'c', ['d']]Passed
empty undo[[], 'a', []][[], 'a', []]Passed
empty redo[[], 'a', []][[], 'a', []]Passed
parameterized history length[[0, 1], 2, []][[0, 1], 2, []]Passed
repeat empty redo[[], 'a', []][[], 'a', []]Passed

SHA-256 / 15db395de38175579c0dce343ecde02e2bf46ec5ec1036d89b3ac8a93fb72dee

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(past, present, future, event, value):
    past, future = list(past), list(future)
    if event == 'edit' and value != present: return (past + [present], value, [])
    if event == 'undo' and past: return (past[:-1], past[-1], [present])
    if event == 'redo' and future: return (past + [present], future[0], future[1:])
    return (past, present, future)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('noop retains redo', solve(['a'], 'b', ['c'], 'edit', 'b'), (['a'], 'b', ['c']))
check('branch', solve(['a'], 'b', ['c'], 'edit', 'x'), (['a', 'b'], 'x', []))
check('undo', solve(['a','b'], 'c', ['d'], 'undo', None), (['a'], 'b', ['c', 'd']))
check('redo', solve(['a'], 'b', ['c','d'], 'redo', None), (['a', 'b'], 'c', ['d']))
check('empty undo', solve([], 'a', [], 'undo', None), ([], 'a', []))
check('empty redo', solve([], 'a', [], 'redo', None), ([], 'a', []))
check('parameterized history length', solve(list(range(N)), N, [], 'edit', N+1), (list(range(N+1)), N+1, []))
for repetition in range(N):
    check('repeat empty redo', solve([], 'a', [], 'redo', None), ([], 'a', []))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
noop retains redo[['a'], 'b', ['c']][['a'], 'b', ['c']]Passed
branch[['a', 'b'], 'x', []][['a', 'b'], 'x', []]Passed
undo[['a'], 'b', ['c']][['a'], 'b', ['c', 'd']]Failed
redo[['a', 'b'], 'c', ['d']][['a', 'b'], 'c', ['d']]Passed
empty undo[[], 'a', []][[], 'a', []]Passed
empty redo[[], 'a', []][[], 'a', []]Passed
parameterized history length[[0, 1], 2, []][[0, 1], 2, []]Passed
repeat empty redo[[], 'a', []][[], 'a', []]Passed

SHA-256 / df772166c5c3a7dcd06f8b50c12ee755bec93d01a34c2c4ddd2705e98e0d2dfc

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(past, present, future, event, value):
    past, future = list(past), list(future)
    if event == 'edit' and value != present: return (past + [present], value, [])
    if event == 'undo' and past: return (past[:-1], past[-1], [present] + future)
    if event == 'redo' and future: return (past + [present], future[0], future[1:])
    return (past, present, future)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('noop retains redo', solve(['a'], 'b', ['c'], 'edit', 'b'), (['a'], 'b', ['c']))
check('branch', solve(['a'], 'b', ['c'], 'edit', 'x'), (['a', 'b'], 'x', []))
check('undo', solve(['a','b'], 'c', ['d'], 'undo', None), (['a'], 'b', ['c', 'd']))
check('redo', solve(['a'], 'b', ['c','d'], 'redo', None), (['a', 'b'], 'c', ['d']))
check('empty undo', solve([], 'a', [], 'undo', None), ([], 'a', []))
check('empty redo', solve([], 'a', [], 'redo', None), ([], 'a', []))
check('parameterized history length', solve(list(range(N)), N, [], 'edit', N+1), (list(range(N+1)), N+1, []))
for repetition in range(N):
    check('repeat empty redo', solve([], 'a', [], 'redo', None), ([], 'a', []))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
noop retains redo[['a'], 'b', ['c']][['a'], 'b', ['c']]Passed
branch[['a', 'b'], 'x', []][['a', 'b'], 'x', []]Passed
undo[['a'], 'b', ['c', 'd']][['a'], 'b', ['c', 'd']]Passed
redo[['a', 'b'], 'c', ['d']][['a', 'b'], 'c', ['d']]Passed
empty undo[[], 'a', []][[], 'a', []]Passed
empty redo[[], 'a', []][[], 'a', []]Passed
parameterized history length[[0, 1], 2, []][[0, 1], 2, []]Passed
repeat empty redo[[], 'a', []][[], 'a', []]Passed

SHA-256 / dae50cc92d1d321aec589e97f3f328c59a42305b416a5d870a20baf5d3824433

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:38:17.696897+00:00.

Case digest / 9bafee495f8974b1f50396a8fa0373aced5ed4c65af0af67bb75ac0cd8e97865