fix(look-at): avoid empty stable idle completion
This commit is contained in:
@@ -61,6 +61,7 @@ Original error: ${createResult.error}`
|
|||||||
log(`[look_at] Created session: ${sessionID}`)
|
log(`[look_at] Created session: ${sessionID}`)
|
||||||
|
|
||||||
log(`[look_at] Sending prompt with ${isBase64Input ? "base64 image" : "file"} to session ${sessionID}`)
|
log(`[look_at] Sending prompt with ${isBase64Input ? "base64 image" : "file"} to session ${sessionID}`)
|
||||||
|
let promptFailed = false
|
||||||
try {
|
try {
|
||||||
await promptSyncWithModelSuggestionRetry(ctx.client, {
|
await promptSyncWithModelSuggestionRetry(ctx.client, {
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
@@ -83,6 +84,7 @@ Original error: ${createResult.error}`
|
|||||||
queueBehavior: "defer",
|
queueBehavior: "defer",
|
||||||
})
|
})
|
||||||
} catch (promptError) {
|
} catch (promptError) {
|
||||||
|
promptFailed = true
|
||||||
log("[look_at] Prompt error (ignored, will still fetch messages):", promptError)
|
log("[look_at] Prompt error (ignored, will still fetch messages):", promptError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +93,7 @@ Original error: ${createResult.error}`
|
|||||||
if (typeof ctx.client.session.status === "function") {
|
if (typeof ctx.client.session.status === "function") {
|
||||||
const waitResult = await waitForLookAtSessionResult(ctx.client, sessionID, {
|
const waitResult = await waitForLookAtSessionResult(ctx.client, sessionID, {
|
||||||
allowStableIdleWithoutActivity: true,
|
allowStableIdleWithoutActivity: true,
|
||||||
|
allowEmptyStableIdleWithoutActivity: promptFailed,
|
||||||
})
|
})
|
||||||
observedText = waitResult.outcome.text ?? undefined
|
observedText = waitResult.outcome.text ?? undefined
|
||||||
if (observedText) {
|
if (observedText) {
|
||||||
|
|||||||
@@ -78,6 +78,18 @@ describe("waitForLookAtSessionResult", () => {
|
|||||||
expect(result.outcome.text).toBe("done")
|
expect(result.outcome.text).toBe("done")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("#given session is absent and has no assistant output #when stable idle is allowed #then keeps polling", async () => {
|
||||||
|
const client = createMockClient([{ data: {} }], [])
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
waitForLookAtSessionResult(unsafeTestValue(client), "ses_test", {
|
||||||
|
pollIntervalMs: 10,
|
||||||
|
timeoutMs: 50,
|
||||||
|
allowStableIdleWithoutActivity: true,
|
||||||
|
}),
|
||||||
|
).rejects.toThrow("timed out")
|
||||||
|
})
|
||||||
|
|
||||||
test("#given session never becomes idle #when polling exceeds timeout #then rejects", async () => {
|
test("#given session never becomes idle #when polling exceeds timeout #then rejects", async () => {
|
||||||
const client = createMockClient(
|
const client = createMockClient(
|
||||||
[{ data: { ses_test: { type: "busy" } } }],
|
[{ data: { ses_test: { type: "busy" } } }],
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export interface PollOptions {
|
|||||||
timeoutMs?: number
|
timeoutMs?: number
|
||||||
abortSignal?: AbortSignal
|
abortSignal?: AbortSignal
|
||||||
allowStableIdleWithoutActivity?: boolean
|
allowStableIdleWithoutActivity?: boolean
|
||||||
|
allowEmptyStableIdleWithoutActivity?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_POLL_INTERVAL_MS = 1000
|
const DEFAULT_POLL_INTERVAL_MS = 1000
|
||||||
@@ -136,7 +137,10 @@ export async function waitForLookAtSessionResult(
|
|||||||
const canConcludeIdle =
|
const canConcludeIdle =
|
||||||
sawNonIdleStatus ||
|
sawNonIdleStatus ||
|
||||||
!status.supported ||
|
!status.supported ||
|
||||||
Boolean(options?.allowStableIdleWithoutActivity)
|
(
|
||||||
|
Boolean(options?.allowStableIdleWithoutActivity)
|
||||||
|
&& (outcome.hasAssistant || Boolean(options?.allowEmptyStableIdleWithoutActivity))
|
||||||
|
)
|
||||||
|
|
||||||
if (canConcludeIdle && stableIdlePolls >= IDLE_STABILITY_POLLS_REQUIRED) {
|
if (canConcludeIdle && stableIdlePolls >= IDLE_STABILITY_POLLS_REQUIRED) {
|
||||||
return { messages, outcome, statusType }
|
return { messages, outcome, statusType }
|
||||||
|
|||||||
Reference in New Issue
Block a user