Open lesson

Mission: the command the reader can no longer see

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

Validate JSON stream changes and preserve incompatible messages for investigation without losing recognized commands.

Voss shows a table where OPEN-18 appears to disappear after a producer update. Mara suspects a JSON contract break; Imani refuses to have unknown messages erased. Explain what the reader accepts and quarantines before the fictional meeting. The countdown belongs to the plot; the exercise has no timer.

Your mission

  1. Name the required fields and types.
  2. Explain why the v2 message containing device remains readable to this practice reader.
  3. Explain the v3 problem and safe handling.
  4. List accepted commands and quarantined event IDs.

How to check your work

  • schema_version integer; event_id, command_id, credential strings.
  • v2 retains required fields, device is optional, and this reader supports v2.
  • v3 renames command_id; keep raw E4 in quarantine.
  • OPEN-17 and OPEN-18 accepted; E4 rejected without silent loss.

Course example

import json

raw_messages = [
    '{"schema_version":1,"event_id":"E1","command_id":"OPEN-17","credential":"SUPPLIER-SVC"}',
    '{"schema_version":2,"event_id":"E2","command_id":"OPEN-18","credential":"SUPPLIER-SVC","device":"KIOSK-2"}',
    '{"schema_version":3,"event_id":"E4","operation_id":"OPEN-19","credential":"SUPPLIER-SVC"}',
]
accepted, quarantined = [], []
for raw in raw_messages:
    message = json.loads(raw)
    valid = (
        type(message.get("schema_version")) is int
        and message["schema_version"] in (1, 2)
        and all(type(message.get(field)) is str
                for field in ("event_id", "command_id", "credential"))
        and ("device" not in message or type(message["device"]) is str)
    )
    if not valid:
        quarantined.append(message.get("event_id", "UNKNOWN"))
        continue
    accepted.append(message["command_id"])
print("accepted", accepted)
print("quarantined", quarantined)

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.

# Name the required fields and types.
# Explain why the v2 message containing device remains readable to this practice reader.
# Explain the v3 problem and safe handling.
# List accepted commands and quarantined event IDs.

exemple.py

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

import json

raw_messages = [
    '{"schema_version":1,"event_id":"E1","command_id":"OPEN-17","credential":"SUPPLIER-SVC"}',
    '{"schema_version":2,"event_id":"E2","command_id":"OPEN-18","credential":"SUPPLIER-SVC","device":"KIOSK-2"}',
    '{"schema_version":3,"event_id":"E4","operation_id":"OPEN-19","credential":"SUPPLIER-SVC"}',
]
accepted, quarantined = [], []
for raw in raw_messages:
    message = json.loads(raw)
    valid = (
        type(message.get("schema_version")) is int
        and message["schema_version"] in (1, 2)
        and all(type(message.get(field)) is str
                for field in ("event_id", "command_id", "credential"))
        and ("device" not in message or type(message["device"]) is str)
    )
    if not valid:
        quarantined.append(message.get("event_id", "UNKNOWN"))
        continue
    accepted.append(message["command_id"])
print("accepted", accepted)
print("quarantined", quarantined)