Commit 3f67c71
fix(sdk): keep chat.history edits made in onTurnComplete after a failed turn
`chat.agent` now keeps a `chat.history` edit made inside
`onTurnComplete` after a failed turn. Previously the edit was applied
only when the turn succeeded, so a failure record or a card the hook
closed on the error path never reached the transcript.
Details of the error-path behaviour:
- The edit is converted to model messages before any state is replaced,
so a conversion that throws (for example from a tool's `toModelOutput`)
leaves the history exactly as it was.
- The stream's partial answer stays marked non-final only while the
message under its id is still that partial by content. A hook that
clones the history keeps it partial; a hook that finishes it in place
saves it as final.
- A history edit left pending by an earlier hook that threw is discarded
before the failed turn continues, whether or not the agent defines
`onTurnComplete`, so it can never be mistaken for a later hook's edit or
leak into the next turn.
Includes a changeset for `@trigger.dev/sdk` (patch).
Mono-RevId: ac849a203949f8a719a8c33866004cf517d5f7951 parent 8b72e6c commit 3f67c71
4 files changed
Lines changed: 459 additions & 3 deletions
File tree
- .changeset
- packages/trigger-sdk
- src/v3
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
1138 | 1139 | | |
1139 | 1140 | | |
1140 | 1141 | | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1141 | 1160 | | |
1142 | 1161 | | |
1143 | 1162 | | |
| |||
10098 | 10117 | | |
10099 | 10118 | | |
10100 | 10119 | | |
| 10120 | + | |
| 10121 | + | |
| 10122 | + | |
| 10123 | + | |
| 10124 | + | |
10101 | 10125 | | |
10102 | 10126 | | |
10103 | 10127 | | |
| |||
10188 | 10212 | | |
10189 | 10213 | | |
10190 | 10214 | | |
| 10215 | + | |
| 10216 | + | |
| 10217 | + | |
| 10218 | + | |
| 10219 | + | |
| 10220 | + | |
10191 | 10221 | | |
10192 | 10222 | | |
10193 | 10223 | | |
| |||
10218 | 10248 | | |
10219 | 10249 | | |
10220 | 10250 | | |
| 10251 | + | |
| 10252 | + | |
| 10253 | + | |
| 10254 | + | |
| 10255 | + | |
| 10256 | + | |
| 10257 | + | |
| 10258 | + | |
| 10259 | + | |
| 10260 | + | |
| 10261 | + | |
| 10262 | + | |
| 10263 | + | |
| 10264 | + | |
| 10265 | + | |
| 10266 | + | |
| 10267 | + | |
| 10268 | + | |
10221 | 10269 | | |
10222 | 10270 | | |
10223 | 10271 | | |
| |||
10232 | 10280 | | |
10233 | 10281 | | |
10234 | 10282 | | |
| 10283 | + | |
10235 | 10284 | | |
10236 | 10285 | | |
10237 | 10286 | | |
| |||
10250 | 10299 | | |
10251 | 10300 | | |
10252 | 10301 | | |
10253 | | - | |
10254 | | - | |
| 10302 | + | |
| 10303 | + | |
| 10304 | + | |
| 10305 | + | |
| 10306 | + | |
| 10307 | + | |
| 10308 | + | |
| 10309 | + | |
10255 | 10310 | | |
10256 | 10311 | | |
10257 | 10312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
| |||
0 commit comments