fix(core): release the nearest held ancestor through a silent subagent chain

This commit is contained in:
Kit Langton
2026-11-04 18:22:44 -08:00
Unverified
parent 3607880396
commit 1b090664a1
2 changed files with 40 additions and 3 deletions
@@ -96,9 +96,15 @@ export const make = (deps: Deps) => {
if (!child?.parentID) return
const parentID = child.parentID
if (!SubagentMetadata.notify(child.metadata)) {
// A silent descendant sends no notice, so wake a held parent to report its final state. The
// wake runs no model step when the parent has no input.
if (held.has(parentID) && (yield* deps.store.get(parentID))) yield* deps.wake(parentID)
// A silent descendant sends no notice, so wake the nearest held ancestor to report its final
// state; silent sessions between them never hold. The wake runs no model step without input.
const seen = new Set([child.id])
let ancestor = yield* deps.store.get(parentID)
while (ancestor && !held.has(ancestor.id) && !seen.has(ancestor.id)) {
seen.add(ancestor.id)
ancestor = ancestor.parentID ? yield* deps.store.get(ancestor.parentID) : undefined
}
if (ancestor && held.has(ancestor.id)) yield* deps.wake(ancestor.id)
return
}
if (!(yield* deps.store.get(parentID))) return
@@ -446,6 +446,37 @@ describe("subagent observer lifetime", () => {
}),
)
it.live("a silent chain releases the nearest held ancestor's report", () =>
Effect.gen(function* () {
const jobs = yield* Job.Service
const llm = yield* TestLLM.Test
const f = yield* family({ "subagent.notify": false })
const grandchild = yield* f.sessions.create({
parentID: f.descendant.id,
agent: Agent.ID.make("reviewer"),
metadata: { "subagent.notify": false },
})
const exitShell = yield* backgroundShell(grandchild.id)
yield* llm.push(TestLLM.text("first", "first"), TestLLM.text("grandchild done", "grandchild"))
expect((yield* f.spawn).status).toBe("completed")
yield* llm.wait(1).pipe(Effect.timeout("2 seconds"))
yield* f.sessions.wait(f.child.id)
expect(yield* reports(f.parent.id)).toEqual([])
// The silent descendant between them never held, so the grandchild must wake the child.
yield* exitShell
yield* jobs.wait({ id: f.child.id }).pipe(Effect.timeout("5 seconds"))
yield* llm.wait(3).pipe(Effect.timeout("2 seconds"))
yield* f.sessions.wait(f.parent.id)
const notices = yield* reports(f.parent.id)
expect(notices).toHaveLength(1)
expect(notices[0]).toMatchObject({ metadata: { source: "subagent", childID: f.child.id, state: "completed" } })
expect(notices[0]?.text).toContain("first")
expect(yield* llm.requests()).toHaveLength(3)
}),
)
it.live("a no-input wake after a child reported sends no second report", () =>
Effect.gen(function* () {
const execution = yield* SessionExecution.Service