fix: repair unpaired tool calls when loading sessions#3707
fix: repair unpaired tool calls when loading sessions#3707bheemreddy181 wants to merge 2 commits intoopenclaw:mainfrom
Conversation
beb5a5b to
5d3b90d
Compare
5d3b90d to
912909b
Compare
When a session is loaded with assistant tool calls that never received results (e.g., due to exec timeout, crash, or interruption), the session would become stuck and unresponsive. This fix adds repair logic during session initialization that: - Detects unpaired tool calls in the loaded session history - Injects synthetic error tool results for missing results - Marks the session as unflushed so repairs are persisted This ensures sessions can always recover from incomplete tool executions instead of remaining permanently stuck. Fixes group chat sessions getting stuck when exec commands time out.
912909b to
0e4ae1b
Compare
- Sort imports alphabetically (Foundation before framework imports) - Fix indentation and remove trailing spaces in help text - Simplify redundant property definitions - Wrap single-line property bodies onto multiple lines - Use if expressions for conditional assignments - Convert comment to doc comment for API declarations
88588f3 to
bd46932
Compare
|
|
||
| if (messages.length === 0) return; | ||
|
|
||
| const report = repairToolUseResultPairing(messages as any); |
There was a problem hiding this comment.
[P2] Avoid any cast when repairing messages
repairToolUseResultPairing expects AgentMessage[], but messages is currently inferred as NonNullable<SessionMessageEntry["message"]>[] and is cast to any (session-manager-init.ts:86). This loses type safety right at the boundary where we’re mutating transcripts, and can hide shape mismatches until runtime.
Consider narrowing SessionMessageEntry["message"] to the concrete AgentMessage type (or validating/casting each message to AgentMessage) so this call can be typed without any.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/session-manager-init.ts
Line: 86:86
Comment:
[P2] Avoid `any` cast when repairing messages
`repairToolUseResultPairing` expects `AgentMessage[]`, but `messages` is currently inferred as `NonNullable<SessionMessageEntry["message"]>[]` and is cast to `any` (`session-manager-init.ts:86`). This loses type safety right at the boundary where we’re mutating transcripts, and can hide shape mismatches until runtime.
Consider narrowing `SessionMessageEntry["message"]` to the concrete `AgentMessage` type (or validating/casting each message to `AgentMessage`) so this call can be typed without `any`.
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
The help text indentation was increased for the header/usage/options lines, but the option lines remain less indented, so the output is visually misaligned (e.g. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/macos/Sources/MoltbotMacCLI/ConnectCommand.swift
Line: 101:103
Comment:
[P3] Help output indentation is inconsistent
The help text indentation was increased for the header/usage/options lines, but the option lines remain less indented, so the output is visually misaligned (e.g. `ConnectCommand.swift:101-113`). Consider making the `--url/--token/...` lines match the indentation level used for `Options:` (and similarly in the other CLI commands). Also appears in `apps/macos/Sources/MoltbotMacCLI/DiscoverCommand.swift:58-68` and `apps/macos/Sources/MoltbotMacCLI/WizardCommand.swift:71-81`.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
When a session is loaded with assistant tool calls that never received results (e.g., due to exec timeout, crash, or interruption), the session would become stuck and unresponsive.
This fix adds repair logic during session initialization that:
This ensures sessions can always recover from incomplete tool executions instead of remaining permanently stuck.
Fixes group chat sessions getting stuck when exec commands time out.
Greptile Overview
Greptile Summary
This PR makes session loading more resilient by repairing incomplete tool execution transcripts during
SessionManagerinitialization. It detects assistant tool calls that never received matching tool results and injects synthetic errortoolResultmessages so strict providers don’t reject the transcript; it also marks the session as unflushed so the repaired transcript is persisted. Additionally, it includes SwiftFormat-driven formatting updates across several macOS CLI/app files.Confidence Score: 4/5
repairToolUseResultPairingand is exercised by a new Vitest suite. The main remaining concern is type-safety around theanycast when passing session messages into the repair function, which could hide unexpected message shapes at runtime, but it’s unlikely to break existing behavior.(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!