Skip to content

fix(sdk): use accumulated responseMessages in retainStepMessages for AI SDK 7 - #5101

Closed
cocvn157 wants to merge 1 commit into
triggerdotdev:mainfrom
cocvn157:fix/steering-context-ai-sdk-7-response-messages-5077
Closed

cocvn157 wants to merge 1 commit into
triggerdotdev:mainfrom
cocvn157:fix/steering-context-ai-sdk-7-response-messages-5077

Conversation

@cocvn157

@cocvn157 cocvn157 commented Nov 6, 2026

Copy link
Copy Markdown

Fixes #5077

In AI SDK 7, step.response.messages contains only the messages produced in that single step rather than accumulating across all steps in the turn. Because retainStepMessages read input.steps.at(-1)?.response.messages and sliced from responseCount, steps 3 and later sliced past the 2 per-step messages and dropped all subsequent tool results whenever prepareStep returned messages.

This prefers input.responseMessages (which AI SDK 7 populates with the accumulated response messages across all steps so far) before falling back to input.steps.at(-1)?.response.messages for AI SDK 5 and 6.

@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 92d391c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Hi @cocvn157, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Nov 6, 2026
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

Devin Review

responseCount = 0;
}
const responses = input.steps.at(-1)?.response.messages ?? [];
const responses = input.responseMessages ?? input.steps.at(-1)?.response.messages ?? [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Missing release note for SDK fix

This customer-facing retainStepMessages fix has no changeset. The package changelog will omit the repaired multi-step tool behavior.

Learn more

The SDK is a published package, and this change fixes a failure customers can encounter when a conversation uses multiple tool steps. The repository requires a changeset for user-facing package bug fixes. None is included in this PR.

Example: A customer upgrades to the release containing this change to fix missing tool results. The package changelog gives them no notice that the fix is available.

Recommended fix: Add a patch changeset for @trigger.dev/sdk with a one-sentence, user-facing description of the restored tool context.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

}
});

it("accumulates tool results across 3+ steps on AI SDK 7 where step.response.messages is per-step", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Missing regression comment on new test

The new retainStepMessages test lacks the required // Catches: <bug> comment identifying the regression it protects.

Learn more

Repository testing guidance requires every new unit test to identify its distinct regression in a one-line // Catches: <bug> comment. This test exercises loss of later tool results after a prepare-step message override, but it does not include that comment.

Example: A future maintainer reading this test sees a three-step scenario without the mandatory comment explaining that the regression is dropped tool results after step two.

Recommended fix: Place a // Catches: AI SDK 7 dropping tool results after the second step when prepareStep returns messages. comment directly above this test.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

responseCount = 0;
}
const responses = input.steps.at(-1)?.response.messages ?? [];
const responses = input.responseMessages ?? input.steps.at(-1)?.response.messages ?? [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Compaction rebuild retains the old response source

The separate chatCompact rebuild still slices per-step responses by a cumulative count. Compaction-enabled AI SDK 7 agents can therefore lose later tool results despite this retention fix.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: chat.agent drops tool results from step 3 on when prepareStep returns messages (AI SDK 7)

1 participant