Repository navigation
Commit 33439bf
authored
Python: Pass stream errors to nested streams when closing them (#9476)
* Python: Pass stream errors to nested streams when closing them
When a ResponseStream failed or was cancelled, close() shut nested ResponseStreams without the error, so their cleanup hooks treated the run as successful. With agent middleware this made the agent telemetry stream call get_final_response(), which ran every ContextProvider.after_run and saved the partial turn to history. close() now takes the terminal error and records it on itself and on nested streams while their cleanup hooks run.
* Python: Pass stream errors to nested streams in buffered mode too
A transform failure or cancellation in a buffered outer stream went through _abort_buffered_materialization, which closed the stream without the error, so the nested stream still ran its cleanup as a normal completion. It now passes the recorded error to close(), and the regression test gains a buffered variant.1 parent d0c3e6a commit 33439bf
2 files changed
Lines changed: 62 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4594 | 4594 | | |
4595 | 4595 | | |
4596 | 4596 | | |
4597 | | - | |
| 4597 | + | |
4598 | 4598 | | |
4599 | 4599 | | |
4600 | 4600 | | |
| |||
4780 | 4780 | | |
4781 | 4781 | | |
4782 | 4782 | | |
4783 | | - | |
| 4783 | + | |
4784 | 4784 | | |
4785 | 4785 | | |
4786 | 4786 | | |
4787 | 4787 | | |
4788 | | - | |
| 4788 | + | |
4789 | 4789 | | |
4790 | 4790 | | |
4791 | 4791 | | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
4792 | 4795 | | |
4793 | 4796 | | |
4794 | 4797 | | |
4795 | 4798 | | |
4796 | 4799 | | |
4797 | 4800 | | |
4798 | | - | |
| 4801 | + | |
4799 | 4802 | | |
4800 | 4803 | | |
4801 | 4804 | | |
| |||
4806 | 4809 | | |
4807 | 4810 | | |
4808 | 4811 | | |
4809 | | - | |
| 4812 | + | |
| 4813 | + | |
| 4814 | + | |
| 4815 | + | |
4810 | 4816 | | |
4811 | 4817 | | |
4812 | 4818 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| 40 | + | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| |||
5616 | 5622 | | |
5617 | 5623 | | |
5618 | 5624 | | |
| 5625 | + | |
| 5626 | + | |
| 5627 | + | |
| 5628 | + | |
| 5629 | + | |
| 5630 | + | |
| 5631 | + | |
| 5632 | + | |
| 5633 | + | |
| 5634 | + | |
| 5635 | + | |
| 5636 | + | |
| 5637 | + | |
| 5638 | + | |
| 5639 | + | |
| 5640 | + | |
| 5641 | + | |
| 5642 | + | |
| 5643 | + | |
| 5644 | + | |
| 5645 | + | |
| 5646 | + | |
| 5647 | + | |
| 5648 | + | |
| 5649 | + | |
| 5650 | + | |
| 5651 | + | |
| 5652 | + | |
| 5653 | + | |
| 5654 | + | |
| 5655 | + | |
| 5656 | + | |
| 5657 | + | |
| 5658 | + | |
| 5659 | + | |
| 5660 | + | |
| 5661 | + | |
| 5662 | + | |
| 5663 | + | |
| 5664 | + | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
5619 | 5670 | | |
5620 | 5671 | | |
5621 | 5672 | | |
| |||
0 commit comments