fix(background-agent): cache observed output for completion checks
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -97,7 +97,11 @@ function createManagerWithClient(clientOverrides: Record<string, unknown> = {}):
|
||||
...clientOverrides,
|
||||
},
|
||||
}
|
||||
return new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
|
||||
return new BackgroundManager(
|
||||
{ client, directory: tmpdir() } as unknown as PluginInput,
|
||||
undefined,
|
||||
{ enableParentSessionNotifications: false },
|
||||
)
|
||||
}
|
||||
|
||||
describe("BackgroundManager verifySessionExists", () => {
|
||||
@@ -201,6 +205,39 @@ describe("BackgroundManager pollRunningTasks", () => {
|
||||
//#then
|
||||
expect(task.status).toBe("completed")
|
||||
})
|
||||
|
||||
test("#when output was already observed from events #then it completes without fetching messages", async () => {
|
||||
//#given
|
||||
let messagesCallCount = 0
|
||||
const manager = createManagerWithClient({
|
||||
status: async () => ({ data: { "ses-idle-cached": { type: "idle" } } }),
|
||||
messages: async () => {
|
||||
messagesCallCount += 1
|
||||
return {
|
||||
data: [{
|
||||
info: { role: "assistant", finish: "end_turn", id: "msg-2" },
|
||||
parts: [{ type: "text", text: "done" }],
|
||||
}],
|
||||
}
|
||||
},
|
||||
})
|
||||
const task = createRunningTask("ses-idle-cached")
|
||||
injectTask(manager, task)
|
||||
|
||||
manager.handleEvent({
|
||||
type: "message.part.updated",
|
||||
properties: { sessionID: "ses-idle-cached", type: "text" },
|
||||
})
|
||||
|
||||
//#when
|
||||
const poll = (manager as unknown as { pollRunningTasks: () => Promise<void> }).pollRunningTasks
|
||||
await poll.call(manager)
|
||||
manager.shutdown()
|
||||
|
||||
//#then
|
||||
expect(task.status).toBe("completed")
|
||||
expect(messagesCallCount).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given a running task whose session status is busy", () => {
|
||||
|
||||
Reference in New Issue
Block a user