fix(session-recovery): fallback when stored unavailable-tool parts are absent

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-17 17:16:10 +09:00
parent 12bd658079
commit 6768decddb
2 changed files with 15 additions and 6 deletions
@@ -13,6 +13,10 @@ mock.module("./storage", () => ({
readParts: () => storedParts,
}))
mock.module("./storage/parts-reader", () => ({
readParts: () => storedParts,
}))
const { recoverUnavailableTool } = await import("./recover-unavailable-tool")
const failedAssistantMsg: MessageData = {
@@ -82,7 +86,10 @@ describe("recoverUnavailableTool", () => {
tool: "bash",
state: { input: {} },
}]
const { client, promptAsync } = createMockClient()
const { client, promptAsync } = createMockClient([{
info: { id: "msg_failed", role: "assistant" },
parts: [{ type: "tool", id: "prt_stored_valid_call", callID: "toolu_recovered", name: "bash", input: {} }],
}])
//#when
const result = await recoverUnavailableTool(client, "ses_2", failedAssistantMsg)
@@ -83,11 +83,13 @@ export async function recoverUnavailableTool(
parts = await readPartsFromSDKFallback(client, sessionID, failedAssistantMsg.info.id)
} else {
const storedParts = readParts(failedAssistantMsg.info.id)
parts = storedParts.map((part) => ({
type: part.type === "tool" ? "tool_use" : part.type,
id: "callID" in part ? (part as { callID?: string }).callID : part.id,
name: "tool" in part && typeof part.tool === "string" ? part.tool : undefined,
}))
parts = storedParts.length > 0
? storedParts.map((part) => ({
type: part.type === "tool" ? "tool_use" : part.type,
id: "callID" in part ? (part as { callID?: string }).callID : part.id,
name: "tool" in part && typeof part.tool === "string" ? part.tool : undefined,
}))
: await readPartsFromSDKFallback(client, sessionID, failedAssistantMsg.info.id)
}
}