SIGN IN SIGN UP

fix: prevent smoothStream custom RegExp chunking from merging chunks or looping on empty matches (#19916)

## Background

Custom smoothStream regular expressions could merge chunk boundaries
when global or sticky, or repeatedly emit empty chunks without
terminating.

## Root Cause

The RegExp detector reused caller-owned state without resetting
lastIndex and accepted zero-length matches. The original replay
confirmed both incorrect boundaries and repeated empty emissions.

## Summary

Reset and restore RegExp lastIndex for each buffer, reject zero-length
matches, document the RegExp contract, and add a patch changeset.

## Testing

Added Node and Edge regression coverage for global and sticky chunk
boundaries, caller lastIndex preservation, and zero-length match
rejection.

## End-to-end Validation

- `pnpm -C examples/ai-functions exec tsx
src/reproduction/issue-19914-smooth-stream-regexp.ts` via immutable
replay exited successfully with correct global and sticky chunks and a
terminating empty-match error.

## Related Issues

Fixes #19914

Closes #19915

---------

Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com>
Co-authored-by: pacocartones <253313177+pacocartones@users.noreply.github.com>
A
ai-sdk-factory[bot] committed
e604532216be75cb29f642f2531b9c52575062cd
Parent: b1fd1bb
Committed by GitHub <noreply@github.com> on 8/28/2026, 4:39:57 PM