Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 26, 2025

Summary

Fixes #10328
Fixes ROO-311: Write to File truncates filenames at special characters before file content

Problem

The Bedrock provider was not emitting tool_call_end events after tool use streaming, unlike other providers (e.g., OpenAI, Anthropic). The NativeToolCallParser requires these events to finalize tool calls and flush complete arguments. Without them, the parser would continue accumulating arguments in a buffer that never got finalized, causing filenames with special characters like parentheses to get truncated.

Root Cause

Comparing to other providers like base-openai-compatible-provider.ts (lines 186-193), they explicitly emit tool_call_end events when the stream indicates tool calls are complete. Bedrock was missing this logic entirely.

Solution

  • Add contentBlockStop event type to the StreamEvent interface
  • Track tool call IDs when contentBlockStart receives a tool use block
  • Emit tool_call_end when contentBlockStop is received for a tracked tool use block
  • Emit tool_call_end as a fallback on messageStop with stopReason: tool_use for any remaining active tool calls

Testing

Added 4 new tests for native tool streaming support:

  • Tests tool_call_end emission when contentBlockStop is received
  • Tests tool_call_end emission via messageStop fallback when contentBlockStop is missing
  • Tests multiple tool_call_end events for parallel tool calls
  • Tests no tool_call_end when stopReason is not tool_use

All 58 bedrock.spec.ts tests pass ✅

Fixes ROO-311: Write to File truncates filenames at special characters before file content

The Bedrock provider was not emitting tool_call_end events after tool use
streaming, unlike other providers (e.g., OpenAI, Anthropic). The NativeToolCallParser
requires these events to finalize tool calls and flush complete arguments.
Without them, the parser would continue accumulating arguments in a buffer
that never got finalized, causing filenames with special characters like
parentheses to get truncated.

Changes:
- Add contentBlockStop event type to StreamEvent interface
- Track tool call IDs when contentBlockStart receives a tool use block
- Emit tool_call_end when contentBlockStop is received for a tracked tool block
- Emit tool_call_end as fallback on messageStop with stopReason: tool_use

Tests added for:
- tool_call_end emission when contentBlockStop is received
- tool_call_end emission via messageStop fallback
- Multiple tool_call_end events for parallel tool calls
- No tool_call_end when stopReason is not tool_use
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Dec 26, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 26, 2025

Rooviewer Clock   See task on Roo Cloud

Code review complete. No issues found.

The implementation correctly adds tool_call_end event emission for the Bedrock provider, consistent with other providers like OpenAI. The fix properly handles:

  • Primary path via contentBlockStop events
  • Fallback path via messageStop with stopReason: tool_use
  • Multiple parallel tool calls
  • Non-tool-use messages

Tests cover all key scenarios.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 26, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

write_to_file truncates filenames at special characters before file extensions

4 participants