fix(session-recovery): fallback to filesystem when API parts empty
When OpenCode API doesn't return parts in message response, read directly from filesystem using readParts(messageID). This fixes session recovery failures where tool_use IDs couldn't be extracted because API response had empty parts array. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
findMessagesWithThinkingOnly,
|
findMessagesWithThinkingOnly,
|
||||||
injectTextPart,
|
injectTextPart,
|
||||||
prependThinkingPart,
|
prependThinkingPart,
|
||||||
|
readParts,
|
||||||
stripThinkingParts,
|
stripThinkingParts,
|
||||||
} from "./storage"
|
} from "./storage"
|
||||||
import type { MessageData } from "./types"
|
import type { MessageData } from "./types"
|
||||||
@@ -100,7 +101,17 @@ async function recoverToolResultMissing(
|
|||||||
sessionID: string,
|
sessionID: string,
|
||||||
failedAssistantMsg: MessageData
|
failedAssistantMsg: MessageData
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const parts = failedAssistantMsg.parts || []
|
// Try API parts first, fallback to filesystem if empty
|
||||||
|
let parts = failedAssistantMsg.parts || []
|
||||||
|
if (parts.length === 0 && failedAssistantMsg.info?.id) {
|
||||||
|
const storedParts = readParts(failedAssistantMsg.info.id)
|
||||||
|
parts = storedParts.map((p) => ({
|
||||||
|
type: p.type === "tool" ? "tool_use" : p.type,
|
||||||
|
id: "callID" in p ? (p as { callID?: string }).callID : p.id,
|
||||||
|
name: "tool" in p ? (p as { tool?: string }).tool : undefined,
|
||||||
|
input: "state" in p ? (p as { state?: { input?: Record<string, unknown> } }).state?.input : undefined,
|
||||||
|
}))
|
||||||
|
}
|
||||||
const toolUseIds = extractToolUseIds(parts)
|
const toolUseIds = extractToolUseIds(parts)
|
||||||
|
|
||||||
if (toolUseIds.length === 0) {
|
if (toolUseIds.length === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user