Skip to content

fix: Chat requests resolve when onFinish throws - #18755

Merged
gr2m merged 3 commits into
mainfrom
bugfix-12175-20260812014858755157
Aug 12, 2026
Merged

fix: Chat requests resolve when onFinish throws#18755
gr2m merged 3 commits into
mainfrom
bugfix-12175-20260812014858755157

Conversation

@ai-sdk-factory

Copy link
Copy Markdown
Contributor

Background

Public AbstractChat requests resolved successfully when onFinish threw, preventing callers from detecting callback failures.

Root Cause

AbstractChat wrapped onFinish in a try/catch that logged callback exceptions instead of propagating them; the reproduction confirmed sendMessage resolved after the exact callback error was thrown.

Summary

Allowed onFinish errors to propagate while preserving active-response and resume-request cleanup, added a patch changeset, and removed reproduction-only artifacts.

Testing

Added a regression test verifying sendMessage rejects with the exact onFinish error and still clears the active response.

End-to-end Validation

  • pnpm -C examples/ai-functions exec tsx src/reproduction/issue-12175-on-finish-error-swallowed.ts exited successfully and confirmed sendMessage rejected with the exact callback error without logging it.

Related Issues

Fixes #12175

Closes #18750

ai-sdk-factory and others added 3 commits August 12, 2026 01:49
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Co-authored-by: anubra266 <30869823+anubra266@users.noreply.github.com>
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Co-authored-by: anubra266 <30869823+anubra266@users.noreply.github.com>
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
@ai-sdk-factory

Copy link
Copy Markdown
Contributor Author

Bugfix review

Outcome: approved

Reproduction replay

Status: no-longer-reproduces

The exact original reproduction completed successfully and the original bug signal did not appear.

Fixes issue

Status: fully-addresses

The callback exception now escapes the request promise, while nested finally cleanup still clears the active response and resume-request state.

Side effects

Risk: low

Requests now reject and automatic follow-up sending is skipped when a user-provided onFinish callback throws; this is the intended correction and only affects that exceptional path.

Performance

Risk: none

The change only restructures exception handling and introduces no additional allocation, iteration, retained state, or asynchronous work.

Backwards compatibility

Risk: none

The changed path does not read, write, migrate, or alter any stored messages, configuration, or persisted data format.

Breaking changes

Risk: none

Public APIs, types, exports, accepted inputs, output shapes, defaults, and configuration remain unchanged; the Promise request methods now correctly expose an exception originating from the caller's own callback.

Architecture

Risk: none

The fix remains localized within AbstractChat's existing request lifecycle and introduces no dependencies, cross-package source imports, shared abstractions, or package-boundary violations.

Change scope

Status: minimal

The production exception-handling change, focused regression test, and required patch changeset are all directly necessary to fix and release the reported behavior.

Security

Risk: none

The change adds no input processing, network access, credential handling, URL handling, serialization, or privilege boundary.

Testing

Status: appropriate

The regression test verifies rejection with the exact callback error and active-response cleanup; the shared request implementation covers send, regenerate, and resume paths, and the original public-API reproduction also passes.

Verification

Inspected the complete three-file merge-base diff and surrounding request, cleanup, public type, framework-wrapper, and concurrency code. The focused Chat test suite passed in both Node and Edge configurations with 35 tests each, package type checking passed, formatting and lint checks passed, and the diff passed whitespace validation.

@gr2m
gr2m merged commit c5b0515 into main Aug 12, 2026
64 checks passed
@gr2m
gr2m deleted the bugfix-12175-20260812014858755157 branch August 12, 2026 22:24
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.65 github npm
@ai-sdk/angular 3.0.65 github npm
@ai-sdk/code-mode 1.0.22 github npm
@ai-sdk/gateway 4.0.52 github npm
@ai-sdk/google 4.0.44 github npm
@ai-sdk/google-vertex 5.0.53 github npm
@ai-sdk/harness 1.0.71 github npm
@ai-sdk/harness-acp 1.0.8 github npm
@ai-sdk/harness-claude-code 1.0.74 github npm
@ai-sdk/harness-codex 1.0.73 github npm
@ai-sdk/harness-deepagents 1.0.71 github npm
@ai-sdk/harness-grok-build 1.0.7 github npm
@ai-sdk/harness-opencode 1.0.72 github npm
@ai-sdk/harness-pi 1.0.72 github npm
@ai-sdk/langchain 3.0.65 github npm
@ai-sdk/llamaindex 3.0.65 github npm
@ai-sdk/otel 1.0.65 github npm
@ai-sdk/policy-opa 1.0.65 github npm
@ai-sdk/react 4.0.68 github npm
@ai-sdk/rsc 3.0.65 github npm
@ai-sdk/sandbox-just-bash 1.0.71 github npm
@ai-sdk/sandbox-vercel 1.0.71 github npm
@ai-sdk/svelte 5.0.65 github npm
@ai-sdk/tui 1.0.66 github npm
@ai-sdk/vue 4.0.65 github npm
@ai-sdk/workflow 1.0.65 github npm
@ai-sdk/workflow-harness 1.0.71 github npm

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chat.ts swallows errors thrown in onFinish

2 participants