fix(agents): normalize mangled tool names and IDs from OpenAI-compati…#39245
fix(agents): normalize mangled tool names and IDs from OpenAI-compati…#39245deepujain wants to merge 2 commits intoopenclaw:mainfrom
Conversation
…ble providers Add normalizeMangledToolCallId (functions -> functions.) and use in extractToolResultId and sanitizeToolCallIdsForCloudCodeAssist. Add normalizePrefixedToolName in session-transcript-repair for assistant and tool-result names. Fixes Tool functions exec not found matching. Fixes openclaw#39091
Greptile SummaryThis PR fixes tool call ID and name mismatches caused by OpenAI-compatible providers (e.g. Kimi) that send Key changes:
Confidence Score: 4/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7de7ed80a6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const normalizedName = trimmedName | ||
| ? normalizePrefixedToolName(trimmedName) | ||
| : trimmedName; | ||
| if (rawName !== normalizedName && normalizedName) { | ||
| const renamed = { ...(block as object), name: normalizedName } as typeof block; |
There was a problem hiding this comment.
Redact prefixed sessions_spawn calls before renaming
When a provider emits a prefixed tool name like functions.sessions_spawn, the blockName check has already skipped the sessions_spawn redaction path, and this new branch only renames the tool to sessions_spawn. Because sanitizeToolCallBlock is never invoked here, input.attachments[].content is persisted unredacted for these prefixed calls, which regresses transcript privacy for OpenAI-compatible providers that mangle tool names.
Useful? React with 👍 / 👎.
|
Codex P1: redaction now runs for prefixed tool names (e.g. functions.sessions_spawn). |
…tions.sessions_spawn)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b488bcaaf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const toolCallId = (msg as { toolCallId?: unknown }).toolCallId; | ||
| if (typeof toolCallId === "string" && toolCallId) { | ||
| return toolCallId; | ||
| return normalizeMangledToolCallId(toolCallId); |
There was a problem hiding this comment.
Preserve raw tool result IDs for pending-state lookups
Normalizing IDs inside extractToolResultId makes downstream code see a different key than what was tracked from assistant tool calls. In installSessionToolResultGuard, pending calls are stored by raw call.id (session-tool-result-state.ts) but removed via extractToolResultId (session-tool-result-guard.ts), so a mangled ID like functions exec:0 now gets looked up as functions.exec:0 and is never deleted. When the next non-tool message arrives, the stale pending entry can trigger a synthetic "missing tool result" even though the real tool result was already written.
Useful? React with 👍 / 👎.
Summary
functions.exec:0asfunctions exec:0(space instead of dot) and tool names likeexecasfunctions exec. Tool result matching fails, causing "Tool functions exec not found" errors.normalizeMangledToolCallId()intool-call-id.tsto rewritefunctions->functions.in IDs; use it inextractToolResultId()and as the key insanitizeToolCallIdsForCloudCodeAssist()so mangled and canonical IDs map to the same sanitized value. AddednormalizePrefixedToolName()insession-transcript-repair.tsto stripfunctions./functionsfrom tool names; applied in assistant block handling,hasToolCallName, andnormalizeToolResultName()so tool-result names are normalized and pairing works.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Tool-using flows with OpenAI-compatible providers that mangle tool IDs/names (e.g. Kimi) now match tool results to tool calls correctly; "Tool functions exec not found" is resolved.
Security Impact (required)
Repro + Verification
Environment
functions exec:0/functions execstyle IDs and namesSteps
Expected
Tool results pair with assistant tool calls; no spurious "tool not found" from ID/name mangling.
Actual
As expected after the fix.
Evidence
normalizeMangledToolCallIdandextractToolResultId/sanitizeToolCallIdsForCloudCodeAssisttests intool-call-id.test.ts.sanitizeToolUseResultPairingtest with mangled ID and prefixed name insession-transcript-repair.test.ts.Human Verification (required)
Compatibility / Migration
Failure Recovery (if this breaks)
src/agents/tool-call-id.ts,src/agents/session-transcript-repair.ts.Risks and Mitigations
None. Normalization is additive and only affects matching/sanitization; no new execution paths.