Brief
Restore the memory and reading position of an interrupted calculation, then check that recovery gives the same result.
Imani's screen turns black just after the first record. Voss demands that the old graph be frozen. Mara hands you the sealed checkpoint and retained messages: reconstruct what the program should do at restart before the new timeline is published. The urgency belongs to the story; the exercise has no timer.
Your mission
- Write the SUPPLIER-SVC state and next position in the checkpoint.
- Process positions 41 and 42 after restoration.
- Compare local actions to the uninterrupted run and give the next position.
- Explain an external publication failure that the simulator cannot solve.
How to check your work
- State {OPEN-17}, next position 41.
- Repeat at 41 has no effect; E2 at 42 adds OPEN-18.
- Both runs have two commands; next position 43.
- External output requires idempotence or a transaction and a restart test.
Course example
from copy import deepcopy
events = [
{"offset": 40, "id": "E1", "command": "OPEN-17", "key": "SUPPLIER-SVC"},
{"offset": 41, "id": "E1", "command": "OPEN-17", "key": "SUPPLIER-SVC"},
{"offset": 42, "id": "E2", "command": "OPEN-18", "key": "SUPPLIER-SVC"},
]
def run(state, next_offset, actions):
for event in events:
if event["offset"] < next_offset:
continue
seen = state.setdefault(event["key"], set())
if event["command"] not in seen:
seen.add(event["command"])
actions.append(event["command"])
next_offset = event["offset"] + 1
return state, next_offset, actions
unbroken = run({}, 40, [])
snapshot = {"SUPPLIER-SVC": {"OPEN-17"}}, 41, ["OPEN-17"]
restored = run(deepcopy(snapshot[0]), snapshot[1], snapshot[2].copy())
print("unbroken", unbroken[2])
print("restored", restored[2])
print("same_result", unbroken[2] == restored[2])
print("next_offset", restored[1])