René's URL Explorer Experiment


Title: bug: chat.agent drops tool results from step 3 on when prepareStep returns messages (AI SDK 7) · Issue #5077 · triggerdotdev/trigger.dev · GitHub

Open Graph Title: bug: chat.agent drops tool results from step 3 on when prepareStep returns messages (AI SDK 7) · Issue #5077 · triggerdotdev/trigger.dev

X Title: bug: chat.agent drops tool results from step 3 on when prepareStep returns messages (AI SDK 7) · Issue #5077 · triggerdotdev/trigger.dev

Description: Provide environment information System: OS: Linux 7.2 CachyOS Linux CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics Memory: 2.75 GB / 15.04 GB Container: Yes Shell: 5.9.2 - /usr/bin/zsh Binaries: Node: 24.18.0 - /home/senpai/.local/...

Open Graph Description: Provide environment information System: OS: Linux 7.2 CachyOS Linux CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics Memory: 2.75 GB / 15.04 GB Container: Yes Shell: 5.9.2 - /usr/bin/zsh Binari...

X Description: Provide environment information System: OS: Linux 7.2 CachyOS Linux CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics Memory: 2.75 GB / 15.04 GB Container: Yes Shell: 5.9.2 - /usr/bin/zsh Binari...

Opengraph URL: https://github.com/triggerdotdev/trigger.dev/issues/5077

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: chat.agent drops tool results from step 3 on when prepareStep returns messages (AI SDK 7)","articleBody":"### Provide environment information\n\n```\n  System:\n    OS: Linux 7.2 CachyOS Linux\n    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics\n    Memory: 2.75 GB / 15.04 GB\n    Container: Yes\n    Shell: 5.9.2 - /usr/bin/zsh\n  Binaries:\n    Node: 24.18.0 - /home/senpai/.local/share/nvm/v24.18.0/bin/node\n    npm: 12.0.1 - /home/senpai/.local/share/nvm/v24.18.0/bin/npm\n    pnpm: 11.13.1 - /home/senpai/.local/share/nvm/v24.18.0/bin/pnpm\n    bun: 1.3.14 - /home/senpai/.bun/bin/bun\n```\n\nPackages: `@trigger.dev/sdk@4.8.1`, `ai@7.0.153`, `zod@4.6.7`.\n\n\n### Describe the bug\n\nWith AI SDK 7, if a `chat.agent`'s `streamText` has a `prepareStep` that returns `messages`, the model stops receiving new tool results after the first one. From step 3 on, every prompt contains only the first tool call and its result. The model never sees its later results, so it repeats the same tool call until `stopWhen` ends the turn.\n\nEven a no-op `prepareStep: ({ messages }) => ({ messages })` triggers it. In our production agent this showed up as the model running the same shell command dozens of times in one turn.\n\n**Expected:** each step's prompt includes every earlier tool call and result, the same as without `prepareStep`.\n\n**Cause:** `chat.agent` wraps `prepareStep` in `retainStepMessages` ([`packages/trigger-sdk/src/v3/steeringContext.ts`](https://github.com/triggerdotdev/trigger.dev/blob/fc33769a/packages/trigger-sdk/src/v3/steeringContext.ts#L37-L41)):\n\n```ts\nconst responses = input.steps.at(-1)?.response.messages ?? [];\nconst messages = retained ? [...retained, ...responses.slice(responseCount)] : input.messages;\n// ...\nresponseCount = responses.length;\n```\n\nThe doc comment above it states the assumption that no longer holds:\n\n> The same logic works when the installed AI SDK already retains overrides: its input is not concatenated again.\n\nThat code was written for AI SDK 5/6, where `step.response.messages` holds every message so far, so slicing off the first `responseCount` leaves only the new ones. AI SDK 7 changed this (migration guide, \"Step Response Messages Are No Longer Accumulated\"): each step's `response.messages` holds only that step's messages. A tool step always yields 2 messages (tool call + tool result), so `responseCount` stays at 2, and from step 3 on `responses.slice(2)` is empty. Nothing new is added to `retained`, and the stale copy replaces the correct `input.messages`.\n\n| Step | `responses` (AI SDK 7) | `responseCount` | Added to history |\n|---|---|---|---|\n| 2 | step 1's 2 messages | 0 | both ✓ |\n| 3 | step 2's 2 messages | 2 | nothing ✗ |\n| 4 | step 3's 2 messages | 2 | nothing ✗ |\n\nAll of these are needed to hit it:\n\n1. `ai` 7.x. With `ai@6.0.315`, the same code works.\n2. Something returns `messages` from `prepareStep`: either the user's `prepareStep`, or the SDK's own built-in one (steering via pending messages, compaction, `chat.inject`). Until the first override, the wrapper passes `input.messages` through.\n3. At least 3 tool steps in one turn. Step 2 is always correct.\n\nBecause of (2), this also affects agents **without** a user `prepareStep`: a single steering message injected mid-turn is enough. With no user `prepareStep` and one steering message on `ai@7`, steps 3 and 4 both see `[\"user:go\", \"result-1\", \"user:steer\"]` (result-2 and result-3 missing); on `ai@6` the same run is correct.\n\n\n### Reproduction repo\n\nhttps://github.com/iharsh02/BugsBunny/tree/02550d8/trigger-repro\n\n### To reproduce\n\n```bash\ngit clone https://github.com/iharsh02/BugsBunny && cd BugsBunny/trigger-repro\nnpm ci\nnode repro.mjs control   # no prepareStep\nnode repro.mjs           # no-op prepareStep\n```\n\n`repro.mjs` uses only public API and needs no network or API keys. It runs a `chat.agent` through `mockChatAgent` from `@trigger.dev/sdk/ai/test`, with a scripted `MockLanguageModelV3` that calls a `lookup` tool 3 times (its `execute` returns `result-N`) and then answers. Each model call logs the tool results in the `prompt` it actually received.\n\nThe core of it:\n\n```js\nconst agent = chat.agent({\n  id: \"repro\",\n  run: async ({ messages, signal, streamText }) =>\n    streamText({\n      model,\n      messages,\n      tools: { lookup },\n      stopWhen: isStepCount(8),\n      abortSignal: signal,\n      ...(usePrepareStep && { prepareStep: ({ messages }) => ({ messages }) }),\n    }),\n});\n```\n\nOutput:\n\n```\n$ node repro.mjs control\nmodel call 1 sees: []\nmodel call 2 sees: [ 'result-1' ]\nmodel call 3 sees: [ 'result-1', 'result-2' ]\nmodel call 4 sees: [ 'result-1', 'result-2', 'result-3' ]\n\n$ node repro.mjs\nmodel call 1 sees: []\nmodel call 2 sees: [ 'result-1' ]\nmodel call 3 sees: [ 'result-1' ]      \u003c- result-2 missing\nmodel call 4 sees: [ 'result-1' ]      \u003c- result-2 and result-3 missing\n```\n\nWith `npm i ai@6.0.315`, both runs match.\n\n\n### Suggested fix\n\nAI SDK 7 passes the accumulated history to `prepareStep` as `responseMessages`. AI SDK 5/6 don't have that field, so falling back keeps their behaviour unchanged:\n\n```diff\n type StepInput = {\n   messages: ModelMessage[];\n   steps: Array\u003c{ response: { messages: ModelMessage[] } }>;\n+  /** AI SDK 7+: response messages accumulated across all steps so far. */\n+  responseMessages?: ModelMessage[];\n };\n\n-    const responses = input.steps.at(-1)?.response.messages ?? [];\n+    const responses = input.responseMessages ?? input.steps.at(-1)?.response.messages ?? [];\n```\n\nI applied this change to the built `dist` of 4.8.1 and the repro passes on `ai@5.0.281`, `ai@6.0.315` and `ai@7.0.153`, including the steering case above.\n\nThe obvious alternative, dropping the slice (`[...retained, ...responses]`), fixes AI SDK 7 but duplicates tool results on AI SDK 5/6: step 3 sees `['result-1', 'result-1', 'result-2']`. The SDK's peer range still includes `ai` 5 and 6, so that version isn't safe.\n\n**Why CI didn't catch it:** the repo's dev dependency is `ai ^6`, so the suite runs on v6. The existing \"SDK retains overrides\" test feeds v6-style accumulated step responses together with v7's carry-forward of overrides, a combination no real AI SDK version produces. Happy to open a PR with the fix plus a v7-shaped regression test.\n\n\n### Additional information\n\n**With a real model.** `real-agent.mjs` in the repro repo runs the same `chat.agent` with a real model (`minimax/minimax-m3.1-flash` via the AI Gateway). Its `getCode` tool returns a random code and takes the previous code as input, so the call's argument shows what the model thinks the last code was. The prompt is \"Call getCode exactly 3 times, one call at a time. Then reply with only the 3 codes joined by dashes.\"\n\nWithout `prepareStep`:\n\n```\nmodel call 1 sees: []\n  getCode -> 5Y        (previous: \"\")\nmodel call 2 sees: [ '5Y' ]\n  getCode -> ZG        (previous: \"5Y\")\nmodel call 3 sees: [ '5Y', 'ZG' ]\n  getCode -> PE        (previous: \"ZG\")\nmodel call 4 sees: [ '5Y', 'ZG', 'PE' ]\n  answer: \"5Y-ZG-PE\"   ✓\n```\n\nWith `prepareStep: ({ messages }) => ({ messages })`:\n\n```\nmodel call 1 sees: []\n  getCode -> CP        (previous: \"\")\nmodel call 2 sees: [ 'CP' ]\n  getCode -> L2        (previous: \"CP\")\nmodel call 3 sees: [ 'CP' ]\n  getCode -> KP        (previous: \"CP\")\nmodel call 4 sees: [ 'CP' ]\n  getCode -> 0B        (previous: \"CP\")\n...\nmodel call 8 sees: [ 'CP' ]\n  getCode -> 8I        (previous: \"CP\")\ngetCode calls: 8 (asked for 3), no answer — stopped by isStepCount(8)\n```\n\nThe model keeps passing `previous: \"CP\"` because it never sees `L2`, `KP` and the later codes. That's the same loop we hit in production.\n\n**Affected versions.** I reproduced this on `@trigger.dev/sdk` 4.8.1 with `ai` 7.0.153. We first hit it on 4.7.5 and also saw it on 4.7.7 and with `ai` 7.0.146. The code is unchanged on `main` as of fc33769a (2026-10-26).\n\n**Workaround until a fix ships.** In `dist/esm/v3/steeringContext.js` and `dist/commonjs/v3/steeringContext.js`, change the `const responses = ...` line to `const responses = input.responseMessages ?? input.steps.at(-1)?.response.messages ?? [];` (the type addition only applies to the TS source). Or don't return `messages` from `prepareStep` (this doesn't help with SDK steering/compaction).\n","author":{"url":"https://github.com/iharsh02","@type":"Person","name":"iharsh02"},"datePublished":"2026-10-26T19:47:38Z","url":"https://github.com/triggerdotdev/trigger.dev/issues/5077"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:af1525da-85ca-07bb-5ccc-7e1df0751c57
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE6B0:38C411:5BCCB0:809DDF:6AFB6168
html-safe-nonce7b3e6bb455b16a2a9ed5718d83de071f33e0ef7e890a16d40ba522cf739d95be
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkIwOjM4QzQxMTo1QkNDQjA6ODA5RERGOjZBRkI2MTY4IiwidmlzaXRvcl9pZCI6IjY1MjQ1MTcxNjY1NDcxNjU1NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf556bc786b432d69993e9015c0ce646ddfff53903aa547642d5fcba62fea2ed9
hovercard-subject-tagissue:6046988784
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/triggerdotdev/trigger.dev/5077/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cb9c3af4fc710be9384d0a9d4f87c07ca506583cdf0454483a2fe22bc63e49a8/triggerdotdev/trigger.dev/issues/5077
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cb9c3af4fc710be9384d0a9d4f87c07ca506583cdf0454483a2fe22bc63e49a8/triggerdotdev/trigger.dev/issues/5077
og:image:altProvide environment information System: OS: Linux 7.2 CachyOS Linux CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics Memory: 2.75 GB / 15.04 GB Container: Yes Shell: 5.9.2 - /usr/bin/zsh Binari...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameiharsh02
hostnamegithub.com
expected-hostnamegithub.com
Noneea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94
turbo-cache-controlno-preview
go-importgithub.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git
octolytics-dimension-user_id95297378
octolytics-dimension-user_logintriggerdotdev
octolytics-dimension-repository_id572570113
octolytics-dimension-repository_nwotriggerdotdev/trigger.dev
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id572570113
octolytics-dimension-repository_network_root_nwotriggerdotdev/trigger.dev
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release59ef97164c52cf59bd10558ddec9c4f482763988
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/triggerdotdev/trigger.dev/issues/5077#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2F5077
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2F5077
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=triggerdotdev%2Ftrigger.dev
Reloadhttps://github.com/triggerdotdev/trigger.dev/issues/5077
Reloadhttps://github.com/triggerdotdev/trigger.dev/issues/5077
Reloadhttps://github.com/triggerdotdev/trigger.dev/issues/5077
triggerdotdevhttps://github.com/triggerdotdev
trigger.devhttps://github.com/triggerdotdev/trigger.dev
Codehttps://github.com/triggerdotdev/trigger.dev
Issues203 (203)https://github.com/triggerdotdev/trigger.dev/issues
Pull requests67 (67)https://github.com/triggerdotdev/trigger.dev/pulls
Discussionshttps://github.com/triggerdotdev/trigger.dev/discussions
Actionshttps://github.com/triggerdotdev/trigger.dev/actions
Projectshttps://github.com/triggerdotdev/trigger.dev/projects
Security and quality39 (39)https://github.com/triggerdotdev/trigger.dev/security
Insightshttps://github.com/triggerdotdev/trigger.dev/pulse
https://github.com/triggerdotdev/trigger.dev
New issuehttps://github.com/login?return_to=https://github.com/triggerdotdev/trigger.dev/issues/5077
New issuehttps://github.com/login?return_to=https://github.com/triggerdotdev/trigger.dev/issues/5077
bug: chat.agent drops tool results from step 3 on when prepareStep returns messages (AI SDK 7)https://github.com/triggerdotdev/trigger.dev/issues/5077#top
https://github.com/iharsh02
iharsh02https://github.com/iharsh02
on Oct 26, 2026https://github.com/triggerdotdev/trigger.dev/issues/5077#issue-6046988784
packages/trigger-sdk/src/v3/steeringContext.tshttps://github.com/triggerdotdev/trigger.dev/blob/fc33769a/packages/trigger-sdk/src/v3/steeringContext.ts#L37-L41
https://github.com/iharsh02/BugsBunny/tree/02550d8/trigger-reprohttps://github.com/iharsh02/BugsBunny/tree/02550d8/trigger-repro
fc33769https://github.com/triggerdotdev/trigger.dev/commit/fc33769a559a69cae687354413b2316bf9fd0bf3
https://github.com/SachinyadavAug20
SachinyadavAug20https://github.com/SachinyadavAug20
on Oct 27, 2026https://github.com/triggerdotdev/trigger.dev/issues/5077#issuecomment-6445281894
#5077https://github.com/triggerdotdev/trigger.dev/issues/5077
https://github.com/bestrada
bestradahttps://github.com/bestrada
on Nov 4, 2026https://github.com/triggerdotdev/trigger.dev/issues/5077#issuecomment-6645593793
Sign up for freehttps://github.com/signup?return_to=https://github.com/triggerdotdev/trigger.dev/issues/5077
Sign in to commenthttps://github.com/login?return_to=https://github.com/triggerdotdev/trigger.dev/issues/5077
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.