Commit 15c7298
committed
graph: spec v0.4 middleware (proposal 0004) — phase 2
Implements pipeline-utilities §2-§7: middleware infrastructure plus
the two canonical middleware classes (Retry and Timing). Lands 16 of
the 18 PU middleware fixtures (001-016); fixtures 020-021 remain
skipped because they compose middleware with fan-out which arrives
in Phase 3.
Engine plumbing:
- middleware/_core.py: Middleware Protocol, NextCall alias,
compose_chain helper assembling outer-to-inner chains.
- nodes.py / subgraph.py: each node carries a per-node middleware
tuple; SubgraphNode treats its tuple as wrapping the dispatch as
a single atomic call per §4 isolation.
- builder.py: GraphBuilder.add_middleware for per-graph; per-node
middleware via add_node(..., middleware=[...]) and
add_subgraph_node(..., middleware=[...]).
- compiled.py: _step_function_node + _step_subgraph_node build the
runtime chain, inject the per-attempt event-dispatch innermost,
and let raw exceptions propagate through the chain so middleware
classifiers see the original exception's `category` attribute.
The engine wraps any exception that escapes the chain as
NodeException per §4.
Canonical middleware (middleware/retry.py, middleware/timing.py):
- RetryMiddleware with configurable max_attempts, classifier
(default matches `provider_rate_limit`, `provider_unavailable`,
`provider_model_not_loaded` — hardcoded canonical strings,
loose-coupled to llm-provider §7), backoff (exponential with full
jitter; deterministic_backoff factory for tests), on_retry
callback. CancelledError propagates via `except Exception`
(Python's CancelledError extends BaseException).
- TimingMiddleware with monotonic-clock duration measurement,
per-node node_name binding, on_complete callback that receives a
TimingRecord. Per-instance clock injection (defaulting to
time.monotonic) lets test fixtures supply a deterministic stub
without globally patching time.monotonic.
Conformance harness:
- middleware_seam.py: test-only middleware (TraceRecorder,
ShortCircuit, ErrorRecovery, ErrorRaiser, StateInspector) used
by the basic firing / composition / short-circuit / error-
recovery fixtures.
- test_pipeline_utilities.py: loads PU fixtures, translates
middleware blocks into instances, supports cases-shape fixtures
(014, 016), determinism re-runs (011), state-aware classifiers
(016), and the deterministic-monotonic clock_stub.
- adapter.py: extends build_graph with graph_middleware and
node_middleware kwargs and adds the `flaky` node directive.
Unit tests (test_middleware.py): chain composition + ordering,
short-circuit, pre/post phase symmetry, retry counting + classifier,
retry cancellation propagation, general error recovery, timing on
success and failure, subgraph isolation, default classifier
behavior across direct / via-cause / non-transient cases.
Total tests: 246 passing, 1 skipped (017 fan-out, Phase 3).1 parent fa74c5a commit 15c7298
13 files changed
Lines changed: 1788 additions & 37 deletions
File tree
- src/openarmature/graph
- middleware
- tests
- conformance
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
| |||
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
| |||
58 | 67 | | |
59 | 68 | | |
60 | 69 | | |
| 70 | + | |
61 | 71 | | |
62 | 72 | | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
67 | 77 | | |
| 78 | + | |
| 79 | + | |
68 | 80 | | |
69 | 81 | | |
| 82 | + | |
| 83 | + | |
70 | 84 | | |
71 | 85 | | |
72 | 86 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
52 | 62 | | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
57 | 69 | | |
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
61 | 73 | | |
62 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
63 | 91 | | |
64 | 92 | | |
65 | 93 | | |
| |||
142 | 170 | | |
143 | 171 | | |
144 | 172 | | |
| 173 | + | |
145 | 174 | | |
146 | 175 | | |
147 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
116 | 120 | | |
117 | 121 | | |
118 | 122 | | |
| |||
263 | 267 | | |
264 | 268 | | |
265 | 269 | | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
273 | 281 | | |
274 | 282 | | |
275 | 283 | | |
| |||
297 | 305 | | |
298 | 306 | | |
299 | 307 | | |
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 | + | |
308 | 326 | | |
309 | 327 | | |
310 | 328 | | |
311 | | - | |
312 | 329 | | |
313 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
314 | 396 | | |
315 | 397 | | |
316 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
317 | 401 | | |
318 | | - | |
319 | | - | |
320 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
321 | 421 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
327 | 427 | | |
328 | | - | |
329 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
330 | 448 | | |
331 | 449 | | |
332 | 450 | | |
| |||
335 | 453 | | |
336 | 454 | | |
337 | 455 | | |
| 456 | + | |
| 457 | + | |
338 | 458 | | |
339 | 459 | | |
340 | 460 | | |
| |||
347 | 467 | | |
348 | 468 | | |
349 | 469 | | |
| 470 | + | |
350 | 471 | | |
351 | 472 | | |
352 | 473 | | |
| |||
360 | 481 | | |
361 | 482 | | |
362 | 483 | | |
| 484 | + | |
363 | 485 | | |
364 | 486 | | |
365 | 487 | | |
| |||
372 | 494 | | |
373 | 495 | | |
374 | 496 | | |
| 497 | + | |
375 | 498 | | |
376 | 499 | | |
0 commit comments