fix(background-agent): use session.status() API for idle detection
session.get() doesn't return status field - it was always undefined.
Now using session.status() API which returns { type: 'idle' | 'busy' | 'retry' }
🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -265,31 +265,28 @@ Use \`background_result\` tool with taskId="${task.id}" to retrieve the full res
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async pollRunningTasks(): Promise<void> {
|
private async pollRunningTasks(): Promise<void> {
|
||||||
|
const statusResult = await this.client.session.status()
|
||||||
|
const allStatuses = (statusResult.data ?? {}) as Record<string, { type: string }>
|
||||||
|
|
||||||
for (const task of this.tasks.values()) {
|
for (const task of this.tasks.values()) {
|
||||||
if (task.status !== "running") continue
|
if (task.status !== "running") continue
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const infoResult = await this.client.session.get({
|
const sessionStatus = allStatuses[task.sessionID]
|
||||||
path: { id: task.sessionID },
|
|
||||||
})
|
if (!sessionStatus) {
|
||||||
|
task.status = "error"
|
||||||
if (infoResult.error) {
|
task.error = "Session not found"
|
||||||
const errorStr = String(infoResult.error)
|
task.completedAt = new Date()
|
||||||
if (errorStr.includes("404") || errorStr.includes("not found")) {
|
|
||||||
task.status = "error"
|
|
||||||
task.error = "Session not found"
|
|
||||||
task.completedAt = new Date()
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionInfo = infoResult.data as { status?: string }
|
if (sessionStatus.type === "idle") {
|
||||||
|
|
||||||
if (sessionInfo.status === "idle") {
|
|
||||||
task.status = "completed"
|
task.status = "completed"
|
||||||
task.completedAt = new Date()
|
task.completedAt = new Date()
|
||||||
this.markForNotification(task)
|
this.markForNotification(task)
|
||||||
this.notifyParentSession(task)
|
this.notifyParentSession(task)
|
||||||
|
log("[background-agent] Task completed, notifying parent:", task.id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user