fix(delegate-task): read messages after status errors
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
/// <reference types="bun-types" />
|
||||||
|
import { afterEach, describe, expect, test } from "bun:test"
|
||||||
|
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||||
|
import { pollSyncSession } from "./sync-session-poller"
|
||||||
|
import { __resetTimingConfig, __setTimingConfig } from "./timing"
|
||||||
|
import type { OpencodeClient, ToolContextWithMetadata } from "./types"
|
||||||
|
|
||||||
|
const toolContext: ToolContextWithMetadata = {
|
||||||
|
sessionID: "ses_parent",
|
||||||
|
messageID: "msg_parent",
|
||||||
|
agent: "sisyphus",
|
||||||
|
abort: new AbortController().signal,
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("pollSyncSession status fallback", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
__resetTimingConfig()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("#given status API is unavailable but assistant text exists #when polling #then messages complete the sync task", async () => {
|
||||||
|
// given
|
||||||
|
__setTimingConfig({
|
||||||
|
POLL_INTERVAL_MS: 1,
|
||||||
|
MAX_POLL_TIME_MS: 50,
|
||||||
|
})
|
||||||
|
const client = unsafeTestValue<OpencodeClient>({
|
||||||
|
session: {
|
||||||
|
messages: async () => ({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
info: { role: "assistant" },
|
||||||
|
parts: [{ type: "text", text: "done" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
abort: async () => ({ data: {} }),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// when
|
||||||
|
const result = await pollSyncSession(toolContext, client, {
|
||||||
|
sessionID: "ses_missing_status",
|
||||||
|
agentToUse: "sisyphus",
|
||||||
|
toastManager: null,
|
||||||
|
taskId: undefined,
|
||||||
|
}, 50)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(result).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -142,15 +142,15 @@ export async function pollSyncSession(
|
|||||||
await wait(syncTiming.POLL_INTERVAL_MS)
|
await wait(syncTiming.POLL_INTERVAL_MS)
|
||||||
pollCount++
|
pollCount++
|
||||||
|
|
||||||
let statusResult: { data?: Record<string, { type: string }> }
|
let sessionStatus: { type: string } | undefined
|
||||||
try {
|
try {
|
||||||
statusResult = await client.session.status()
|
const statusResult = await client.session.status()
|
||||||
|
const allStatuses = normalizeSDKResponse(statusResult, {} as Record<string, { type: string }>)
|
||||||
|
sessionStatus = allStatuses[input.sessionID]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log("[task] Poll status fetch failed, retrying", { sessionID: input.sessionID, error: String(error) })
|
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||||
continue
|
log("[task] Poll status fetch failed, checking messages", { sessionID: input.sessionID, error: errorMessage })
|
||||||
}
|
}
|
||||||
const allStatuses = normalizeSDKResponse(statusResult, {} as Record<string, { type: string }>)
|
|
||||||
const sessionStatus = allStatuses[input.sessionID]
|
|
||||||
|
|
||||||
if (pollCount % 10 === 0) {
|
if (pollCount % 10 === 0) {
|
||||||
log("[task] Poll status", {
|
log("[task] Poll status", {
|
||||||
|
|||||||
Reference in New Issue
Block a user