| 
13 | 13 | 
 
  | 
14 | 14 | @dataclass  | 
15 | 15 | class WorkflowBrokerState:  | 
16 |  | -    """Asyncio-native broker state holder managed by the runtime.  | 
 | 16 | +    """Asyncio-native, serializable broker state for a single workflow run.  | 
17 | 17 | 
  | 
18 |  | -    Note: The state store remains owned by `Context` and is not included here.  | 
 | 18 | +    Owned and mutated by ``WorkflowBroker``; excludes the user state store  | 
 | 19 | +    (owned by ``Context``). See ``SerializedContext`` for the wire format.  | 
19 | 20 |     """  | 
20 | 21 | 
 
  | 
 | 22 | +    # True while a run is active; cleared on completion/timeout/cancel  | 
21 | 23 |     is_running: bool = False  | 
 | 24 | + | 
 | 25 | +    # Event stream for observers; broker writes lifecycle/system events here  | 
 | 26 | +    # A None item may be used as a sentinel for end-of-stream  | 
22 | 27 |     streaming_queue: asyncio.Queue[Event | None] = field(  | 
23 | 28 |         default_factory=lambda: asyncio.Queue()  | 
24 | 29 |     )  | 
 | 30 | + | 
 | 31 | +    # Per-step and waiter inbound queues: step name / waiter ID -> asyncio.Queue  | 
 | 32 | +    # Workers consume from these to drive step execution  | 
25 | 33 |     queues: dict[str, asyncio.Queue[Event]] = field(default_factory=dict)  | 
 | 34 | + | 
 | 35 | +    # Buffers used by collect_events: buffer_id -> fully.qualified.Event -> [Event]  | 
 | 36 | +    # Enables waiting for specific combinations of events  | 
26 | 37 |     event_buffers: dict[str, dict[str, list[Event]]] = field(default_factory=dict)  | 
 | 38 | + | 
 | 39 | +    # Step name -> list of input events currently being processed by that step  | 
 | 40 | +    # Also used to seed queues on deserialization so in-flight work can resume  | 
27 | 41 |     in_progress: dict[str, list[Event]] = field(default_factory=dict)  | 
 | 42 | + | 
 | 43 | +    # (step_name, input_event_class_name) recorded when a step outputs an event  | 
 | 44 | +    # Consumed by drawing/visualization utilities to reconstruct edges  | 
28 | 45 |     accepted_events: list[tuple[str, str]] = field(default_factory=list)  | 
 | 46 | + | 
 | 47 | +    # Append-only log of all events dispatched by the broker in order  | 
29 | 48 |     broker_log: list[Event] = field(default_factory=list)  | 
 | 49 | + | 
 | 50 | +    # Active waiter IDs to suppress duplicate waiter events (e.g., UI prompts)  | 
30 | 51 |     waiting_ids: set[str] = field(default_factory=set)  | 
31 | 52 | 
 
  | 
32 | 53 |     def to_serialized(self, serializer: BaseSerializer) -> SerializedContext:  | 
 | 
0 commit comments