Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zerone0x
Copy link
Contributor

Summary

Fixes #1359

Some providers like Mistral via OpenRouter require strictly alphanumeric tool call IDs. The error message indicates:

Tool call id was whatsapp_login_1768799841527_1 but must be a-z, A-Z, 0-9, with a length of 9.

This PR updates the tool call ID sanitization to be more restrictive, using only alphanumeric characters ([a-zA-Z0-9]) instead of the previous pattern that allowed underscores and hyphens ([a-zA-Z0-9_-]).

Changes

  • Update sanitizeToolCallId to strip all non-alphanumeric characters (previously replaced with underscores)
  • Update makeUniqueToolId to use alphanumeric suffixes (x2, x3, etc. and t<timestamp>) instead of underscores
  • Update isValidCloudCodeAssistToolId to validate alphanumeric-only IDs
  • Update tests to reflect stricter sanitization

Test plan

  • Run pnpm exec vitest run src/agents/tool-call-id.test.ts - all 4 tests pass
  • Run pnpm exec vitest run src/agents/pi-embedded-helpers.sanitizetoolcallid.test.ts - all 3 tests pass
  • Run related sanitization tests - all pass
  • Test with actual OpenRouter Mistral model to verify fix

🤖 Generated with Claude Code

@steipete
Copy link
Contributor

Should we make this conditional? Does this even show up in session logs? Makes stuff hard to read.

zerone0x added a commit to zerone0x/clawdbot that referenced this pull request Jan 21, 2026
…/strict modes

- Add ToolCallIdMode type ('standard' | 'strict') for provider compatibility
- Standard mode (default): allows [a-zA-Z0-9_-] for readable session logs
- Strict mode: only [a-zA-Z0-9] for Mistral via OpenRouter
- Update sanitizeSessionMessagesImages to accept toolCallIdMode option
- Export ToolCallIdMode from pi-embedded-helpers barrel

Addresses review feedback on PR openclaw#1372 about readability.
@zerone0x
Copy link
Contributor Author

Good call! I've refactored the sanitization to support two modes:

  • Standard mode (default): Allows [a-zA-Z0-9_-] for better readability in session logs. IDs like call_abc_123 stay as call_abc_123, and only truly invalid chars (like | or :) get replaced with _.
  • Strict mode: Only [a-zA-Z0-9] for providers like Mistral via OpenRouter that require strictly alphanumeric IDs.

The sanitizeSessionMessagesImages function now accepts an optional toolCallIdMode parameter so callers can explicitly opt into strict mode when needed for specific providers.

This preserves readability by default while still fixing the Mistral/OpenRouter compatibility issue when strict mode is used.

@steipete steipete force-pushed the fix/openrouter-tool-call-id-alphanumeric branch from 9cab74e to 867b60f Compare January 22, 2026 00:39
steipete pushed a commit to zerone0x/clawdbot that referenced this pull request Jan 22, 2026
…/strict modes

- Add ToolCallIdMode type ('standard' | 'strict') for provider compatibility
- Standard mode (default): allows [a-zA-Z0-9_-] for readable session logs
- Strict mode: only [a-zA-Z0-9] for Mistral via OpenRouter
- Update sanitizeSessionMessagesImages to accept toolCallIdMode option
- Export ToolCallIdMode from pi-embedded-helpers barrel

Addresses review feedback on PR openclaw#1372 about readability.
steipete added a commit to zerone0x/clawdbot that referenced this pull request Jan 22, 2026
zerone0x and others added 4 commits January 22, 2026 00:41
…tibility

Some providers like Mistral via OpenRouter require strictly alphanumeric
tool call IDs. The error message indicates: "Tool call id was
whatsapp_login_1768799841527_1 but must be a-z, A-Z, 0-9, with a length
of 9."

Changes:
- Update sanitizeToolCallId to strip all non-alphanumeric characters
  (previously allowed underscores and hyphens)
- Update makeUniqueToolId to use alphanumeric suffixes (x2, x3, etc.)
  instead of underscores
- Update isValidCloudCodeAssistToolId to validate alphanumeric-only IDs
- Update tests to reflect stricter sanitization

Fixes openclaw#1359

Co-Authored-By: Claude <[email protected]>
…/strict modes

- Add ToolCallIdMode type ('standard' | 'strict') for provider compatibility
- Standard mode (default): allows [a-zA-Z0-9_-] for readable session logs
- Strict mode: only [a-zA-Z0-9] for Mistral via OpenRouter
- Update sanitizeSessionMessagesImages to accept toolCallIdMode option
- Export ToolCallIdMode from pi-embedded-helpers barrel

Addresses review feedback on PR openclaw#1372 about readability.
@steipete steipete force-pushed the fix/openrouter-tool-call-id-alphanumeric branch from 867b60f to f5cec1d Compare January 22, 2026 01:17
@steipete steipete merged commit 9780748 into openclaw:main Jan 22, 2026
17 of 22 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: f5cec1d\n- Merge commit: 9780748\n\nThanks @zerone0x!

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]: OpenRouter rejects tool call IDs with underscores

2 participants