Skip to content

fix: normalize tool call ids before persisting events - #4610

Open
Gai-shi wants to merge 3 commits into
OpenHands:mainfrom
Gai-shi:fix_colon-delimited_tool-call_IDs
Open

fix: normalize tool call ids before persisting events#4610
Gai-shi wants to merge 3 commits into
OpenHands:mainfrom
Gai-shi:fix_colon-delimited_tool-call_IDs

Conversation

@Gai-shi

@Gai-shi Gai-shi commented Aug 24, 2026

Copy link
Copy Markdown

HUMAN:
I verified this bugfix locally and it matches the issue reproduction scope.


AGENT:

Why

Parallel MCP tool calls can produce tool call IDs containing characters such as :.
Those IDs are persisted into conversation events and later used to link agent
actions with tool observations. If invalid IDs enter persisted history, replaying
the conversation through the OpenAI Responses API can fail because Responses only
accepts letters, numbers, underscores, and dashes in function call IDs.

This PR normalizes tool call IDs when SDK MessageToolCall objects are created
from LLM tool-call outputs, before those IDs are persisted into conversation events.

Summary

  • Normalize Chat Completions tool call IDs before creating SDK MessageToolCall objects.
  • Normalize OpenAI Responses function call call_id values when parsing Responses output.
  • Add regression coverage for parallel colon-delimited tool call IDs flowing through conversation.run() into ActionEvent and ObservationEvent.

Issue Number

fixes #4578

How to Test

Ran:

UV_CACHE_DIR=.uv-cache uv run pytest tests/sdk/agent/test_tool_call_id_normalization.py tests/sdk/llm/test_message_tool_call.py -q
UV_CACHE_DIR=.uv-cache uv run pre-commit run --files openhands-sdk/openhands/sdk/llm/message.py tests/sdk/agent/test_tool_call_id_normalization.py

Results:

10 passed
pre-commit passed: ruff format, ruff lint, pycodestyle, pyright, import rules, tool registration

Video/Screenshots

N/A. This is an SDK event serialization bugfix covered by automated tests.

Design Doc

N/A. Small scoped bugfix.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

This prevents newly generated colon-delimited tool call IDs from being persisted.
It does not migrate or repair already persisted historical conversations that contain
invalid tool call IDs.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

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.

[Bug]: Switching to GPT-5.6 fails when history contains colon-delimited tool-call IDs

2 participants