Skip to content

Commit 8e611c9

Browse files
committed
fix(core): count image jobs as background work for idle hooks
1 parent ef757c4 commit 8e611c9

4 files changed

Lines changed: 37 additions & 20 deletions

File tree

‎packages/core/src/plugin/goal.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ export const Plugin = define({
145145
if (goal?.status !== "active") return
146146
if (goal.boot !== boot())
147147
return yield* settle(sessionID, goal, "paused", "The server restarted while the goal was active")
148-
// The Session's own running subagent wakes it with its report, and the hook runs again then. A grandchild reports
149-
// to its own parent, so it would never wake this Session.
150-
if (background.some((work) => work.kind === "subagent" && work.sessionID === sessionID)) return
148+
// The Session's own running subagent or image job wakes it with its notice, and the hook runs again then. A
149+
// grandchild reports to its own parent, so it would never wake this Session.
150+
if (
151+
background.some((work) => (work.kind === "subagent" || work.kind === "image") && work.sessionID === sessionID)
152+
)
153+
return
151154
if (goal.rounds >= goal.maxRounds)
152155
return yield* settle(sessionID, goal, "paused", `Reached the limit of ${goal.maxRounds} rounds`)
153156

‎packages/core/src/session/background.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ export const outstanding = Effect.fnUntraced(function* (
1616
sessionID: SessionSchema.ID,
1717
) {
1818
const owned = yield* Effect.filter(yield* jobs.runningBackground, (recovery) =>
19-
descends(store, recovery.kind === "shell" ? recovery.sessionID : recovery.parentSessionID, sessionID),
20-
)
21-
return owned.map((recovery) =>
22-
recovery.kind === "shell"
23-
? {
24-
kind: "shell" as const,
25-
sessionID: recovery.sessionID,
26-
shellID: recovery.shellID,
27-
command: recovery.command,
28-
}
29-
: {
30-
kind: "subagent" as const,
31-
sessionID: recovery.parentSessionID,
32-
childSessionID: recovery.childSessionID,
33-
agent: recovery.agent,
34-
description: recovery.description,
35-
},
19+
descends(store, recovery.kind === "subagent" ? recovery.parentSessionID : recovery.sessionID, sessionID),
3620
)
21+
return owned.map((recovery) => {
22+
if (recovery.kind === "shell")
23+
return {
24+
kind: "shell" as const,
25+
sessionID: recovery.sessionID,
26+
shellID: recovery.shellID,
27+
command: recovery.command,
28+
}
29+
if (recovery.kind === "image")
30+
return { kind: "image" as const, sessionID: recovery.sessionID, path: recovery.path, model: recovery.model }
31+
return {
32+
kind: "subagent" as const,
33+
sessionID: recovery.parentSessionID,
34+
childSessionID: recovery.childSessionID,
35+
agent: recovery.agent,
36+
description: recovery.description,
37+
}
38+
})
3739
})
3840

3941
const descends = Effect.fnUntraced(function* (

‎packages/plugin/src/effect/session.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ export type SessionIdleBackground =
154154
readonly agent: string
155155
readonly description: string
156156
}
157+
| {
158+
readonly kind: "image"
159+
readonly sessionID: Session.ID
160+
readonly path: string
161+
readonly model: string
162+
}
157163

158164
/**
159165
* Runs when a Session finishes model work and has no pending input, just before it goes idle.

‎packages/plugin/src/promise/session.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ export type SessionIdleBackground =
154154
readonly agent: string
155155
readonly description: string
156156
}
157+
| {
158+
readonly kind: "image"
159+
readonly sessionID: Session.ID
160+
readonly path: string
161+
readonly model: string
162+
}
157163

158164
/**
159165
* Runs when a Session finishes model work and has no pending input, just before it goes idle.

0 commit comments

Comments
 (0)