FAILURE MAP
← Case archive

FA-8041 / Undo and history / Open access

Undo stack transitions: Undo leaves the restored state on the undo stack · case 01

Undo leaves the restored state on the undo stack.

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

ROOT CAUSE

The undo past operation uses `past, past[-1]` where the contract requires `past[:-1], past[-1]`.

VERIFIED REPAIR

Implement the undo past operation as `past[:-1], past[-1]`.

Unsuccessful approach: Removing the oldest state restores history out of order.

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, 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'], 'b', ['c', 'd']][['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 / aec30b85ae56b39fc91732c0b75094bdf979b7c85184752f01e4bb5cba5385e0

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[0], [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[['b'], 'a', ['c', 'd']][['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 / 78bd1cb5ad9bceb79d85eb8be42f9dadc2216eb44250b4c6f3a4e1ec3aaac758

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.571698+00:00.

Case digest / 2f29885647b2a17d1eec679e787f191922ba375b67bf7cf032d6a6aa503eb147