Nested glass palette edits leave changes behind after cancellation
Level 3 · node · Data · Loss of parent undo records when a nested transaction commits
Scenario
A fictional stained glass workshop records piece counts by color in a palette. A large edit can contain smaller edits. Even when an inner edit commits, canceling the outer edit must restore the initial state. Standalone cancellation works, but after an inner edit commits and the outer edit fails, some color counts remain changed. Trace the entry point, editing service, change journal, and store.
Requirements
createPalette(initial) creates an independent palette. edit(work) supplies set(color, count), remove(color), and edit(work) to a synchronous callback; counts are nonnegative integers. On normal completion return the callback result unchanged. On an exception undo that edit and rethrow the same exception. An inner commit remains provisional until the outer edit commits, and an inner rollback must preserve earlier outer changes. Apply the same rules to repeated changes, additions and deletions of a color, and nesting of three or more levels. read() returns an independent object of current counts. Keep the existing change journal rather than cloning the entire palette per edit.
Acceptance criteria
- Standalone edits preserve return values and exceptions and restore the prior palette on cancellation.
- If an outer edit fails after an inner edit succeeds, undo all changes, including repeated writes, additions, and deletions.
- If the outer edit handles an inner failure, undo only the inner changes and allow the outer edit to continue and commit.
- After canceling an outer edit with three nesting levels, restore the initial state and allow later edits and independent reads.