Conversation
… injected generator
lazerg
force-pushed
the
fix-stream-result-nested-delta-dispatch
branch
from
August 7, 2026 14:32
1cfb87f to
e2f8d10
Compare
Contributor
Author
|
The Examples / PHP 8.5 job failed while pulling the service images, with a 502 from the registry |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a stream listener replaces a delta with a generator,
StreamResult::getContent()forwarded it withyield 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 toonDelta(). The toolboxStreamListenerinjects the tool-call follow-up exactly that way, which is whyChatStreamListenersaw 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:
PartialObjectStreamListenerwould otherwise buffer the same text twice and re-inject forever, and the toolboxStreamListenerwould 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 key0anditerator_to_array()on it silently lost deltas. Yielding one by one gives the whole stream sequential keys again.