refactor(core): remove the subagent notify option (#63413)

This commit is contained in:
James Long
2026-11-11 17:44:14 -06:00
committed by GitHub
Unverified
parent 63dd3f1c6c
commit 6d023043ca
13 changed files with 16 additions and 528 deletions
+1 -4
View File
@@ -29,7 +29,6 @@ import path from "path"
import { SessionRunner } from "./session/runner/index.js"
import { SessionStore } from "./session/store.js"
import { SessionExecution } from "./session/execution.js"
import { SubagentMetadata } from "./session/subagent-metadata.js"
import {
AttachmentError,
BusyError,
@@ -313,9 +312,7 @@ const layer = Layer.effect(
agent: input.agent,
// Children inherit metadata and permissions the way they inherit
// location, so host policies that read them treat the family uniformly.
// The per-link subagent switch is not host metadata, though: a silent
// child must not silence the sessions created beneath it.
metadata: input.metadata ?? SubagentMetadata.inherit(parent?.metadata),
metadata: input.metadata ?? parent?.metadata,
permissions: input.permissions ?? parent?.permissions,
model: input.model,
},
+1 -12
View File
@@ -20,7 +20,6 @@ import { ImageNotice } from "../../image/notice.js"
import { ShellResult } from "../../shell/result.js"
import { SubagentCompletion } from "../subagent-completion.js"
import { SubagentJob } from "../subagent-job.js"
import { SubagentMetadata } from "../subagent-metadata.js"
const CONTINUE_AFTER_SERVER_RESTART =
"The server restarted while you were working. Continue from where you left off without repeating completed work."
@@ -338,15 +337,9 @@ export const layer = (options?: Options) =>
yield* jobs.completeBackground(background.notificationID)
return false
}
const silent = !SubagentMetadata.notify(child.metadata)
if (background.status !== "running") {
// The outbox row already holds the formatted result; replay it without touching
// the child. A silent link owes no report, so only the marker needs clearing.
if (silent) {
yield* jobs.completeBackground(background.notificationID)
return false
}
// The outbox row already holds the formatted result; replay it without touching the child.
yield* deliverSubagentSafe(notices, background.notificationID, recovery, background)
return false
}
@@ -355,10 +348,6 @@ export const layer = (options?: Options) =>
// prepareResume publishes Execution.Failed directly on the bus outside the
// coordinator, so the settle hook never reports an exhausted child.
if (!(yield* prepareResume(recovery.childSessionID))) {
if (silent) {
yield* jobs.completeBackground(background.notificationID)
return false
}
yield* deliverSubagentSafe(notices, background.notificationID, recovery, {
status: "error",
error: RESUME_EXHAUSTED.message,
@@ -8,7 +8,6 @@ import { SessionMessage } from "../message.js"
import type { SessionSchema } from "../schema.js"
import type { SessionStore } from "../store.js"
import { SubagentCompletion } from "../subagent-completion.js"
import { SubagentMetadata } from "../subagent-metadata.js"
export type Outcome =
| { readonly type: "succeeded" }
@@ -156,7 +155,7 @@ export const make = (deps: Deps) => {
yield* deps.store.release(sessionID)
const child = yield* deps.store.get(sessionID)
const parent = child?.parentID ? yield* deps.store.get(child.parentID) : undefined
if (!child?.parentID || !SubagentMetadata.notify(child.metadata) || !parent) {
if (!child?.parentID || !parent) {
if (jobState.mode === "background") {
yield* deps.jobs.deleteBackgroundRow(jobState.notificationID)
box.postCommit = { type: "cleanup", notificationID: jobState.notificationID }
+1 -2
View File
@@ -19,7 +19,6 @@ import { SessionBlob } from "./blob.js"
import { SessionInboxTable, SessionMessageTable, SessionPartTable, SessionTable, type SessionPartData } from "./sql.js"
import { SessionStored } from "./stored.js"
import { InstructionEntry } from "./instruction-entry.js"
import { SubagentMetadata } from "./subagent-metadata.js"
import type { SQLiteUpdateSetSource } from "drizzle-orm/sqlite-core/query-builders/update"
import { Slug } from "../util/slug.js"
import { FSUtil } from "@opencode/util/fs-util"
@@ -175,7 +174,7 @@ const projectFork = Effect.fn("SessionProjector.projectFork")(function* (
title: forkTitle(parent.title ?? undefined),
agent: parent.agent,
model: parent.model,
metadata: SubagentMetadata.inherit(parent.metadata ?? undefined) ?? null,
metadata: parent.metadata,
permission: parent.permission,
version: parent.version,
cost: 0,
@@ -1,52 +0,0 @@
export * as SubagentMetadata from "./subagent-metadata.js"
import type { SessionSchema } from "./schema.js"
/** Per-link switch for reporting a subagent's idle transition to its parent. */
export const KEY = "subagent.notify"
/** Absence means loud: only an explicit `false` silences the link. */
export function notify(metadata: SessionSchema.Metadata | undefined): boolean {
return metadata?.[KEY] !== false
}
/**
* Strips the per-link switch when metadata moves to a child or fork. Host
* annotations belong to the family, but a silent link must not silence the
* sessions created beneath it.
*/
export function inherit(metadata: SessionSchema.Metadata | undefined): SessionSchema.Metadata | undefined {
if (metadata === undefined || !Object.hasOwn(metadata, KEY)) return metadata
const { [KEY]: _notify, ...rest } = metadata
return Object.keys(rest).length === 0 ? undefined : rest
}
/** Writes the switch, keeping default-loud sessions free of redundant keys. */
export function apply(
metadata: SessionSchema.Metadata | undefined,
value: boolean,
): SessionSchema.Metadata | undefined {
if (value === false) return { ...metadata, [KEY]: false }
return inherit(metadata)
}
/** Metadata for a child created from `metadata` with the requested link state. */
export function withNotify(
metadata: SessionSchema.Metadata | undefined,
value: boolean,
): SessionSchema.Metadata | undefined {
return apply(inherit(metadata), value)
}
/**
* Metadata to persist with `sessions.setMetadata` on an existing session.
* `undefined` means the requested state already holds, so the caller can skip
* the write; `{}` clears the last key.
*/
export function update(
metadata: SessionSchema.Metadata | undefined,
value: boolean,
): SessionSchema.Metadata | undefined {
if (notify(metadata) === value) return undefined
return apply(metadata, value) ?? {}
}
+8 -22
View File
@@ -12,21 +12,18 @@ import { Permission } from "../../permission.js"
import { Session } from "../../session.js"
import { SessionSchema } from "../../session/schema.js"
import { SubagentJob } from "../../session/subagent-job.js"
import { SubagentMetadata } from "../../session/subagent-metadata.js"
export const name = "subagent"
const backgroundResult = (sessionID: SessionSchema.ID, notify: boolean) => ({
const backgroundResult = (sessionID: SessionSchema.ID) => ({
sessionID,
status: "running" as const,
output: notify
? [
`The subagent is working in the background (sessionID: ${sessionID}). You will receive a <subagent> message when it goes idle, and again after each later round of work.`,
"DO NOT sleep, poll for progress, ask the subagent for status, or duplicate this subagent's work; avoid working with the same files or topics it is using.",
"Work on non-overlapping tasks, or briefly tell the user what you launched and end your response.",
"To send it follow-ups or change its instructions while it runs, call subagent again with this sessionID.",
].join("\n")
: `The subagent is working in the background (sessionID: ${sessionID}) and will not notify you when it finishes, so you won't receive its result. Only use notify=false for work whose result you don't need. To send it more work, call subagent again with this sessionID.`,
output: [
`The subagent is working in the background (sessionID: ${sessionID}). You will receive a <subagent> message when it goes idle, and again after each later round of work.`,
"DO NOT sleep, poll for progress, ask the subagent for status, or duplicate this subagent's work; avoid working with the same files or topics it is using.",
"Work on non-overlapping tasks, or briefly tell the user what you launched and end your response.",
"To send it follow-ups or change its instructions while it runs, call subagent again with this sessionID.",
].join("\n"),
})
export const Input = Schema.Struct({
@@ -43,10 +40,6 @@ export const Input = Schema.Struct({
sessionID: Schema.optionalKey(SessionSchema.ID).annotate({
description: "Send a follow-up to an existing subagent, running or finished. Omit to start a new one.",
}),
notify: Schema.optionalKey(Schema.Boolean).annotate({
description:
"Send you a `<subagent>` message each time this subagent goes idle. Defaults to true for new subagents. On follow-ups (sessionID), keeps the subagent's current setting unless you pass it.",
}),
})
export const Output = Schema.Struct({
@@ -60,7 +53,6 @@ export const description = [
"Keep working on non-overlapping tasks, or briefly tell the user what you launched and end your response. Do not sleep, poll for progress, or ask the child for status.",
"New child sessions start with fresh context, so include all relevant context and instructions when you don't pass a sessionID.",
"Pass the returned sessionID to continue that specific child conversation. A follow-up to a running child joins its current run.",
"Pass notify=false for a new subagent only if you don't need its results: you won't receive its idle reports.",
].join("\n")
export const Plugin = {
@@ -173,13 +165,9 @@ export const Plugin = {
if (existing !== undefined) {
const switched = existing.agent !== agent.id
const model = override ?? (switched ? agent.model : undefined)
// Omitted notify keeps the child's current link state; only an explicit value writes.
const metadata =
input.notify === undefined ? undefined : SubagentMetadata.update(existing.metadata, input.notify)
yield* Effect.all([
switched ? sessions.switchAgent({ sessionID: existing.id, agent: agent.id }) : Effect.void,
model === undefined ? Effect.void : sessions.switchModel({ sessionID: existing.id, model }),
metadata === undefined ? Effect.void : sessions.setMetadata({ sessionID: existing.id, metadata }),
]).pipe(
Effect.mapError(
(error) => new ToolFailure({ message: `Failed to switch subagent session: ${existing.id}`, error }),
@@ -196,7 +184,6 @@ export const Plugin = {
title: input.description,
agent: agent.id,
model,
metadata: SubagentMetadata.withNotify(parent.metadata, input.notify !== false),
})
.pipe(
Effect.mapError(
@@ -204,7 +191,6 @@ export const Plugin = {
),
))
const notify = input.notify ?? SubagentMetadata.notify(child.metadata)
// A child that is not draining yet must be admitted without waking: the job's resume
// owns the start, so the period cannot run before its boundary is registered.
const running =
@@ -235,7 +221,7 @@ export const Plugin = {
description: input.description,
}
yield* subagents.start(recovery)
return backgroundResult(child.id, notify)
return backgroundResult(child.id)
}).pipe(
Effect.map((output) => ({
output,
-37
View File
@@ -31,7 +31,6 @@ import { InstructionEntry } from "@opencode/core/session/instruction-entry"
import { SessionEvent } from "@opencode/core/session/event"
import { SessionTable } from "@opencode/core/session/sql"
import { SessionStore } from "@opencode/core/session/store"
import { SubagentMetadata } from "@opencode/core/session/subagent-metadata"
import { SessionTransfer } from "@opencode/core/session/transfer"
import { Workspace } from "@opencode/core/workspace"
import { Expected } from "./lib/session-message"
@@ -475,42 +474,6 @@ describe("Session.create", () => {
}),
)
it.effect("does not inherit the per-link subagent notify switch through children", () =>
Effect.gen(function* () {
const session = yield* Session.Service
const parent = yield* session.create({
location,
metadata: { threadID: "t1", "subagent.notify": false },
})
const child = yield* session.create({ parentID: parent.id })
expect(child.metadata).toEqual({ threadID: "t1" })
expect(SubagentMetadata.notify(child.metadata)).toBe(true)
const silent = yield* session.create({ parentID: parent.id, metadata: { "subagent.notify": false } })
expect(silent.metadata).toEqual({ "subagent.notify": false })
expect(SubagentMetadata.notify(silent.metadata)).toBe(false)
}),
)
it.effect("strips the per-link subagent notify switch when forking", () =>
Effect.gen(function* () {
const session = yield* Session.Service
const bus = yield* Bus.Service
const { db } = yield* Database.Service
const parent = yield* session.create({
location,
metadata: { threadID: "t1", "subagent.notify": false },
})
yield* session.prompt({ sessionID: parent.id, text: "Fork context", resume: false })
yield* SessionInbox.promote(db, bus, parent.id, "steer")
const forked = yield* session.fork({ sessionID: parent.id })
expect(forked.metadata).toEqual({ threadID: "t1" })
expect(SubagentMetadata.notify(forked.metadata)).toBe(true)
}),
)
it.effect("stores permission rules, inherits them through children and forks, and replaces them", () =>
Effect.gen(function* () {
const session = yield* Session.Service
+1 -121
View File
@@ -1709,124 +1709,6 @@ describe("SessionRestart background recovery", () => {
}),
)
it.effect("clears an exhausted silent subagent without notifying its parent", () =>
Effect.gen(function* () {
const database = yield* Database.Service
const jobs = yield* Job.Service
const parent = Session.ID.make("ses_silent_exhausted_parent")
const child = Session.ID.make("ses_silent_exhausted_child")
yield* seedSessions(database, [parent])
yield* seedSessions(database, [child], {
parent_id: parent,
time_suspended: Date.now(),
resume_attempts: 2,
metadata: { "subagent.notify": false },
})
yield* jobs.start({
id: child,
type: "subagent",
recovery: {
kind: "subagent",
parentSessionID: parent,
childSessionID: child,
agent: "explore",
description: "Silent exhausted inspection",
},
run: Effect.never,
})
yield* jobs.background(child)
const drained: Session.ID[] = []
const scope = yield* Scope.make()
yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void))
const restarted = yield* Job.make.pipe(Effect.provideService(Scope.Scope, scope))
const context = yield* buildExecution(
scope,
({ sessionID }) => Effect.sync(() => void drained.push(sessionID)),
{ maxAttempts: 2 },
restarted,
)
yield* Context.get(context, SessionRestart.Service).resumeSuspendedSessions
expect(drained).toEqual([])
expect((yield* claims(database))[child]).toBe(false)
expect(yield* SessionInbox.list(database.db, parent)).toEqual([])
expect(yield* restarted.pendingBackground).toEqual([])
}),
)
it.effect("keeps a silent subagent quiet across restart for both finished and running rows", () =>
Effect.gen(function* () {
const database = yield* Database.Service
const jobs = yield* Job.Service
const store = yield* SessionStore.Service
const parent = Session.ID.make("ses_silent_recovery_parent")
const finished = Session.ID.make("ses_silent_recovery_finished")
const running = Session.ID.make("ses_silent_recovery_running")
const metadata = { "subagent.notify": false }
yield* seedSessions(database, [parent])
yield* seedSessions(database, [finished], { parent_id: parent, metadata })
yield* seedSessions(database, [running], { parent_id: parent, metadata, time_suspended: Date.now() })
const recovery = (child: Session.ID, description: string) => ({
kind: "subagent" as const,
parentSessionID: parent,
childSessionID: child,
agent: "explore",
description,
})
yield* jobs.start({
id: finished,
type: "subagent",
recovery: recovery(finished, "Silent finished inspection"),
background: true,
run: Effect.succeed("Silent result"),
})
yield* jobs.wait({ id: finished })
yield* jobs.start({
id: running,
type: "subagent",
recovery: recovery(running, "Silent running inspection"),
background: true,
run: Effect.never,
})
const resumed = yield* Deferred.make<void>()
const release = yield* Deferred.make<void>()
const drained: Session.ID[] = []
const scope = yield* Scope.make()
yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void))
const restarted = yield* Job.make.pipe(Effect.provideService(Scope.Scope, scope))
const context = yield* buildExecution(
scope,
({ sessionID }) =>
Effect.sync(() => void drained.push(sessionID)).pipe(
Effect.andThen(
sessionID === running
? Deferred.succeed(resumed, undefined).pipe(Effect.andThen(Deferred.await(release)))
: Effect.void,
),
),
undefined,
restarted,
)
const execution = Context.get(context, SessionExecution.Service)
yield* Context.get(context, SessionRestart.Service).resumeSuspendedSessions
yield* Deferred.await(resumed)
// The finished row is acknowledged at inspection; only the still-running row remains.
expect(drained).toEqual([running])
expect(yield* restarted.pendingBackground).toMatchObject([{ id: running, status: "running" }])
expect(yield* SessionInbox.list(database.db, parent)).toEqual([])
yield* Deferred.succeed(release, undefined)
yield* execution.awaitIdle(running)
expect(yield* restarted.pendingBackground).toEqual([])
expect(yield* SessionInbox.list(database.db, parent)).toEqual([])
expect((yield* store.context(parent)).filter((message) => message.type === "synthetic")).toEqual([])
expect(yield* claims(database)).toEqual({ [parent]: false, [finished]: false, [running]: false })
}),
)
it.effect("charges a suspended parent's restart attempt before a fast child can wake it", () =>
Effect.gen(function* () {
const database = yield* Database.Service
@@ -2092,9 +1974,7 @@ function seedInbox(
function seedSessions(
database: Database.Service["Service"],
sessionIDs: ReadonlyArray<Session.ID>,
values: Partial<
Pick<typeof SessionTable.$inferInsert, "time_suspended" | "resume_attempts" | "parent_id" | "metadata">
> = {},
values: Partial<Pick<typeof SessionTable.$inferInsert, "time_suspended" | "resume_attempts" | "parent_id">> = {},
) {
return Effect.gen(function* () {
yield* database.db
@@ -267,13 +267,6 @@ const harness = Effect.fnUntraced(function* (input?: HarnessInput) {
const outputSessionID = (value: unknown) =>
Schema.decodeUnknownSync(Schema.Struct({ sessionID: Session.ID }))(value).sessionID
const messageText = (message: SessionMessage.Info) =>
message.type === "assistant"
? message.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("\n\n")
: message.type === "synthetic"
? message.text
: ""
const deliveredReports = (app: { readonly sessions: Session.Interface }, sessionID: Session.ID) =>
app.sessions
.context(sessionID)
@@ -514,54 +507,6 @@ describe("subagent idle reports end to end", () => {
30_000,
)
e2e.live(
"a silent middle keeps its loud grandchild from skipping a level",
() =>
Effect.gen(function* () {
const h = yield* harness({
config: {
experimental: { subagent_depth: 2 },
permissions: [{ action: "*", resource: "*", effect: "allow" }],
},
})
yield* h.llm.serve(
script({
reviewer: [
TestLLM.toolCall("call-grandchild", SubagentTool.name, {
agent: "fallback",
description: "grandchild review",
prompt: "review the grandchild fixture",
}),
TestLLM.text("silent child launched grandchild", "child-turn-1"),
TestLLM.text("silent child saw grandchild", "child-turn-2"),
],
fallback: [TestLLM.text("grandchild answer", "grandchild-turn-1")],
build: [TestLLM.text("parent ack", "parent-1")],
}),
)
const launched = yield* h.call("call-silent-child", {
notify: false,
description: "silent child review",
})
const childID = outputSessionID(launched.metadata)
expect((yield* h.sessions.get(childID)).metadata).toEqual({ "subagent.notify": false })
yield* waitForReports(h, childID, 1)
const report = (yield* deliveredReports(h, childID))[0]!
const grandchildID = Schema.decodeUnknownSync(Session.ID)(report.metadata?.childID)
expect((yield* h.sessions.get(grandchildID)).metadata).toBeUndefined()
expect((yield* h.sessions.context(childID)).map(messageText)).toContain("silent child saw grandchild")
// The grandchild reported to the silent child, and the silent child never reported up.
expect(yield* deliveredReports(h, h.parent.id)).toEqual([])
expect((yield* h.sessions.inbox(h.parent.id)).filter((item) => item.type === "synthetic")).toEqual([])
expect((yield* h.sessions.get(childID)).metadata).toEqual({ "subagent.notify": false })
expect(yield* h.jobs.pendingBackground).toEqual([])
}),
30_000,
)
e2e.live(
"replays the report committed before a crash without running the child again",
() =>
@@ -1,89 +0,0 @@
import { describe, expect, test } from "bun:test"
import { SubagentMetadata } from "@opencode/core/session/subagent-metadata"
const silent = { [SubagentMetadata.KEY]: false } as const
const silentThread = { threadID: "123", [SubagentMetadata.KEY]: false } as const
const thread = { threadID: "123" } as const
describe("SubagentMetadata.notify", () => {
test("defaults to loud when the switch is absent", () => {
expect(SubagentMetadata.notify(undefined)).toBe(true)
expect(SubagentMetadata.notify({})).toBe(true)
expect(SubagentMetadata.notify(thread)).toBe(true)
expect(SubagentMetadata.notify({ [SubagentMetadata.KEY]: true })).toBe(true)
})
test("only an explicit false silences the link", () => {
expect(SubagentMetadata.notify(silent)).toBe(false)
expect(SubagentMetadata.notify(silentThread)).toBe(false)
})
})
describe("SubagentMetadata.inherit", () => {
test("returns metadata without the switch unchanged", () => {
expect(SubagentMetadata.inherit(undefined)).toBeUndefined()
expect(SubagentMetadata.inherit(thread)).toBe(thread)
})
test("strips the switch and keeps host annotations", () => {
expect(SubagentMetadata.inherit(silentThread)).toEqual({ threadID: "123" })
expect(SubagentMetadata.inherit({ ...thread, [SubagentMetadata.KEY]: true })).toEqual({ threadID: "123" })
})
test("collapses metadata that only carried the switch", () => {
expect(SubagentMetadata.inherit(silent)).toBeUndefined()
})
})
describe("SubagentMetadata.apply", () => {
test("writes an explicit false", () => {
expect(SubagentMetadata.apply(undefined, false)).toEqual({ [SubagentMetadata.KEY]: false })
expect(SubagentMetadata.apply(thread, false)).toEqual({ threadID: "123", [SubagentMetadata.KEY]: false })
})
test("loud stays clean by stripping the switch", () => {
expect(SubagentMetadata.apply(undefined, true)).toBeUndefined()
expect(SubagentMetadata.apply(thread, true)).toEqual({ threadID: "123" })
expect(SubagentMetadata.apply(silent, true)).toBeUndefined()
expect(SubagentMetadata.apply(silentThread, true)).toEqual({ threadID: "123" })
})
})
describe("SubagentMetadata.withNotify", () => {
test("creates loud children from absent or silent parents", () => {
expect(SubagentMetadata.withNotify(undefined, true)).toBeUndefined()
expect(SubagentMetadata.withNotify(thread, true)).toEqual({ threadID: "123" })
expect(SubagentMetadata.withNotify(silent, true)).toBeUndefined()
expect(SubagentMetadata.withNotify(silentThread, true)).toEqual({ threadID: "123" })
})
test("creates silent children without inheriting the parent's switch", () => {
expect(SubagentMetadata.withNotify(undefined, false)).toEqual({ [SubagentMetadata.KEY]: false })
expect(SubagentMetadata.withNotify(thread, false)).toEqual({ threadID: "123", [SubagentMetadata.KEY]: false })
expect(SubagentMetadata.withNotify(silentThread, false)).toEqual({
threadID: "123",
[SubagentMetadata.KEY]: false,
})
})
})
describe("SubagentMetadata.update", () => {
test("skips writes that would not change the link state", () => {
expect(SubagentMetadata.update(undefined, true)).toBeUndefined()
expect(SubagentMetadata.update({}, true)).toBeUndefined()
expect(SubagentMetadata.update(thread, true)).toBeUndefined()
expect(SubagentMetadata.update({ [SubagentMetadata.KEY]: true }, true)).toBeUndefined()
expect(SubagentMetadata.update(silent, false)).toBeUndefined()
expect(SubagentMetadata.update(silentThread, false)).toBeUndefined()
})
test("returns the metadata to persist on a transition", () => {
expect(SubagentMetadata.update(undefined, false)).toEqual({ [SubagentMetadata.KEY]: false })
expect(SubagentMetadata.update(thread, false)).toEqual({ threadID: "123", [SubagentMetadata.KEY]: false })
expect(SubagentMetadata.update(silentThread, true)).toEqual({ threadID: "123" })
})
test("returns an empty object when clearing the last key", () => {
expect(SubagentMetadata.update(silent, true)).toEqual({})
})
})
+1 -47
View File
@@ -431,49 +431,6 @@ describe("SubagentReport settlement", () => {
if (marker) yield* jobs.completeBackground(marker.notificationID)
}),
)
it.effect("suppresses reports for a silent child and clears its background marker", () =>
Effect.gen(function* () {
const database = yield* Database.Service
const jobs = yield* Job.Service
const parent = sessionID("ses_silent_parent")
const child = sessionID("ses_silent_child")
yield* seedSessions(database, [parent])
yield* seedSessions(database, [child], {
parent_id: parent,
metadata: { "subagent.notify": false },
})
const scope = yield* Scope.make()
yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void))
const context = yield* buildExecution(scope, () => Effect.void)
const execution = Context.get(context, SessionExecution.Service)
yield* seedAssistant(database, child, 100, "Silent work")
yield* execution.wake(child)
yield* execution.awaitIdle(child)
expect(yield* SessionInbox.list(database.db, parent)).toEqual([])
const job = yield* jobs.start({
id: child,
type: "subagent",
recovery: {
kind: "subagent",
parentSessionID: parent,
childSessionID: child,
agent: "explore",
description: "Silent job",
},
background: true,
run: execution.resume(child).pipe(Effect.as("")),
})
yield* jobs.wait({ id: job.id })
expect(yield* SessionInbox.list(database.db, parent)).toEqual([])
expect(yield* jobs.pendingBackground).toEqual([])
expect(yield* jobs.backgroundJobs).toEqual([])
expect(yield* jobs.get(child)).toBeUndefined()
}),
)
})
describe("SubagentReport outbox", () => {
@@ -741,10 +698,7 @@ function buildExecution(scope: Scope.Scope, drain: Drain) {
}
type SeedValues = Partial<
Pick<
typeof SessionTable.$inferInsert,
"time_suspended" | "resume_attempts" | "parent_id" | "metadata" | "title" | "revert"
>
Pick<typeof SessionTable.$inferInsert, "time_suspended" | "resume_attempts" | "parent_id" | "title" | "revert">
> & { readonly agent?: string }
function seedSessions(
-82
View File
@@ -31,7 +31,6 @@ import { SessionMessage } from "@opencode/core/session/message"
import { SessionRunnerModel } from "@opencode/core/session/runner/model"
import { SessionStore } from "@opencode/core/session/store"
import { SubagentJob } from "@opencode/core/session/subagent-job"
import { SubagentMetadata } from "@opencode/core/session/subagent-metadata"
import { Plugin } from "@opencode/core/plugin"
import { PluginHooks } from "@opencode/core/plugin/hooks"
import { PluginSupervisor } from "@opencode/core/plugin/supervisor"
@@ -989,87 +988,6 @@ describe("SubagentTool reporting", () => {
expect(reports[0]?.text).toContain("provider exploded")
}),
)
completionIt.live("keeps a silent child silent until a follow-up enables notify", () =>
Effect.gen(function* () {
const fixture = yield* reportingFixture()
const jobs = yield* Job.Service
const spawned = yield* fixture.call("call-silent-spawn", { notify: false })
const childID = outputSessionID(spawned.metadata)
expect(spawned.content).toEqual([
{
type: "text",
text: `The subagent is working in the background (sessionID: ${childID}) and will not notify you when it finishes, so you won't receive its result. Only use notify=false for work whose result you don't need. To send it more work, call subagent again with this sessionID.`,
},
])
expect((yield* fixture.sessions.get(childID)).metadata).toEqual({ "subagent.notify": false })
yield* fixture.sessions.wait(childID)
yield* fixture.sessions.wait(fixture.parent.id)
expect(yield* fixture.notices).toEqual([])
// Omitted notify keeps the child silent across follow-ups.
const silent = yield* fixture.call("call-silent-follow", { sessionID: childID })
expect(silent.content).toEqual(spawned.content)
yield* fixture.sessions.wait(childID)
yield* fixture.sessions.wait(fixture.parent.id)
expect((yield* fixture.sessions.get(childID)).metadata).toEqual({ "subagent.notify": false })
expect(yield* fixture.notices).toEqual([])
const loud = yield* fixture.call("call-loud-follow", { sessionID: childID, notify: true })
expect(loud.content).toEqual([
{
type: "text",
text: expect.stringContaining(
"You will receive a <subagent> message when it goes idle, and again after each later round of work.",
),
},
])
yield* fixture.sessions.wait(childID)
yield* fixture.sessions.wait(fixture.parent.id)
expect((yield* fixture.sessions.get(childID)).metadata).toEqual({})
const reports = (yield* fixture.notices).filter((notice) => notice.metadata?.["source"] === "subagent")
expect(reports).toHaveLength(1)
expect(reports[0]?.text).toContain(`<subagent sessionID="${childID}" state="completed"`)
expect(yield* jobs.pendingBackground).toEqual([])
}),
)
completionIt.live("defaults a child of a silent parent to reporting", () =>
Effect.gen(function* () {
const dir = yield* tmpdirScoped()
const location = Location.Ref.make({ directory: AbsolutePath.make(dir.path) })
const sessions = yield* Session.Service
const parent = yield* sessions.create({
location,
model: parentModel,
metadata: { [SubagentMetadata.KEY]: false },
})
yield* withSubagent(parent.location)
const locations = yield* LocationServiceMap.Service
const registry = yield* Tool.Service.pipe(Effect.provide(locations.get(parent.location)))
const spawned = yield* executeTool(registry, {
sessionID: parent.id,
...toolIdentity,
call: {
type: "tool-call",
id: "call-silent-parent-child",
name: SubagentTool.name,
input: { agent: "reviewer", description: "review", prompt: "review this" },
},
})
const childID = outputSessionID(spawned.metadata)
// The link switch belongs to the child's link, not to the parent's own metadata.
expect((yield* sessions.get(childID)).metadata).toBeUndefined()
yield* sessions.wait(childID)
yield* sessions.wait(parent.id)
const delivered = (yield* sessions.context(parent.id))
.filter((message) => message.type === "synthetic")
.filter((message) => message.metadata?.["source"] === "subagent")
expect(delivered).toHaveLength(1)
expect(delivered[0]?.text).toContain(`<subagent sessionID="${childID}" state="completed"`)
}),
)
})
describe("SubagentJob cancellation", () => {
+2 -3
View File
@@ -219,9 +219,8 @@ Subagents always run in the background. The call returns immediately with a
`sessionID`, and the parent receives a `<subagent>` message when the child goes
idle, and again after each later round of work, so it can keep working or end
its turn without waiting. Pass the returned `sessionID` to continue that same
child conversation; a follow-up to a running child joins its current run. Set
`notify: false` on a new subagent to stop its idle reports. Only subagent-mode
agents can be used, and the default nesting depth is one.
child conversation; a follow-up to a running child joins its current run. Only
subagent-mode agents can be used, and the default nesting depth is one.
Permission: `subagent` with the selected agent ID as its resource.