fix(background-agent): handle idle status events
This commit is contained in:
@@ -5023,6 +5023,67 @@ describe("BackgroundManager.handleEvent - session.error", () => {
|
|||||||
manager.shutdown()
|
manager.shutdown()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("completes task on session.status idle after todo-continuation finishes", async () => {
|
||||||
|
//#given
|
||||||
|
const sessionID = "ses-status-idle-after-todo-continuation"
|
||||||
|
const client = {
|
||||||
|
session: {
|
||||||
|
prompt: async () => ({}),
|
||||||
|
promptAsync: async () => ({}),
|
||||||
|
abort: async () => ({}),
|
||||||
|
messages: async () => ({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
info: { role: "assistant" },
|
||||||
|
parts: [{ type: "text", text: "final verified result" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
todo: async () => ({ data: [] }),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const manager = new BackgroundManager({ pluginContext: createPluginInput(client) })
|
||||||
|
stubNotifyParentSession(manager)
|
||||||
|
mockVerifySessionExists(manager, true)
|
||||||
|
|
||||||
|
const task = createMockTask({
|
||||||
|
id: "task-status-idle-after-todo-continuation",
|
||||||
|
sessionId: sessionID,
|
||||||
|
parentSessionId: "parent-session",
|
||||||
|
parentMessageId: "msg-status-idle",
|
||||||
|
description: "task that finished after todo-continuation",
|
||||||
|
agent: "explore",
|
||||||
|
status: "running",
|
||||||
|
startedAt: new Date(Date.now() - (MIN_IDLE_TIME_MS + 10)),
|
||||||
|
})
|
||||||
|
getTaskMap(manager).set(task.id, task)
|
||||||
|
|
||||||
|
manager.handleEvent({
|
||||||
|
type: "todo.updated",
|
||||||
|
properties: {
|
||||||
|
sessionID,
|
||||||
|
todos: [{ id: "todo-1", content: "compile result", status: "completed", priority: "high" }],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
//#when
|
||||||
|
manager.handleEvent({
|
||||||
|
type: "session.status",
|
||||||
|
properties: {
|
||||||
|
sessionID,
|
||||||
|
status: { type: "idle" },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await flushBackgroundNotifications()
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(task.status).toBe("completed")
|
||||||
|
expect(task.completedAt).toBeDefined()
|
||||||
|
|
||||||
|
manager.shutdown()
|
||||||
|
})
|
||||||
|
|
||||||
test("retry path releases current concurrency slot and prefers current provider in fallback entry", async () => {
|
test("retry path releases current concurrency slot and prefers current provider in fallback entry", async () => {
|
||||||
//#given
|
//#given
|
||||||
const manager = createBackgroundManager()
|
const manager = createBackgroundManager()
|
||||||
|
|||||||
@@ -1531,7 +1531,14 @@ The fallback retry session is now created and can be inspected directly.
|
|||||||
if (event.type === "session.status") {
|
if (event.type === "session.status") {
|
||||||
const sessionID = props?.sessionID as string | undefined
|
const sessionID = props?.sessionID as string | undefined
|
||||||
const status = props?.status as { type?: string; message?: string } | undefined
|
const status = props?.status as { type?: string; message?: string } | undefined
|
||||||
if (!sessionID || status?.type !== "retry") return
|
if (!sessionID || !status?.type) return
|
||||||
|
|
||||||
|
if (status.type === "idle") {
|
||||||
|
this.handleEvent({ type: "session.idle", properties: { sessionID } })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.type !== "retry") return
|
||||||
|
|
||||||
const resolved = this.resolveTaskAttemptBySession(sessionID)
|
const resolved = this.resolveTaskAttemptBySession(sessionID)
|
||||||
if (!resolved?.isCurrent) return
|
if (!resolved?.isCurrent) return
|
||||||
|
|||||||
Reference in New Issue
Block a user