Repository navigation
Handle terminal error frames in useAgentChat observers #2023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "agents": patch | ||
| "@cloudflare/ai-chat": patch | ||
| "@cloudflare/think": patch | ||
| --- | ||
|
|
||
| Treat `useAgentChat` observer error frames as terminal responses. | ||
|
|
||
| Plain-text error bodies are no longer parsed as stream chunks or merged into an empty assistant message. Error frames now clear observer streaming, replay, recovery, and tool-continuation state even when they omit `done`, matching the transport-owned stream behavior. |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Partial assistant answer disappears when a reconnecting tab replays a turn that ended in an error
The partially generated answer that was replayed to a reconnecting tab is thrown away (
breakin the new error branch atpackages/agents/src/chat/react.tsx:2173-2193) before it is written into the chat list, so the user sees an empty turn instead of the text the assistant had produced before failing.Impact: After reconnecting to a turn that errored mid-generation, the text already produced is silently lost from the conversation instead of being shown alongside the error.
How the replay-then-terminal-error sequence loses the accumulated content
When a client resumes a turn that ended in an error,
ResumeHandshake._replayTerminalOnAck(packages/agents/src/chat/resume-handshake.ts:293-322) first replays the stored chunks asreplay: true, done: falseframes and then sends a terminal{ done: true, error: true, body: <diagnostic text> }frame.In the observer (non transport-owned) path, replayed chunks are accumulated but NOT merged into
messages:transitiononly produces amessagesUpdatefor non-replay chunks,replayComplete, ordone(packages/agents/src/chat/broadcast-state.ts:130-146). Before this PR, the terminal frame fell through to theresponsetransition withdone: true, which ranaccumulator.mergeInto(prev)and surfaced the partial text.With the new short-circuit at
packages/agents/src/chat/react.tsx:2173, the terminal error frame instead issues acleartransition (which returns{ status: "idle" }with nomessagesUpdate) andbreaks, so the accumulated replay content is discarded. Consider merging the accumulator (e.g. dispatching aresponseevent withdone: trueand nochunkData, or explicitly applyingaccumulator.mergeInto) before clearing observer state.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.