Commit 75740a9
authored
graph: spec v0.3 observer hooks (proposal 0003) (#5)
* graph: spec v0.3 observer hooks (proposal 0003)
Implement spec v0.3 / proposal 0003: node-boundary observer hooks.
A `NodeEvent` is dispatched once per node execution onto a per-
invocation delivery queue that runs concurrently with the graph's
execution loop.
Public surface:
- `NodeEvent` (frozen dataclass): node_name, namespace tuple, step,
pre/post state, error category+instance, parent_states tuple.
- `Observer` Protocol: async callable receiving a NodeEvent;
parameter is positional-only so conformance isn't tied to a
parameter name.
- `CompiledGraph.attach_observer(fn) -> RemoveHandle` for graph-
attached observers; `invoke(state, observers=...)` for invocation-
scoped.
- `CompiledGraph.drain()` awaits delivery of every event dispatched
by prior invocations of this graph.
Delivery semantics per spec §6:
- Strictly serial within an invocation: no two observers process the
same event concurrently; no observer sees event N+1 until everyone
has finished N. Order is graph-attached (outermost → innermost),
then invocation-scoped, both in registration order.
- Async-from-graph: invoke() returns when the graph reaches END
regardless of queue state. Use drain() for short-lived processes.
- Observer exceptions are caught and reported via warnings.warn —
they don't break siblings, subsequent events, or the graph run.
- Subgraph-internal events bubble up: the subgraph wrapper itself
does NOT generate an event (per fixture 013); only its inner nodes
do. Step counter spans the subgraph boundary; namespace and
parent_states extend.
Bumps openarmature to 0.4.0 and the spec submodule to v0.3.1.
* graph: address PR #5 review
CodeQL noise (10 threads): replace bare `...` Protocol/stub bodies
with explicit forms. `Observer.__call__` gets a docstring +
`raise NotImplementedError` (so pyright accepts the declared return
type, same pattern as Protocol bodies fixed in #4); test stub
observers get `pass`. Add an explanatory comment to
`RemoveHandle.remove`'s `try/except ValueError: pass` documenting
the idempotency intent the docstring already promises.
Logic (2 threads):
- `_active_workers` switched from list to set and each per-
invocation worker now registers add_done_callback(
self._active_workers.discard). Long-running services that
never call drain() no longer accumulate completed Task
references indefinitely. drain() simplifies to a one-line
asyncio.gather over a snapshot of the set.
- SubgraphNode branch in _invoke now wraps non-RuntimeGraphError
exceptions from node.run(state, context=context) as
NodeException tagged with the wrapper's name. Projection
errors (project_in / project_out) and subgraph state-class
init errors (e.g. Pydantic ValidationError) were previously
propagating raw, bypassing the spec §4 error contract. Already-
wrapped errors from inside the subgraph's _invoke pass through
unchanged so the inner node's identity stays attached. Adds
test_subgraph_projection_error_wrapped_as_node_exception
covering the case.1 parent d53fefc commit 75740a9
15 files changed
Lines changed: 1026 additions & 80 deletions
File tree
- src/openarmature
- graph
- tests
- conformance
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
Submodule openarmature-spec updated 16 files
- .github/workflows/validate-fixtures.yaml+25
- .github/workflows/validate-markdown.yaml+24
- CHANGELOG.md+17
- README.md+27
- proposals/0003-node-boundary-observer-hooks.md+23-7
- scripts/validate_fixtures.py+45
- scripts/validate_markdown_links.py+106
- spec/graph-engine/conformance/012-observer-basic-firing.md+83
- spec/graph-engine/conformance/012-observer-basic-firing.yaml+89
- spec/graph-engine/conformance/013-observer-subgraph-namespacing-and-ordering.md+61
- spec/graph-engine/conformance/013-observer-subgraph-namespacing-and-ordering.yaml+159
- spec/graph-engine/conformance/014-observer-error-event.md+34
- spec/graph-engine/conformance/014-observer-error-event.yaml+65
- spec/graph-engine/conformance/015-observer-error-isolation.md+43
- spec/graph-engine/conformance/015-observer-error-isolation.yaml+92
- spec/graph-engine/spec.md+124-8
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| 54 | + | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| 60 | + | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
16 | | - | |
17 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| |||
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
| 39 | + | |
30 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
31 | 50 | | |
32 | 51 | | |
| 52 | + | |
33 | 53 | | |
34 | 54 | | |
35 | 55 | | |
| |||
77 | 97 | | |
78 | 98 | | |
79 | 99 | | |
80 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
81 | 107 | | |
82 | 108 | | |
83 | 109 | | |
84 | 110 | | |
85 | 111 | | |
86 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
87 | 141 | | |
88 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
89 | 171 | | |
90 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
91 | 182 | | |
92 | 183 | | |
93 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
94 | 224 | | |
95 | 225 | | |
96 | 226 | | |
97 | 227 | | |
98 | 228 | | |
99 | 229 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
110 | 249 | | |
111 | | - | |
112 | 250 | | |
113 | 251 | | |
114 | 252 | | |
| |||
125 | 263 | | |
126 | 264 | | |
127 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
0 commit comments