diff --git a/src/tools/delegate-task/sync-continuation.test.ts b/src/tools/delegate-task/sync-continuation.test.ts index 7d0015503..967b30fb4 100644 --- a/src/tools/delegate-task/sync-continuation.test.ts +++ b/src/tools/delegate-task/sync-continuation.test.ts @@ -357,6 +357,60 @@ describe("executeSyncContinuation - toast cleanup error paths", () => { expect(removeTaskCalls[0]).toBe("resume_sync_ses_test") }) + test("does not recover abort poll error when anchor cannot be established", async () => { + const mockClient = { + session: { + messages: async () => { + throw new Error("messages unavailable") + }, + promptAsync: async () => ({}), + status: async () => ({ + data: { ses_test: { type: "idle" } }, + }), + }, + } + + const { executeSyncContinuation } = require("./sync-continuation") + let fetchSyncResultCalled = false + + const deps = { + pollSyncSession: async () => "The operation was aborted.", + fetchSyncResult: async () => { + fetchSyncResultCalled = true + return { ok: true as const, textContent: "Recovered result" } + }, + } + + const mockCtx = { + sessionID: "parent-session", + callID: "call-123", + metadata: () => {}, + } + + const mockExecutorCtx = { + client: mockClient, + } + + const args = { + task_id: "ses_test_12345678", + prompt: "test prompt", + description: "test task", + category: "test", + load_skills: [], + run_in_background: false, + } + + //#when + const result = await executeSyncContinuation(args, mockCtx, mockExecutorCtx, { + sessionID: "parent-session", + messageID: "parent-message", + }, deps) + + //#then + expect(result).toBe("The operation was aborted.") + expect(fetchSyncResultCalled).toBe(false) + }) + test("removes toast on successful completion", async () => { //#given - mock successful completion with messages growing after anchor const mockClient = { diff --git a/src/tools/delegate-task/sync-continuation.ts b/src/tools/delegate-task/sync-continuation.ts index 17c85f026..817a7e95d 100644 --- a/src/tools/delegate-task/sync-continuation.ts +++ b/src/tools/delegate-task/sync-continuation.ts @@ -188,6 +188,9 @@ export async function executeSyncContinuation( anchorMessageCount, }, syncPollTimeoutMs) if (pollError && shouldAttemptPollErrorRecovery(pollError)) { + if (anchorMessageCount === undefined) { + return pollError + } const recoveredResult = await deps.fetchSyncResult(client, continuationID, anchorMessageCount) if (!recoveredResult.ok) { return pollError diff --git a/src/tools/delegate-task/sync-result-fetcher.ts b/src/tools/delegate-task/sync-result-fetcher.ts index f2274eae6..9631d3637 100644 --- a/src/tools/delegate-task/sync-result-fetcher.ts +++ b/src/tools/delegate-task/sync-result-fetcher.ts @@ -56,5 +56,12 @@ export async function fetchSyncResult( } } + if (!textContent) { + return { + ok: false, + error: `No assistant text output found in completed response.\n\nSession ID: ${sessionID}`, + } + } + return { ok: true, textContent } }