Skip to content

Conversation

@valtzu
Copy link
Contributor

@valtzu valtzu commented Jul 20, 2025

Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #161
License MIT

Address 2 streaming-related issues:

  1. When using symfony/ai from within StreamedResponse callback (in http controller), no data was collected due to not implementing LateDataCollectorInterface
  2. An attempt to save StreamResult to the profiler storage always failed, because \Generators are not serializable

Both are used in the Turbo Stream Bot demo, and now the profiler works. Though the toolbar still does not auto-update, but that is currently expected behavior.

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AssertSame where possible please

@valtzu valtzu force-pushed the fix-stream-profiler branch from fb0cf29 to 53a05cb Compare July 20, 2025 18:19
Comment on lines +71 to +81
private function createTraceableStreamResult(\Generator $originalStream): StreamResult
{
return $result = new StreamResult((function () use (&$result, $originalStream) {
$this->resultCache[$result] = '';
foreach ($originalStream as $chunk) {
yield $chunk;
if (\is_string($chunk)) {
$this->resultCache[$result] .= $chunk;
}
}
})());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one 👏

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works 👍

image

@chr-hertel
Copy link
Member

Thank you @valtzu.

@chr-hertel chr-hertel merged commit 45ea78c into symfony:main Jul 20, 2025
12 checks passed
@chr-hertel chr-hertel added the AI Bundle Issues & PRs about the AI integration bundle label Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Bundle Issues & PRs about the AI integration bundle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AIBundle] Streaming responses missing from the profiler

3 participants