Commit 8426217
fix: settle nested streamed agent tool outputs
Move nested streamed agent-tool output settlement back to the normal turn-resolution path by concatenating all text segments from the final assistant message before plain-text return or structured-output validation. This fixes empty or truncated outputs for successful nested streaming runs, including cases where an MCP tool failure is handled and followed by a final assistant message.
Preserve caller cancellation semantics for as_tool(..., on_stream=...) by re-raising outer cancellation and cancelling the background stream-dispatch task promptly instead of converting CancelledError into a successful tool result.
Add regression coverage for multi-segment plain-text settlement, multi-segment structured-output settlement, nested MCP cancellation and McpError failures followed by final output, and prompt parent cancellation while the on_stream handler is blocked.
Co-authored-by: Codex <noreply@openai.com>1 parent 05cc57c commit 8426217
3 files changed
Lines changed: 189 additions & 414 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
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 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | 121 | | |
176 | 122 | | |
177 | 123 | | |
| |||
843 | 789 | | |
844 | 790 | | |
845 | 791 | | |
| 792 | + | |
846 | 793 | | |
847 | 794 | | |
848 | 795 | | |
| |||
860 | 807 | | |
861 | 808 | | |
862 | 809 | | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
| 810 | + | |
| 811 | + | |
869 | 812 | | |
870 | | - | |
871 | | - | |
872 | | - | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
873 | 823 | | |
874 | 824 | | |
875 | 825 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
618 | | - | |
| 618 | + | |
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
| |||
0 commit comments