fix: recognize snake_case tool call types in session history repair#50802
fix: recognize snake_case tool call types in session history repair#50802lishuaigit wants to merge 4 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
https://github.com/openclaw/openclaw/blob/f72c134ea75a747529c16c4dc5fb575260e8ab8f/src/agents/session-transcript-repair.ts#L262-L266
Re-add snake_case tool blocks when rebuilding assistant content
Now that isRawToolCallBlock() returns true for tool_use/tool_call, this nested check still only handles the camelCase variants. When the same assistant turn also contains any dropped or rewritten block, repairToolCallInputs() emits nextContent without the valid snake_case block, so sanitizeToolCallInputs() can drop the assistant message entirely. I reproduced this with a turn containing a valid tool_use plus one malformed toolCall; the sanitizer returned only the following toolResult, which later repair logic treats as orphaned.
ℹ️ 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".
Greptile SummaryThis PR extends However, the inner type guard inside
The new tests pass because they use pure snake_case-only messages, which leave Key issues:
Confidence Score: 2/5
|
f72c134 to
a0084c1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0084c151c
ℹ️ 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".
68172b8 to
5e9c003
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e9c003df7
ℹ️ 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".
isRawToolCallBlock() only matched camelCase variants (toolCall, toolUse, functionCall) but Anthropic and some providers persist snake_case types (tool_call, tool_use, function_call) in session transcripts. When a streamed tool call is interrupted, the broken block with missing input survives sanitization because repairToolCallInputs skips it, causing persistent "session history corrupted" errors. Add tool_call, tool_use, and function_call to the type check so the repair logic can detect and fix (or drop) broken snake_case blocks. Closes openclaw#48915
The inner type guard only checked camelCase block types (toolCall, toolUse, functionCall), so snake_case blocks (tool_use, tool_call, function_call) passed isRawToolCallBlock but fell through without sanitization. This caused sessions_spawn attachments in snake_case blocks to persist un-redacted. Add a companion test confirming redaction works for tool_use blocks with sessions_spawn attachments.
be87849 to
4a1eeab
Compare
|
ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical. Source PR: #50802 |
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. from source inspection. A persisted assistant block like Next step before merge Security Review detailsBest possible solution: Land this PR, or an equivalent main-branch fix, after mergeability is restored and exact-head validation passes; keep linked #48915 open until the implementation merges. Do we have a high-confidence way to reproduce the issue? Yes, from source inspection. A persisted assistant block like Is this the best way to solve the issue? Yes. The PR applies the same narrow type-set expansion across detection, rebuild/redaction, result-pairing extraction, ID rewriting, tests, and changelog without adding a provider-specific migration or new policy knob. Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 103cdd9d96f8. |
Summary
/newcannot reliably resolve.isRawToolCallBlock()insession-transcript-repair.tsonly recognizes camelCase block types (toolCall,toolUse,functionCall) but Anthropic persiststool_use(snake_case). The broken block survivesrepairToolCallInputs()sanitization, and Anthropic rejects the request with"tool_use.input: field required".tool_call,tool_use, andfunction_callto the type check so the repair logic can detect and fix (or drop) broken snake_case blocks.Change Type
Scope
Linked Issue
User-visible / Behavior Changes
Before: Interrupted Anthropic tool call → persistent "session history corrupted" error →
/newdoesn't fix itAfter: Broken
tool_useblocks are detected and dropped by the sanitizer → session recovers automaticallySecurity Impact
None.
Evidence
Compatibility
Risks
None — the added types follow the exact same repair logic as the existing camelCase types.
[AI-assisted development by OpenClaw agent 虾干 🦐]