You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
core: foreground subagent interrupted by parent shutdown is recorded as a user stop #61413
When owner teardown (shutdown) interrupts a parent session while it is blocked waiting on a foreground subagent (jobs.block in packages/core/src/tool/plugin/subagent.ts), the Effect.onInterrupt cleanup calls sessions.interrupt(child.id) with no parent context.
Because SessionExecution.interrupt unconditionally passes "user" to coordinator.interrupt(sessionID, "user"), the parent session records reason: "shutdown" (preserving its time_suspended execution claim for restart recovery and omitting the idle marker), whereas the foreground child session records reason: "user", releases its execution claim (time_suspended = null), sets idle_outcome = "interrupted", and appends an idle context message as if a user had manually stopped it.
Steps to reproduce
Start a parent session that invokes a foreground subagent tool call.
While the child subagent execution is in flight, interrupt the parent execution fiber without calling the user-stop API (simulating owner/shutdown teardown).
Inspect the emitted SessionEvent.Execution.Interrupted events and session rows for both parent and child:
Child: reason === "user", time_suspended === null, idle_outcome === "interrupted" (expected "shutdown" to match the parent teardown)
Expected behavior
When a foreground subagent is interrupted as part of cascading its parent's interruption, it should inherit the active parent's recorded interruption reason (falling back to "shutdown" when unlabelled, matching terminal()), while ordinary user stops continue to report "user".
Thanks for the detailed report. I reproduced this on the latest dev (6d1c444) with a core unit test.
What the test does:
A parent session's turn starts a child session and waits on it.
Like the foreground path in subagent.ts, the parent calls sessions.interrupt(child) when it is interrupted.
The test then closes the execution owner scope, as a graceful shutdown does, without any user stop.
What happens:
Parent:Execution.Interrupted has reason shutdown, time_suspended is kept and idle_outcome is null, as intended.
Child: reason is user, time_suspended is cleared and idle_outcome is interrupted, so restart recovery won't pick it up.
The cause is that SessionExecution.interrupt always passes "user" to the coordinator. That overwrites the reason for a child that shutdown has already interrupted. The script below reproduces it; run it from an opencode checkout after bun install. Your PR #61414 proposes a fix.
Reproduction script (repro-61413.sh)
#!/usr/bin/env bash# Reproduces anomalyco/opencode#61413 as a core unit test.# Run from an opencode checkout (dev) after `bun install`: REPO=/path/to/opencode bash repro-61413.sh# It reuses the helpers in packages/core/test/session-execution.test.ts (seedSessions, buildExecution)# and adds one test: a parent drain starts a foreground child and, like subagent.ts, calls# sessions.interrupt(child) in Effect.onInterrupt. The owner scope is then closed (shutdown teardown).set -euo pipefail
REPO="${REPO:-/workspace/repo}"cd"$REPO/packages/core"
T=test/repro-61413.test.ts
cp test/session-execution.test.ts "$T"trap'rm -f "$T"' EXIT
cat >>"$T"<<'TEST'describe("repro #61413", () => { it.effect("foreground child interrupted by parent shutdown teardown", () => Effect.gen(function* () { const database = yield* Database.Service const bus = yield* Bus.Service const parent = Session.ID.make("ses_repro_parent") const child = Session.ID.make("ses_repro_child") yield* seedSessions(database, [parent]) yield* seedSessions(database, [child], { parent_id: parent }) const events: { sessionID: string; reason: string }[] = [] yield* bus.project(SessionEvent.Execution.Interrupted, (event) => Effect.sync(() => void events.push({ sessionID: event.data.sessionID, reason: event.data.reason })), ) const childRunning = yield* Deferred.make<void>() const parentBlocked = yield* Deferred.make<void>() const scope = yield* Scope.make() yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void)) let execution!: SessionExecution.Interface const context = yield* buildExecution(scope, ({ sessionID }) => sessionID === child ? Deferred.succeed(childRunning, undefined).pipe( Effect.andThen(Effect.never), // A real child turn has async cleanup (stream/tool teardown) when interrupted. ) : Effect.gen(function* () { // Mirrors subagent.ts: start child, block on it, and on interrupt call sessions.interrupt(child.id) yield* execution.resume(child).pipe(Effect.forkDetach) yield* Deferred.await(childRunning) yield* Deferred.succeed(parentBlocked, undefined) yield* Effect.never.pipe(Effect.onInterrupt(() => execution.interrupt(child).pipe(Effect.tap((r) => Effect.sync(() => console.log("parent onInterrupt -> interrupt(child) =", r))), Effect.asVoid))) }), ) execution = Context.get(context, SessionExecution.Service) yield* execution.resume(parent).pipe(Effect.forkIn(scope)) yield* Deferred.await(parentBlocked) yield* Effect.promise(() => new Promise<void>((r) => setTimeout(r, 20))) // Owner teardown (shutdown): close the scope without any user stop. yield* Scope.close(scope, Exit.void) yield* Effect.promise(() => new Promise<void>((r) => setTimeout(r, 100))) const rows = yield* database.db .select({ id: SessionTable.id, suspended: SessionTable.time_suspended, idle: SessionTable.idle_outcome }) .from(SessionTable) .all() .pipe(Effect.orDie) console.log("EVENTS", JSON.stringify(events)) console.log("ROWS", JSON.stringify(rows.map((r) => ({ id: r.id, suspended: r.suspended !== null, idle: r.idle })))) expect(events.find((e) => e.sessionID === child)?.reason).toBe("shutdown") }), )})TEST
bun test"$T" -t "repro #61413"
The upstream subagent lifetime refactor (#63382, #63223, #63392) removed the foreground subagent path: children now run as background Jobs, parent teardown no longer cascades an interruption into them (only an explicit caller cancel does), and a server shutdown leaves them resumable by design. The mismatch described here should no longer be reproducible on current dev.
The foreground subagent interrupt path this describes was removed in #63382, #63223 and #63392, so this no longer applies. If you still see this on the latest version, comment here and we'll reopen.
Activity
opencodejr commentedon Nov 3, 2026
Thanks for the detailed report. I reproduced this on the latest
dev(6d1c444) with a core unit test.What the test does:
subagent.ts, the parent callssessions.interrupt(child)when it is interrupted.What happens:
Execution.Interruptedhas reasonshutdown,time_suspendedis kept andidle_outcomeis null, as intended.user,time_suspendedis cleared andidle_outcomeisinterrupted, so restart recovery won't pick it up.The cause is that
SessionExecution.interruptalways passes"user"to the coordinator. That overwrites the reason for a child that shutdown has already interrupted. The script below reproduces it; run it from an opencode checkout afterbun install. Your PR #61414 proposes a fix.Reproduction script (repro-61413.sh)
Run it:
bash repro-61413.shYMoose commentedon Nov 22, 2026
The upstream subagent lifetime refactor (#63382, #63223, #63392) removed the foreground subagent path: children now run as background Jobs, parent teardown no longer cascades an interruption into them (only an explicit caller cancel does), and a server shutdown leaves them resumable by design. The mismatch described here should no longer be reproducible on current
dev.neriousy commentedon Nov 23, 2026
The foreground subagent interrupt path this describes was removed in #63382, #63223 and #63392, so this no longer applies. If you still see this on the latest version, comment here and we'll reopen.