Commit 7bfddca
committed
fix(plugin): give each invocation its own plugin session and log correlation
Review findings on the per-invocation plugin contract. The first one meant the
contract change did not actually deliver what it promised under concurrency.
`durable_execution` built one `PluginExecutor` at decoration time and every
invocation shared it, while the executor stored that invocation's plugin
instances, invocation metadata and operations provider on itself. So the SDK
created one plugin per invocation and then parked it in a shared mutable slot.
Measured with two invocations held inside their user function at once,
invocation A's operation hook was delivered to B's plugin and A's plugin never
received its own operation or end hook; in a second scenario A's scope exit
cleared the shared state while B was live and B lost `on_invocation_end`
entirely.
A new handler-lifetime `PluginHost` now holds nothing but the resolved factory
list and hands out a fresh `PluginExecutor` per invocation, which is the shape
JS and Java already had. The executor is reachable only from the frames of the
invocation that owns it, and a second `run()` on one executor raises, so reuse
fails loudly instead of as silent crosstalk. Its thread pool is per invocation
too: sharing one would let an ending invocation shut down a pool a concurrent
invocation was still submitting to.
The OTel log filter had the same class of bug. It held one mutable plugin
reference, so with two invocations open the one that started last won and every
other invocation's records carried its trace. Reading the active span from the
OTel context, as the Java plugin does, is not sufficient here: the invocation
span is never attached to the context, and the SDK runs the handler body on a
pool thread that does not inherit the context of the thread the plugin bound on.
The filter is now stateless and resolves per record, preferring the invocation
that claimed the emitting thread through a `ContextVar` and falling back to the
single open invocation when exactly one is open. With several open and an
unclaimed thread it leaves the record unstamped, because an unattributed record
is a smaller defect than one attributed to another customer's execution.
Installation is serialized so concurrent first-time callers cannot stack
filters.
Third, the Insight scheduler used `0` for both "no flush in flight" and "a flush
in flight covering zero exports", which are different facts. An invocation that
emitted no record could not tell that its flush was already running, so it
requested a second one that then ran after both invocations had returned —
customer exporter code past the invocation boundary, which the flush contract
forbids. Absence is now `None` and coverage an integer.1 parent f011990 commit 7bfddca
13 files changed
Lines changed: 842 additions & 152 deletions
File tree
- packages
- aws-durable-execution-sdk-python-insight
- src/aws_durable_execution_sdk_python_insight
- tests
- aws-durable-execution-sdk-python-otel
- src/aws_durable_execution_sdk_python_otel
- tests
- aws-durable-execution-sdk-python
- src/aws_durable_execution_sdk_python
- tests
Lines changed: 26 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| |||
202 | 208 | | |
203 | 209 | | |
204 | 210 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
214 | 220 | | |
215 | 221 | | |
216 | 222 | | |
| |||
260 | 266 | | |
261 | 267 | | |
262 | 268 | | |
263 | | - | |
| 269 | + | |
264 | 270 | | |
265 | 271 | | |
266 | 272 | | |
| |||
304 | 310 | | |
305 | 311 | | |
306 | 312 | | |
307 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
308 | 317 | | |
309 | 318 | | |
310 | 319 | | |
| |||
353 | 362 | | |
354 | 363 | | |
355 | 364 | | |
356 | | - | |
| 365 | + | |
357 | 366 | | |
358 | 367 | | |
359 | 368 | | |
| |||
Lines changed: 91 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
433 | 519 | | |
434 | 520 | | |
435 | 521 | | |
| |||
475 | 561 | | |
476 | 562 | | |
477 | 563 | | |
478 | | - | |
| 564 | + | |
479 | 565 | | |
480 | 566 | | |
481 | 567 | | |
482 | 568 | | |
483 | 569 | | |
484 | | - | |
485 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
486 | 573 | | |
487 | 574 | | |
488 | 575 | | |
| |||
503 | 590 | | |
504 | 591 | | |
505 | 592 | | |
506 | | - | |
| 593 | + | |
507 | 594 | | |
508 | 595 | | |
509 | 596 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
434 | 437 | | |
435 | 438 | | |
436 | 439 | | |
| |||
Lines changed: 33 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| |||
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | | - | |
181 | | - | |
182 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
| |||
426 | 433 | | |
427 | 434 | | |
428 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
429 | 442 | | |
430 | 443 | | |
431 | 444 | | |
| |||
660 | 673 | | |
661 | 674 | | |
662 | 675 | | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
663 | 680 | | |
664 | 681 | | |
665 | 682 | | |
666 | 683 | | |
667 | 684 | | |
668 | 685 | | |
| 686 | + | |
669 | 687 | | |
670 | 688 | | |
671 | 689 | | |
| |||
675 | 693 | | |
676 | 694 | | |
677 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
678 | 704 | | |
679 | 705 | | |
680 | 706 | | |
| |||
807 | 833 | | |
808 | 834 | | |
809 | 835 | | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
810 | 839 | | |
811 | 840 | | |
812 | 841 | | |
| |||
0 commit comments