fix(delegate-task): require anchored text for abort recovery
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user