Skip to content

[Chat][Platform] Notify stream listeners about deltas yielded from an injected generator - #2389

Open
lazerg wants to merge 1 commit into
symfony:mainfrom
lazerg:fix-stream-result-nested-delta-dispatch
Open

lazerg wants to merge 1 commit into
symfony:mainfrom
lazerg:fix-stream-result-nested-delta-dispatch

Conversation

@lazerg

@lazerg lazerg commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #2330
License MIT

When a stream listener replaces a delta with a generator, StreamResult::getContent() forwarded it with yield from. PHP does not re-enter the outer generator for the values of a delegated one, so the deltas coming out of that generator were never sent to onDelta(). The toolbox StreamListener injects the tool-call follow-up exactly that way, which is why ChatStreamListener saw nothing after a tool call and stored an empty assistant message, while the frontend received the text.

The delta dispatch now recurses into an injected generator and notifies the listeners about each delta it yields. The listener that injected the generator is left out of that nested round, so it does not reprocess its own output: PartialObjectStreamListener would otherwise buffer the same text twice and re-inject forever, and the toolbox StreamListener would drop the follow-up it just produced. The order and the number of yielded deltas stay the same.

The forwarding also went through yield from, which keeps the inner generator's keys, so the outer stream repeated key 0 and iterator_to_array() on it silently lost deltas. Yielding one by one gives the whole stream sequential keys again.

@carsonbot carsonbot added Status: Needs Review Bug Something isn't working Chat Issues & PRs about the AI Chat component Platform Issues & PRs about the AI Platform component labels Aug 7, 2026
@carsonbot carsonbot changed the title [Platform][Chat] Notify stream listeners about deltas yielded from an injected generator [Chat][Platform] Notify stream listeners about deltas yielded from an injected generator Aug 7, 2026
@lazerg
lazerg force-pushed the fix-stream-result-nested-delta-dispatch branch from 1cfb87f to e2f8d10 Compare August 7, 2026 14:32
@lazerg

lazerg commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor Author

The Examples / PHP 8.5 job failed while pulling the service images, with a 502 from the registry

@lazerg

lazerg commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Hey @chr-hertel, could you take a look at this fix for notifying stream listeners about deltas yielded from an injected generator? The earlier CI failure was a registry 502, unrelated to the change.

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

Labels

Bug Something isn't working Chat Issues & PRs about the AI Chat component Platform Issues & PRs about the AI Platform component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chat][Agent][Platform] Streamed tool-call answers are not persisted by ChatStreamListener

2 participants