Commit 4783419
authored
fix(sdk): stop chat.createSession wedging on stop and erroring on continuation boots (#3920)
## Summary
Two `chat.createSession()` bugs that break chats at its abstraction
level:
1. **Stopping a generation wedged the run forever.** `turn.complete()`
bare-awaited the AI SDK's `totalUsage` promise, which never settles
after a stop-abort. The run stayed stuck inside the stopped turn (trace
shows a permanently partial `ai.streamText` span and no further `waiting
for next message`), so the chat could never take another message. Fixed
with the same 2s `Promise.race` guard `chat.agent`'s turn loop already
uses.
2. **Continuation runs invoked the model with an empty prompt.** The
first turn only waited for a message on `preload` boots. A continuation
run (spawned after a cancel, crash, or version upgrade) arrives with the
boot payload stripped, so the loop ran a turn with zero messages and
errored with `AI_InvalidPromptError: messages must not be empty`.
Message-less continuation boots now wait for the next session input
("waiting for first message (continuation)"), and `turn.continuation` is
preserved across the wait so user code can seed stored history off it.
Both reproduced and verified end-to-end against a live environment (stop
followed by a next turn; cancel followed by a continuation turn with
seeded history), plus the existing unit suite.1 parent a04cdff commit 4783419
2 files changed
Lines changed: 37 additions & 8 deletions
| 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 | |
|---|---|---|---|
| |||
8988 | 8988 | | |
8989 | 8989 | | |
8990 | 8990 | | |
8991 | | - | |
8992 | | - | |
| 8991 | + | |
| 8992 | + | |
| 8993 | + | |
| 8994 | + | |
| 8995 | + | |
| 8996 | + | |
| 8997 | + | |
| 8998 | + | |
8993 | 8999 | | |
8994 | 9000 | | |
8995 | 9001 | | |
8996 | 9002 | | |
8997 | | - | |
| 9003 | + | |
| 9004 | + | |
| 9005 | + | |
| 9006 | + | |
8998 | 9007 | | |
8999 | 9008 | | |
9000 | 9009 | | |
9001 | 9010 | | |
9002 | 9011 | | |
| 9012 | + | |
9003 | 9013 | | |
| 9014 | + | |
| 9015 | + | |
| 9016 | + | |
| 9017 | + | |
| 9018 | + | |
| 9019 | + | |
9004 | 9020 | | |
9005 | 9021 | | |
9006 | 9022 | | |
| |||
9170 | 9186 | | |
9171 | 9187 | | |
9172 | 9188 | | |
9173 | | - | |
| 9189 | + | |
| 9190 | + | |
| 9191 | + | |
| 9192 | + | |
9174 | 9193 | | |
9175 | 9194 | | |
9176 | 9195 | | |
9177 | | - | |
9178 | | - | |
9179 | | - | |
9180 | | - | |
| 9196 | + | |
| 9197 | + | |
| 9198 | + | |
| 9199 | + | |
| 9200 | + | |
| 9201 | + | |
| 9202 | + | |
| 9203 | + | |
| 9204 | + | |
9181 | 9205 | | |
9182 | 9206 | | |
9183 | 9207 | | |
| |||
0 commit comments