fix(core): tag subagent reports with pending background work as running (#63675)

This commit is contained in:
Aiden Cline
2026-11-13 00:51:04 -06:00
committed by GitHub
Unverified
parent b81c5f3465
commit 91dccad1eb
4 changed files with 21 additions and 8 deletions
@@ -34,6 +34,8 @@ export function text(message: SessionMessage.Info | undefined) {
const clean = (value: string) => value.replace(/\s+/g, " ").trim()
const STILL_RUNNING = "\n\nBackground work still running:\n"
export function formatBody(
body: string,
childSessionID: SessionSchema.ID,
@@ -47,7 +49,7 @@ export function formatBody(
return `- image (${item.model}${item.sessionID !== childSessionID ? `, in ${item.sessionID}` : ""}): ${item.path}`
return `- subagent (${item.agent}, sessionID: ${item.childSessionID}): ${clean(item.description)}`
})
return `${body}\n\nBackground work still running:\n${lines.join("\n")}`
return `${body}${STILL_RUNNING}${lines.join("\n")}`
}
export const deliver = Effect.fnUntraced(function* <E>(
@@ -65,11 +67,14 @@ export const deliver = Effect.fnUntraced(function* <E>(
: input.status === "error"
? (input.error ?? "Subagent failed")
: (input.output ?? input.error ?? "Subagent cancelled")
// The body is all a recovered outbox row keeps, so the still-running list is how a replay tells this period apart.
// Only the model-facing tag says "running": the job and the message metadata keep the period's real status.
const state = input.status === "completed" && body.includes(STILL_RUNNING) ? "running" : input.status
yield* sessions.synthetic({
...(input.notificationID ? { id: input.notificationID } : {}),
sessionID: recovery.parentSessionID,
description: recovery.description,
text: `<subagent sessionID="${recovery.childSessionID}" state="${input.status}" description="${recovery.description}">\n${body}\n</subagent>`,
text: `<subagent sessionID="${recovery.childSessionID}" state="${state}" description="${recovery.description}">\n${body}\n</subagent>`,
metadata: { source: "subagent", childID: recovery.childSessionID, agent: recovery.agent, state: input.status },
})
if (input.notificationID) yield* jobs.completeBackground(input.notificationID)
+2 -2
View File
@@ -1495,13 +1495,13 @@ describe("SessionRestart background recovery", () => {
yield* Context.get(context, SessionRestart.Service).resumeSuspendedSessions
yield* Deferred.await(parentWoken)
// Replay delivers the formatted row verbatim; the completed child never runs again.
// Replay delivers the formatted row verbatim, its still-running list labelling the tag; the child never runs again.
expect(drained).toEqual([parent])
expect(yield* SessionInbox.list(database.db, parent)).toMatchObject([
{
type: "synthetic",
payload: {
text: `<subagent sessionID="${child}" state="completed" description="Outbox inspection">\n${output}\n</subagent>`,
text: `<subagent sessionID="${child}" state="running" description="Outbox inspection">\n${output}\n</subagent>`,
metadata: { source: "subagent", childID: child, agent: "explore", state: "completed" },
},
},
+10 -3
View File
@@ -59,7 +59,7 @@ describe("SubagentCompletion", () => {
}),
)
it.effect("delivers completed, failed, and cancelled reports with pending background work", () =>
it.effect("labels a completed report with pending background work as running, only in the model text", () =>
Effect.gen(function* () {
const notificationID = SessionMessage.ID.create()
const sent: SyntheticInput[] = []
@@ -88,11 +88,12 @@ describe("SubagentCompletion", () => {
yield* SubagentCompletion.deliver(sessions, jobs, { status: "cancelled", recovery })
// A running job has nothing to report and must not be acknowledged.
yield* SubagentCompletion.deliver(sessions, jobs, { status: "running", recovery })
yield* SubagentCompletion.deliver(sessions, jobs, { status: "completed", output: "All done", recovery })
expect(sent).toHaveLength(3)
expect(sent).toHaveLength(4)
expect(sent[0]?.text).toBe(
[
'<subagent sessionID="ses_deliver_child" state="completed" description="Deliver report">',
'<subagent sessionID="ses_deliver_child" state="running" description="Deliver report">',
"All green",
"",
"Background work still running:",
@@ -100,6 +101,12 @@ describe("SubagentCompletion", () => {
"</subagent>",
].join("\n"),
)
expect(sent[0]?.metadata?.state).toBe("completed")
expect(sent[3]?.text).toBe(
['<subagent sessionID="ses_deliver_child" state="completed" description="Deliver report">', "All done", "</subagent>"].join(
"\n",
),
)
expect(sent[1]?.text).toBe(
[
'<subagent sessionID="ses_deliver_child" state="error" description="Deliver report">',
+2 -1
View File
@@ -153,7 +153,7 @@ describe("SubagentReport settlement", () => {
{
payload: {
text: [
`<subagent sessionID="${child}" state="completed" description="Background audit">`,
`<subagent sessionID="${child}" state="running" description="Background audit">`,
"Started tests",
"",
"Background work still running:",
@@ -162,6 +162,7 @@ describe("SubagentReport settlement", () => {
`- subagent (subagent, sessionID: ${active}): ${active}`,
"</subagent>",
].join("\n"),
metadata: { state: "completed" },
},
},
])