Skip to content

fix(event): generate unique blockId for text and thinking stream events#1929

Open
itxaiohanglover wants to merge 3 commits into
agentscope-ai:mainfrom
itxaiohanglover:fix/block-id-unique
Open

fix(event): generate unique blockId for text and thinking stream events#1929
itxaiohanglover wants to merge 3 commits into
agentscope-ai:mainfrom
itxaiohanglover:fix/block-id-unique

Conversation

@itxaiohanglover

@itxaiohanglover itxaiohanglover commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Problem

Text and Thinking block stream events used hardcoded block IDs ("text" and "thinking") instead of unique identifiers. When a single model response contained multiple text or thinking blocks (e.g., text → tool call → text), all blocks shared the same ID, making it impossible for clients to correlate start/delta/end events to the correct block.

Fix

Generate unique block IDs using replyId + "_text_" + counter and replyId + "_thinking_" + counter:

  • TextBlock: replyId + "_text_" + textBlockCounter.incrementAndGet()
  • ThinkingBlock: replyId + "_thinking_" + thinkingBlockCounter.incrementAndGet()

Both patterns are applied consistently to Start, Delta, and End events in:

  • emitBlockEvents() — main model call stream
  • summaryModelCallStream() — summary model call stream

Per maintainer feedback (@yulindong), ThinkingBlock was included in the same fix.

Test plan

  • Build passes: mvn compile -pl agentscope-core
  • Existing event tests pass

The blockId in TextBlockStartEvent, TextBlockDeltaEvent, and
TextBlockEndEvent was hardcoded as "text", violating the contract
that blockId should be a unique identifier per text block.

Generate a unique blockId (replyId + "_text_" + counter) each time
a new text block starts, so consumers can distinguish multiple text
blocks within a single reply.

Fixes agentscope-ai#1899
@itxaiohanglover itxaiohanglover requested a review from a team June 26, 2026 03:59
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 81.81% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@yulindong

Copy link
Copy Markdown

blockID of Thinking Block shell be fixed together

@itxaiohanglover

Copy link
Copy Markdown
Contributor Author

Good catch. I'll update the PR to also generate unique blockIDs for ThinkingBlock, following the same pattern as the text block fix.

Apply the same unique blockID pattern to ThinkingBlock that was
already applied to TextBlock: replyId + "_thinking_" + counter.

This ensures ThinkingBlockStart/Delta/End events within the same
reply use a consistent, unique block ID instead of the hardcoded
"thinking" string, which caused collisions when multiple thinking
blocks appeared in a single model response.
@itxaiohanglover itxaiohanglover changed the title fix(event): generate unique blockId for text stream events fix(event): generate unique blockId for text and thinking stream events Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants