fix(delegate-task): prevent stale-text abort recovery

This commit is contained in:
YeonGyu-Kim
2026-05-11 09:20:14 +09:00
parent 8e47d3a166
commit 8b1696f5e5
4 changed files with 89 additions and 3 deletions
+22 -1
View File
@@ -5,7 +5,8 @@ import { normalizeSDKResponse } from "../../shared"
export async function fetchSyncResult(
client: OpencodeClient,
sessionID: string,
anchorMessageCount?: number
anchorMessageCount?: number,
options?: { strictAbortRecovery?: boolean }
): Promise<{ ok: true; textContent: string } | { ok: false; error: string }> {
const messagesResult = await client.session.messages({
path: { id: sessionID },
@@ -44,6 +45,26 @@ export async function fetchSyncResult(
return { ok: false, error: `No assistant response found.\n\nSession ID: ${sessionID}` }
}
if (options?.strictAbortRecovery) {
if (lastMessage.info && "error" in lastMessage.info) {
return {
ok: false,
error: `Latest assistant message is an error; refusing abort recovery.\n\nSession ID: ${sessionID}`,
}
}
const lastTextParts = lastMessage.parts?.filter((p) => p.type === "text" || p.type === "reasoning") ?? []
const lastContent = lastTextParts.map((p) => p.text ?? "").filter(Boolean).join("\n")
if (!lastContent) {
return {
ok: false,
error: `No assistant text output found in latest response.\n\nSession ID: ${sessionID}`,
}
}
return { ok: true, textContent: lastContent }
}
// Search assistant messages (newest first) for one with text/reasoning content.
// The last assistant message may only contain tool calls with no text.
let textContent = ""