Open lesson

Mission: the calculation goes dark

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

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

  1. Write the SUPPLIER-SVC state and next position in the checkpoint.
  2. Process positions 41 and 42 after restoration.
  3. Compare local actions to the uninterrupted run and give the next position.
  4. 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])

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with # are task reminders. Python ignores them. Write your code beneath them.

Python console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.py

Current editor source. Inspection shows your current edits.

# 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.

exemple.py

Declarative lesson asset; this is not a file created in the Python filesystem.

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])