Skip to content

Propagate ContinuationToken through Response.ToUpdates so it survives a ToUpdates/Collect round-trip - #705

Merged
George Adams (gdams) merged 2 commits into
microsoft:mainfrom
PratikDhanaveFork:propagate-continuationtoken-toupdates
Jul 29, 2026
Merged

Propagate ContinuationToken through Response.ToUpdates so it survives a ToUpdates/Collect round-trip#705
George Adams (gdams) merged 2 commits into
microsoft:mainfrom
PratikDhanaveFork:propagate-continuationtoken-toupdates

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Response.ToUpdates() copies response-level FinishReason, CreatedAt, AdditionalProperties and Usage onto the emitted ResponseUpdate values, but never set ContinuationToken, even though both Response and ResponseUpdate carry that field.

Because Response.Update() resets resp.ContinuationToken to empty for every update whose token is empty, and every ToUpdates-emitted update had an empty token, a Response{ContinuationToken: tok} converted via ToUpdates and re-collected yielded an empty ContinuationToken.

This extends the trailing extra-update condition to also fire when ContinuationToken is non-empty, and sets extra.ContinuationToken on it so a subsequent Collect reconstructs the token.

Why

Four sibling response-level fields were already copied in the same function while ContinuationToken alone was omitted. This aligns with .NET, where AsChatResponseUpdate copies ContinuationToken, keeping the ToUpdates/Collect round-trip lossless across SDKs.

Testing

Added TestResponse_ToUpdates_PropagatesContinuationToken in agent/response_test.go: it builds a Response with an assistant message and ContinuationToken: tok-123, round-trips it through ToUpdates then Update/Coalesce, and asserts the token is preserved. The test fails before the change (empty token) and passes after. go build ./..., go vet ./agent/... and go test ./agent/... are green.

Copilot AI review requested due to automatic review settings July 24, 2026 02:35
@PratikDhanave
PratikDhanave (PratikDhanave) requested a review from a team as a code owner July 24, 2026 02:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Propagates ContinuationToken through Response.ToUpdates() so a Response can round-trip through ToUpdates + Update/Collect without losing the continuation token, aligning behavior with other SDKs.

Changes:

  • Emit an extra metadata ResponseUpdate when Response.ContinuationToken is non-empty, and copy the token onto that update.
  • Add a regression test ensuring ContinuationToken survives a ToUpdatesUpdate/Coalesce round-trip.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
agent/response.go Include ContinuationToken in the metadata-only “extra update” path so it can be reconstructed by collection.
agent/response_test.go Add a round-trip test to verify ContinuationToken is preserved.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agent/response.go
Comment thread agent/response.go
@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 24, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the public-api-change Pull Request changes public APIs label Jul 24, 2026
@PratikDhanave
PratikDhanave (PratikDhanave) force-pushed the propagate-continuationtoken-toupdates branch from a22e442 to cbc8057 Compare July 24, 2026 03:01
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the public-api-change Pull Request changes public APIs label Jul 24, 2026
@github-actions

This comment has been minimized.

ToUpdates copied response-level FinishReason, CreatedAt,
AdditionalProperties and Usage onto emitted updates but omitted
ContinuationToken. Since Collect clears the token on any empty-token
update, a Response carrying a token lost it after a ToUpdates/Collect
round-trip. Set it on the trailing update, matching .NET
AsChatResponseUpdate.
@PratikDhanave
PratikDhanave (PratikDhanave) force-pushed the propagate-continuationtoken-toupdates branch from 9ca0b4c to 514d8cb Compare July 24, 2026 09:33
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review — ✅ Approved

Scope: agent/response.go, agent/response_test.go — behavioral bug fix only; no new exported types, methods, or fields introduced.

What changed

  1. Response.ToUpdates() — the trailing metadata-only update now carries ContinuationToken when the response has one, so a ToUpdatesUpdate/Coalesce round-trip is lossless.
  2. Response.Update() — a nil RawRepresentation on an incoming ResponseUpdate is now skipped instead of overwriting the accumulated message value. This prevents metadata-only updates (e.g. the token-carrying trailing update from ToUpdates) from corrupting a message's raw provider data.

Cross-repo alignment

The PR description correctly identifies the upstream .NET reference. In dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs, the streaming path wraps and forwards ContinuationToken through every ChatResponseUpdate via WrapContinuationToken(update.ContinuationToken, ...). The fix in this PR closes the equivalent gap in Go, making ToUpdates/Collect round-trips as lossless as the .NET streaming path.

No equivalent Python surface for ContinuationToken-in-streaming was found; this appears to be a .NET ↔ Go concept only, so no Python divergence to flag.

API surface

No exported identifiers were added, removed, or renamed. The public-api-change label is not warranted.

Verdict

The change is a targeted bug fix that moves Go closer to .NET parity. No cross-SDK consistency issues found.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 42.1 AIC · ⌖ 4.03 AIC · ⊞ 5.9K ·

@gdams
George Adams (gdams) added this pull request to the merge queue Jul 29, 2026
Merged via the queue into microsoft:main with commit ff23f1e Jul 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants