Skip to content

fix: save steps from the AI SDK's hooks instead of predicting them - #449

Open
robelest wants to merge 2 commits into
mainfrom
fix/388-step-saves-v3
Open

robelest wants to merge 2 commits into
mainfrom
fix/388-step-saves-v3

Conversation

@robelest

@robelest robelest commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Steps are now saved from the AI SDK's hooks instead of being predicted. onStepEnd holds the step. prepareStep saves it in one mutation with the next pending message. A transform saves the last step before finish reaches the caller, and finishes the stream in that same mutation (#181). willContinue is gone.

The transform uses experimental_transform because the AI SDK has no stable hook that runs after the last step and before finish.

Failures:

  • A failed step save stops the generation and fails it.
  • Provider errors stay in onError and fullStream, and the stream ends aborted.
  • A step cut off by stopStream fails instead of staying pending.

Observable changes:

This answers the review on #397: no state machine copying the SDK's behaviour, each save runs in the hook where the SDK has already decided what comes next.

Closes #388, closes #419, closes #428.

Supersedes #397.

@pkg-pr-new

pkg-pr-new Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/agent@449

commit: 9f96b67

@robelest
robelest force-pushed the fix/388-step-saves-v3 branch from 3f4046f to cd15193 Compare November 9, 2026 15:52
, #419, #428)

onStepEnd holds the step, prepareStep saves it with the next pending
message in one mutation, and a transform saves the last one before
`finish` reaches the caller, finishing its stream in the same mutation.
A stream that ends without `finish`, on an error or a stopStream, fails
the step it cut off there, before the result resolves. A failure, or a
failed step, ends the SDK's loop through stopWhen, and keeps the steps
that ended: an abort stops what hasn't finished. A failed message's
stream ends aborted. The generation runs to its end whoever reads the
stream. willContinue is gone, and a caller's onStepEnd now runs before
its step is saved, after its usage is reported.
@robelest
robelest force-pushed the fix/388-step-saves-v3 branch from cd15193 to 9f96b67 Compare November 9, 2026 16:05
@robelest
robelest marked this pull request as ready for review November 9, 2026 23:10
@robelest
robelest requested a review from ianmacartney November 9, 2026 23:10

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 12 files

Re-trigger cubic

@ianmacartney
ianmacartney requested review from sethconvex and removed request for ianmacartney November 10, 2026 00:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant