Repository navigation
Python: keep an in-progress continuation_token on the aggregated response - #8889
Closed
kuse (liwenjie200543) wants to merge 1 commit into
Closed
kuse (liwenjie200543) wants to merge 1 commit into
kuse (liwenjie200543) wants to merge 1 commit into
Conversation
kuse (liwenjie200543)
temporarily deployed
to
github-app-auth
September 30, 2026 08:18 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Some terminal OpenAI and A2A updates lack a finish reason, causing stale continuation tokens to survive completion.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Fixes streamed response aggregation so in-progress continuation tokens survive unrelated updates and clear on terminal updates.
Changes:
- Preserves the last non-
Nonecontinuation token. - Clears tokens when an update has a finish reason.
- Adds aggregation tests for both paths.
| File | Description |
|---|---|
python/packages/core/agent_framework/_types.py |
Updates continuation-token aggregation. |
python/packages/core/tests/core/test_types.py |
Tests token preservation and clearing. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+2241
to
+2244
| elif update.finish_reason is not None: | ||
| # A terminal update withdraws the token: its presence on the aggregate | ||
| # means the operation is still in progress. | ||
| response.continuation_token = None |
Member
|
As mentioned in the issue, the core team will fix this. |
This branch was previously deployed
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.

Motivation & Context
Fixes #8826. A streamed background response that is still in progress reports itself as complete: the aggregated response loses its
continuation_tokenon the next event that does not repeat it, and consumers that read the aggregate to decide whether to poll or re-POST act on the wrong reading.Description & Review Guide
_process_update— the single aggregation point behindChatResponse.from_updates/AgentResponse.from_updates— copiedupdate.continuation_tokenunconditionally, the only field among its siblings without anis not Noneguard. The copy is now guarded: the aggregate keeps the last token the provider actually sent, and an update that carriesfinish_reason(a terminal update) withdraws it._chat_client.py:964,:4420) no longer see "complete" while the background operation is running, and polling/function-loop continuation stops dropping the token early. A bare guard alone would have left the stale token on the aggregate afterresponse.completedand broken the documented "presence means in progress,Nonemeans complete" contract in the other direction — hence the paired withdrawal onfinish_reason.finish_reasonis the right terminal marker for all providers (the OpenAI Responses parser sets it exactly onresponse.completed/incomplete/failed; stdio/Linux behaviour of the repro path is unchanged).Related Issue
Fixes #8826
Contribution Checklist