Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/trigger-sdk/src/v3/managedChatResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,56 @@ describe("steering model context", () => {
}
});

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.

const first = modelUser("go");
const step1: ModelMessage[] = [
{ role: "assistant", content: "call-1" },
{ role: "tool", content: [] },
];
const step2: ModelMessage[] = [
{ role: "assistant", content: "call-2" },
{ role: "tool", content: [] },
];
const step3: ModelMessage[] = [
{ role: "assistant", content: "call-3" },
{ role: "tool", content: [] },
];

const prepare = retainStepMessages(async ({ messages }) => ({ messages }));

const s1 = await prepare({
messages: [first],
steps: [],
responseMessages: [],
});
expect(s1?.messages).toEqual([first]);

const s2 = await prepare({
messages: [...s1!.messages!, ...step1],
steps: [{ response: { messages: step1 } }],
responseMessages: [...step1],
});
expect(s2?.messages).toEqual([first, ...step1]);

const s3 = await prepare({
messages: [...s2!.messages!, ...step2],
steps: [{ response: { messages: step1 } }, { response: { messages: step2 } }],
responseMessages: [...step1, ...step2],
});
expect(s3?.messages).toEqual([first, ...step1, ...step2]);

const s4 = await prepare({
messages: [...s3!.messages!, ...step3],
steps: [
{ response: { messages: step1 } },
{ response: { messages: step2 } },
{ response: { messages: step3 } },
],
responseMessages: [...step1, ...step2, ...step3],
});
expect(s4?.messages).toEqual([first, ...step1, ...step2, ...step3]);
});

it("retains compaction instead of reintroducing old response segments", async () => {
const summary = modelUser("summary");
const old = modelUser("old");
Expand Down
4 changes: 3 additions & 1 deletion packages/trigger-sdk/src/v3/steeringContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type SteeringInjection = {
type StepInput = {
messages: ModelMessage[];
steps: Array<{ response: { messages: ModelMessage[] } }>;
/** AI SDK 7+: response messages accumulated across all steps so far. */
responseMessages?: ModelMessage[];
};

/**
Expand All @@ -41,7 +43,7 @@ export function retainStepMessages<T extends StepInput, R extends { messages?: M
retainedFrom = undefined;
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.

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.

if (retainedFrom) {
responseCount += alreadyIncluded(retainedFrom, responses.slice(responseCount));
retainedFrom = undefined;
Expand Down