Open lesson

Mission: four door messages

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

Identify stream repetitions and process commands idempotently without discarding a genuine second command.

The control room shows four lines under SUPPLIER-SVC. Voss points to the screen and declares four openings. Imani gives you event IDs E1, E1, E3, E2; Mara adds command IDs OPEN-17, OPEN-17, OPEN-17, OPEN-18. Prepare an answer before the fictional meeting without deleting messages or activating a door. There is no exercise timer.

Your mission

  1. Count messages, distinct event IDs, and distinct command IDs.
  2. Identify the exact replay and the new delivery of an old action.
  3. Name the commands to apply once each.
  4. Explain why SUPPLIER-SVC cannot identify a person.

How to check your work

  • 4 messages, 3 event IDs, 2 command IDs.
  • Second line repeats E1; third has new E3 but OPEN-17 was already requested.
  • OPEN-17 then OPEN-18, once each.
  • A technical identity alone is insufficient to attribute human action.

Course example

messages = [
    {"event_id": "E1", "command_id": "OPEN-17", "credential": "SUPPLIER-SVC"},
    {"event_id": "E1", "command_id": "OPEN-17", "credential": "SUPPLIER-SVC"},
    {"event_id": "E3", "command_id": "OPEN-17", "credential": "SUPPLIER-SVC"},
    {"event_id": "E2", "command_id": "OPEN-18", "credential": "SUPPLIER-SVC"},
]
seen_events, applied_commands = set(), set()
for message in messages:
    seen_events.add(message["event_id"])
    if message["command_id"] not in applied_commands:
        applied_commands.add(message["command_id"])
        print("apply", message["command_id"])
print("messages", len(messages))
print("unique_events", len(seen_events))
print("unique_commands", len(applied_commands))

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.

# Count messages, distinct event IDs, and distinct command IDs.
# Identify the exact replay and the new delivery of an old action.
# Name the commands to apply once each.
# Explain why SUPPLIER-SVC cannot identify a person.

exemple.py

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

messages = [
    {"event_id": "E1", "command_id": "OPEN-17", "credential": "SUPPLIER-SVC"},
    {"event_id": "E1", "command_id": "OPEN-17", "credential": "SUPPLIER-SVC"},
    {"event_id": "E3", "command_id": "OPEN-17", "credential": "SUPPLIER-SVC"},
    {"event_id": "E2", "command_id": "OPEN-18", "credential": "SUPPLIER-SVC"},
]
seen_events, applied_commands = set(), set()
for message in messages:
    seen_events.add(message["event_id"])
    if message["command_id"] not in applied_commands:
        applied_commands.add(message["command_id"])
        print("apply", message["command_id"])
print("messages", len(messages))
print("unique_events", len(seen_events))
print("unique_commands", len(applied_commands))