Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions dist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ class TaskTracker {
}
async refreshLiveChildren(client, parentSessionID) {
const session = client.session;
if (!session.children || !session.status)
if (!session.children)
return;
let childIDs;
try {
Expand All @@ -1154,7 +1154,8 @@ class TaskTracker {
} catch {
return;
}
if (childIDs.length === 0)
this.markAbsentRunningChildren(parentSessionID, new Set(childIDs));
if (childIDs.length === 0 || !session.status)
return;
let statuses;
try {
Expand Down Expand Up @@ -1240,6 +1241,16 @@ class TaskTracker {
continue;
this.snapshotIdleHolds.delete(key);
this.settledSnapshotIdleTasks.add(key);
const task = this.tasks.get(hold.taskID);
if (task?.parentSessionID === hold.parentSessionID && task.state === "running")
this.tasks.delete(hold.taskID);
}
}
markAbsentRunningChildren(parentSessionID, liveChildIDs) {
for (const task of this.tasks.values()) {
if (task.parentSessionID !== parentSessionID || task.state !== "running" || liveChildIDs.has(task.taskID))
continue;
this.markSnapshotIdle(parentSessionID, task.taskID);
}
}
snapshotIdleKey(parentSessionID, taskID) {
Expand Down Expand Up @@ -1364,6 +1375,8 @@ var server = async ({ client }, options) => {
await pauseGoalForPlanMode(sessionID);
return;
}
if (busySessions.has(sessionID))
return;
if (!fromTaskDeferral && taskDeferredSessions.has(sessionID)) {
scheduleSettledContinuation(sessionID);
return;
Expand Down
15 changes: 13 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class TaskTracker {
children?: (input: { path: { id: string } }) => Promise<{ data?: unknown } | unknown[]>
status?: () => Promise<{ data?: unknown } | Record<string, unknown>>
}
if (!session.children || !session.status) return
if (!session.children) return
let childIDs: string[]
try {
const result = await session.children({ path: { id: parentSessionID } })
Expand All @@ -447,7 +447,8 @@ class TaskTracker {
} catch {
return
}
if (childIDs.length === 0) return
this.markAbsentRunningChildren(parentSessionID, new Set(childIDs))
if (childIDs.length === 0 || !session.status) return
let statuses: Record<string, unknown>
try {
const result = await session.status()
Expand Down Expand Up @@ -540,6 +541,15 @@ class TaskTracker {
if (hold.expiresAt > now) continue
this.snapshotIdleHolds.delete(key)
this.settledSnapshotIdleTasks.add(key)
const task = this.tasks.get(hold.taskID)
if (task?.parentSessionID === hold.parentSessionID && task.state === "running") this.tasks.delete(hold.taskID)
}
}

private markAbsentRunningChildren(parentSessionID: string, liveChildIDs: Set<string>) {
for (const task of this.tasks.values()) {
if (task.parentSessionID !== parentSessionID || task.state !== "running" || liveChildIDs.has(task.taskID)) continue
this.markSnapshotIdle(parentSessionID, task.taskID)
}
}

Expand Down Expand Up @@ -662,6 +672,7 @@ const server: Plugin = async ({ client }, options?: Options) => {
if (current.status === "active") await pauseGoalForPlanMode(sessionID)
return
}
if (busySessions.has(sessionID)) return
if (!fromTaskDeferral && taskDeferredSessions.has(sessionID)) {
scheduleSettledContinuation(sessionID)
return
Expand Down
32 changes: 32 additions & 0 deletions test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,38 @@ test("idle live child bounded retry does not inject while parent session is busy
expect(JSON.stringify(calls[0])).toContain("Continue working toward the active session goal")
})

test("tracked running child absent from live children stops blocking after grace period", async () => {
const calls: unknown[] = []
let children = [{ id: "task_1" }]
const hooks = await plugin.server(
{
client: {
session: {
children: async () => ({ data: children }),
status: async () => ({ data: { task_1: { type: "busy" } } }),
promptAsync: async (input: unknown) => {
calls.push(input)
},
},
},
} as never,
{ auto_continue: true, max_auto_turns: 1, min_continue_interval_seconds: 0 },
)
const tools = hooks.tool
if (!tools) throw new Error("expected goal tools to be registered")

await requireTool(tools.create_goal, "create_goal").execute({ objective: "keep going" }, { sessionID: "ses_1" } as never)
await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_1" } } as never })
expect(calls).toHaveLength(0)

children = []
await hooks.event!({ event: { type: "session.idle", properties: { sessionID: "ses_1" } } as never })

expect(calls).toHaveLength(0)
await waitForContinuation(calls)
expect(JSON.stringify(calls[0])).toContain("Continue working toward the active session goal")
})

test("task deferral can be disabled with config", async () => {
const calls: unknown[] = []
const hooks = await plugin.server(
Expand Down