From 1b090664a198cb6b0c7707cbe13aaa72c8c939c2 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 4 Nov 2026 18:22:44 -0800 Subject: [PATCH] fix(core): release the nearest held ancestor through a silent subagent chain --- .../src/session/execution/subagent-report.ts | 12 +++++-- packages/core/test/subagent-lifetime.test.ts | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/core/src/session/execution/subagent-report.ts b/packages/core/src/session/execution/subagent-report.ts index dfbd742739e..f4971921db5 100644 --- a/packages/core/src/session/execution/subagent-report.ts +++ b/packages/core/src/session/execution/subagent-report.ts @@ -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 diff --git a/packages/core/test/subagent-lifetime.test.ts b/packages/core/test/subagent-lifetime.test.ts index d061fdf0eb3..9f0f0c836f5 100644 --- a/packages/core/test/subagent-lifetime.test.ts +++ b/packages/core/test/subagent-lifetime.test.ts @@ -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