Commit 27f657b
Alex Wang
fix(plugin): report SUSPENDED user functions
wrap_user_function re-raised SuspendExecution without calling
on_user_function_end, so a user function that stopped so the
execution could resume later never reported its end. Plugins were
expected to "observe it by absence" and clean up during their own
invocation-end sweep.
That contract cannot be honoured for state that is
thread-confined. The OTel plugins attach an opentelemetry.context
token in on_user_function_start, and a token is only detachable in
the contextvars.Context that created it -- the user-code worker
thread, not the handler thread the invocation hooks run on. A
suspended operation therefore stranded its context scope with no
hook able to release it. The same applies to any plugin holding
per-operation state: a timer, an open log group, a span.
The Java SDK already fires the end hook here.
BaseDurableOperation.runUserFunction catches Throwable -- which
covers SuspendExecutionException -- and its javadoc gives the same
reason: onUserFunctionEnd fires for failures and suspensions alike
so plugins can clean up the attempt rather than leak state.
Changes:
- Add UserFunctionOutcome.SUSPENDED. Suspension is its own
outcome rather than reusing FAILED: nothing went wrong, and
plugins that count failures or set an error status must not
treat it as one. Java models this as succeeded=false plus the
suspend exception as the error, which reads as a failure to
exactly those consumers.
- Allow an explicit outcome on UserFunctionEndInfo.from_start_info
and PluginExecutor.on_user_function_end, so the suspension path
reports SUSPENDED with error=None instead of deriving the
outcome from an absent error.
- Fire the hook from wrap_user_function's SuspendExecution branch
and re-raise unchanged, so durable control flow is untouched.
- Teach both OTel plugins to treat SUSPENDED as "release the
scope, leave the span open": the attempt has not concluded, so
it must not be ended with an outcome here. It is ended when the
operation reaches a terminal status, matching how an operation
that suspends mid-invocation is already handled.
test_wrap_user_function_suspend_does_not_fire_end_hook pinned the
old behaviour and is inverted accordingly. Adds an end-to-end test
driving a real child context that suspends, and OTel tests
asserting a suspended attempt releases its scope, exports nothing,
and is never marked ERROR.
Note for reviewers: this makes Python the first of the three SDKs
with a third user-function outcome. JS has no hook on this path at
all, and Java reports suspension through the existing boolean. A
follow-up should decide whether JS and Java adopt SUSPENDED.1 parent 8ace0f5 commit 27f657b
8 files changed
Lines changed: 181 additions & 14 deletions
File tree
- packages
- 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: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
560 | 567 | | |
561 | 568 | | |
562 | 569 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
665 | 672 | | |
666 | 673 | | |
667 | 674 | | |
| |||
Lines changed: 62 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
432 | 452 | | |
433 | 453 | | |
434 | 454 | | |
| |||
747 | 767 | | |
748 | 768 | | |
749 | 769 | | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
750 | 812 | | |
751 | 813 | | |
752 | 814 | | |
| |||
Lines changed: 30 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
166 | 173 | | |
167 | 174 | | |
168 | 175 | | |
| |||
187 | 194 | | |
188 | 195 | | |
189 | 196 | | |
190 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
191 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
192 | 211 | | |
193 | 212 | | |
194 | 213 | | |
| |||
200 | 219 | | |
201 | 220 | | |
202 | 221 | | |
203 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
204 | 225 | | |
205 | 226 | | |
206 | 227 | | |
| |||
622 | 643 | | |
623 | 644 | | |
624 | 645 | | |
625 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
626 | 652 | | |
627 | 653 | | |
628 | | - | |
| 654 | + | |
629 | 655 | | |
630 | 656 | | |
631 | 657 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
1170 | 1171 | | |
1171 | 1172 | | |
1172 | 1173 | | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
1173 | 1184 | | |
1174 | 1185 | | |
1175 | 1186 | | |
| |||
Lines changed: 46 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2923 | 2923 | | |
2924 | 2924 | | |
2925 | 2925 | | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
2926 | 2932 | | |
2927 | 2933 | | |
2928 | 2934 | | |
| |||
3182 | 3188 | | |
3183 | 3189 | | |
3184 | 3190 | | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
| 3230 | + | |
3185 | 3231 | | |
3186 | 3232 | | |
3187 | 3233 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1788 | 1788 | | |
1789 | 1789 | | |
1790 | 1790 | | |
1791 | | - | |
| 1791 | + | |
1792 | 1792 | | |
1793 | 1793 | | |
1794 | 1794 | | |
| |||
Lines changed: 17 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
4821 | 4822 | | |
4822 | 4823 | | |
4823 | 4824 | | |
4824 | | - | |
4825 | | - | |
| 4825 | + | |
| 4826 | + | |
4826 | 4827 | | |
4827 | | - | |
4828 | | - | |
4829 | | - | |
4830 | | - | |
4831 | | - | |
4832 | | - | |
| 4828 | + | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
| 4832 | + | |
| 4833 | + | |
| 4834 | + | |
| 4835 | + | |
4833 | 4836 | | |
4834 | 4837 | | |
4835 | 4838 | | |
| |||
4858 | 4861 | | |
4859 | 4862 | | |
4860 | 4863 | | |
4861 | | - | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
4862 | 4870 | | |
4863 | 4871 | | |
4864 | 4872 | | |
| |||
0 commit comments