René's URL Explorer Experiment


Title: fix(sdk): preserve partial assistant message on chat stream failure by matt-aitken · Pull Request #4348 · triggerdotdev/trigger.dev · GitHub

Open Graph Title: fix(sdk): preserve partial assistant message on chat stream failure by matt-aitken · Pull Request #4348 · triggerdotdev/trigger.dev

X Title: fix(sdk): preserve partial assistant message on chat stream failure by matt-aitken · Pull Request #4348 · triggerdotdev/trigger.dev

Description: Summary When a chat.agent (or chat.createSession) turn's model stream fails mid-response (e.g. a transport timeout like UND_ERR_BODY_TIMEOUT), the assistant output that already streamed was dropped: onTurnComplete fired with responseMessage: undefined, and the manual loop's turn.complete() rethrew without keeping the partial. Apps that register hydrateMessages are hit hardest, since boot-time tail-replay recovery is off by design. This preserves the streamed-so-far assistant output while still reporting the turn as errored, so persistence and recovery keep it. Scope of behavior change Only the error path changes. Successful turns are unaffected: the same chunks stream to the client in the same order, and backpressure/cancel behave as before. Everything here is a correctness improvement on a turn that hit a source-stream failure. What it does Follow-up to #4304 (chat.pipeAndCapture), extending the same partial-recovery to the two loops that lacked it: chat.agent: taps the response stream (via a TransformStream, so pass-through backpressure and cancel are preserved) to buffer chunks, and on a source-stream failure reconstructs the partial (preferring the onFinish message). It's surfaced on the error-path onTurnComplete (responseMessage, rawResponseMessage, uiMessages, newUIMessages, newMessages) and committed to the accumulator so the next turn and the reboot snapshot keep it. chat.createSession / turn.complete(): the reconstructed partial is accumulated (so turn.uiMessages reflects it and the caller can persist after catching) before turn.complete() rethrows. onBeforeTurnComplete stays skipped on the error path (it hands out a writer for a stream that has already broken). Correctness properties (each covered by a regression test) Each test below was confirmed to fail without its fix: The recovered partial reaches onTurnComplete and the next turn's accumulated messages. An already-committed (possibly enriched) response is not overwritten if a post-response hook then throws. Incomplete tool parts are cleaned from the recovered partial (text kept), so the UI and model views agree and the next turn isn't poisoned. A prior turn's model-only compaction survives an errored turn (append only the new tail, don't reconvert the full history). A reconstructed fragment that reuses an existing message id does not clobber the complete message. Queued chat.response data parts are folded into the recovered partial, matching the success path. newMessages (model delta) stays symmetric with newUIMessages. Tests New chat-agent-source-stream-error.test.ts covers the cases above. The full @trigger.dev/sdk unit suite passes and the package build is green across all supported runtimes (Node 20 to 26, Bun, Deno, Cloudflare Workers).

Open Graph Description: Summary When a chat.agent (or chat.createSession) turn's model stream fails mid-response (e.g. a transport timeout like UND_ERR_BODY_TIMEOUT), the assistant output that already streamed was dro...

X Description: Summary When a chat.agent (or chat.createSession) turn's model stream fails mid-response (e.g. a transport timeout like UND_ERR_BODY_TIMEOUT), the assistant output that already streamed was...

Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/4348

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a2703fa3-7f74-2cf8-29db-3e235d13cc5a
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA0A8:305F92:8C787:C7BF3:6AFAF402
html-safe-noncef3b6481a287c2f1b25a3d825198f39e4ab411af3a560c3c04da58982b0c1e957
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEE4OjMwNUY5Mjo4Qzc4NzpDN0JGMzo2QUZBRjQwMiIsInZpc2l0b3JfaWQiOiI0MzYzNDU4MDA3MzkyNzc3MjE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd550ee5c8dca081e213ab3b1835c701299b9c46ff01001c8f192a34e6e380d0b
hovercard-subject-tagpull_request:4117162773
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/4348/files
twitter:imagehttps://avatars.githubusercontent.com/u/10635986?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/10635986?s=400&v=4
og:image:altSummary When a chat.agent (or chat.createSession) turn's model stream fails mid-response (e.g. a transport timeout like UND_ERR_BODY_TIMEOUT), the assistant output that already streamed was dro...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None0178036d8230524a18422872393ab7e708443ae4c2047f758560a2db870c1913
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea85e96a83bed7871993e6b1ffda24105928eee17
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/triggerdotdev/trigger.dev/pull/4348/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fpull%2F4348%2Ffiles
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%2Fpull%2F4348%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=triggerdotdev%2Ftrigger.dev
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
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
Sign up for GitHub https://github.com/signup?return_to=%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2Fnew%2Fchoose
matt-aitkenhttps://github.com/matt-aitken
mainhttps://github.com/triggerdotdev/trigger.dev/tree/main
fix/chat-preserve-partial-on-stream-failurehttps://github.com/triggerdotdev/trigger.dev/tree/fix/chat-preserve-partial-on-stream-failure
Conversation 26 https://github.com/triggerdotdev/trigger.dev/pull/4348
Commits 14 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits
Checks 50 https://github.com/triggerdotdev/trigger.dev/pull/4348/checks
Files changed https://github.com/triggerdotdev/trigger.dev/pull/4348/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
fix(sdk): preserve partial assistant message on chat stream failure https://github.com/triggerdotdev/trigger.dev/pull/4348/files#top
Show all changes 14 commits https://github.com/triggerdotdev/trigger.dev/pull/4348/files
8152444 fix(sdk): preserve partial assistant message on chat stream failure matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/8152444cfd4264c0bf1259485d4f88f404b58ae0
dc63a6e fix(sdk): persist recovered partial to accumulator and snapshot on error matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/dc63a6e6266e5e0bd1542d0b1e58de9199a3ef4c
1fe685c fix(sdk): mirror success-path accumulation on chat.agent error path matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/1fe685cf3145677ff2d7ea47761e84962dd1c177
b6ea02f fix(sdk): don't overwrite a committed response when a post-response s… matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/b6ea02fd6c69095af84882ce2d482d9035e28b40
a225c36 fix(sdk): include the recovered partial in the error event's newMessages matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/a225c369ea8ed3ca67249dd8c4b25238c9eadd73
882364a fix(sdk): harden error-path partial recovery against fragment clobber… matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/882364a4d8ab1a5b1063278b884a5facb2d9d0e1
ec33b97 fix(sdk): preserve stream backpressure when tapping chat chunks matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/ec33b975d77c6b3231d5addbb786f77ee9a0c329
6aeb2b9 fix(sdk): clean incomplete parts from the recovered error partial matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/6aeb2b95a656b25e577ce3c9c28a5ef9e1c2b933
ecfede6 perf(sdk): release the chat chunk buffer once the response is committed matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/ecfede634a535d9513ac637254e427ddf980f564
1916507 fix(sdk): preserve compaction and avoid double-persist on the error path matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/19165076b01a46baaeff377c50d642cc1f897571
b5c37ee fix(sdk): include the errored user message in the error event's newMe… matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/b5c37ee72749b9b66ba2b3cea4733dc96a05e45b
aaa51a3 fix(sdk): fold queued response data parts into the managed error partial matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/aaa51a37e9a011c8b1909a1ddcee82cfd5bb084d
0316b05 fix(sdk): satisfy the package build's stricter null-narrowing on the … matt-aitken Jul 23, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/0316b05fe3c5aa57e7edeaf8e0215b103c09145b
65fc6d2 chore(sdk): strip explanatory comments and trim the changeset matt-aitken Jul 24, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4348/commits/65fc6d2e361f5b452430e61830a1da514265c35c
Clear filters https://github.com/triggerdotdev/trigger.dev/pull/4348/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
chat-agent-preserve-partial-on-stream-failure.md https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-2a4893945e9bc1388c547b6ac773b2aec53709426393b6ec3313bdefdd979586
ai.ts https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
chat-agent-source-stream-error.test.ts https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-676ba4f8cce50a3d8f1f8940b5e4a8a2aa11e18b11294bef750eaee99264874a
.changeset/chat-agent-preserve-partial-on-stream-failure.mdhttps://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-2a4893945e9bc1388c547b6ac773b2aec53709426393b6ec3313bdefdd979586
View file https://github.com/triggerdotdev/trigger.dev/blob/65fc6d2e361f5b452430e61830a1da514265c35c/.changeset/chat-agent-preserve-partial-on-stream-failure.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4348/{{ revealButtonHref }}
packages/trigger-sdk/src/v3/ai.tshttps://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
View file https://github.com/triggerdotdev/trigger.dev/blob/65fc6d2e361f5b452430e61830a1da514265c35c/packages/trigger-sdk/src/v3/ai.ts
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4348/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
https://github.com/triggerdotdev/trigger.dev/pull/4348/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4348/files
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.