GeezerVison is showing github.com — core: orphaned background child keeps an admitted completion that nothing drains · Issue #60245 · anomalyco/opencode
core: orphaned background child keeps an admitted completion that nothing drains #60245DescriptionCorrection (2026-10-30)
The original report below claimed the sweep never resumes a nested parent and that there is "no compensating resume anywhere". That is wrong, and I am replacing it. A nested parent is resumed by recovery of its own background job (recoverSubagent calls execution.resume(recovery.childSessionID) at packages/core/src/session/execution/restart.ts:206-211, and jobs.get only reads the in-process map at packages/core/src/job.ts:253-258, so it is empty on a fresh process and the :248 skip does not fire). I verified this with a harness test: a suspended nested parent with a running job is drained by the sweep.
The real defect is narrower.
Summary
If a background job's recorded identity fails the guard at packages/core/src/session/execution/restart.ts:182 — the child is missing, its parentID no longer matches, or the recorded parent session is gone — the sweep calls completeBackground (:183) and returns. It never resumes the child and never notifies anyone.
That is usually fine: the parent is gone, so there is nowhere to deliver.
The problem is the child's own inbox. A completion from the child's own background subagent may already have been admitted into it with resume: false, because the child was a member of the suspended set (restart.ts:240-242, via children). Suppressing the wake was safe under the assumption that the sweep would resume that child. When the identity guard bails, the assumption no longer holds, and nobody ever drains the row:
- the completion stays in
session_inbox forever;
- the child stays claimed until a later boot, when
releaseChildClaims (store.ts:238-249) silently clears time_suspended and resets resume_attempts because the child is no longer a pending job;
- nothing prompts a child session, so the row is never consumed.
Reachability
Deleting a parent session does not delete its children: parent_id is a plain column with no foreign key (packages/core/src/session/sql.ts:37) and deletion removes a single row (packages/core/src/session/projector.ts:649). Routine cleanup of an old session therefore orphans any children that were still running — the same operation reported in #36349.
Reproduction (harness, verified)
Seeded in packages/core/test/session-execution.test.ts style: a suspended nested parent P (parent_id = G, claimed), a completed child C of P with a terminal marker, a running background job for P whose recorded parent G is not seeded, and nothing else.
Running resumeSuspendedSessions produces:
drained: [] // P is never resumed
inbox(P): 1 // C's completion was admitted
claim(P): true // still suspended
pendingBackground: 0 // P's marker was removed by completeBackground
So the completion is durable but unreachable, and the retry record is already gone.
Control: the same scenario with G seeded drains P normally (drained: [P]), which is why this only bites the orphaned case.
What does not fix it
Releasing the claim in the guard branch (store.release(childSessionID) before completeBackground) was tried: it clears claim(P) but leaves inbox(P): 1. The completion is still never consumed. Delivering to an orphaned subtree is a product decision, not a local patch.
Suggested direction
Either keep such completions retrievable (a pending queue the next session in the project can drain), or fail loudly instead of clearing the claim silently. Both are policy choices, so I am not proposing a specific patch here.
Original report (superseded)
Kept only for history; its central claim was wrong.
The restart sweep suppresses a parent wake with resume: false when the parent is in the suspended set, but only resumes sessions from listSuspended(), which filters parent_id IS NULL. A nested parent enters the set but can never be resumed, so its completion is admitted and never delivered.
Activityopencodejr commented on Oct 29, 2026 Thanks for the detailed analysis. I reproduced this on the latest dev (589c62d) with a core-level regression test (script below).
Setup: G is top-level, P is a child of G and claimed, and C is a child of P. P's background subagent job is still running and C's job is completed, with both markers left over from the crash. After resumeSuspendedSessions, C's <subagent ... state="completed"> notice is left in P's session_inbox and never consumed. P is idle, every claim is cleared and no job markers remain, so a later boot can't recover it either.
The path I hit is slightly different from the one you describe. P's own job recovery does resume it, but that turn finishes before C's notice is admitted with resume: false. The final loop only resumes listSuspended(), which never includes P, so nothing wakes P again. If C's job is recorded before P's, the notice is consumed and the test passes.
The latest release, v2.2.1, has the same logic.
Reproduction script (repro-60245.sh)
#!/usr/bin/env bash
# Repro for #60245: run from a checkout of anomalyco/opencode (dev) after `bun install`.
# Inserts a regression test into packages/core/test/session-execution.test.ts and runs it.
set -euo pipefail
REPO=${1:-.}
F="$REPO/packages/core/test/session-execution.test.ts"
cat > /tmp/repro-60245.snippet <<'SNIP'
for (const childFirst of [false, true])
it.effect(`repro-60245: nested parent receives a completed grandchild notice (childFirst=${childFirst})`, () =>
Effect.gen(function* () {
const database = yield* Database.Service
const jobs = yield* Job.Service
const bus = yield* Bus.Service
const store = yield* SessionStore.Service
const g = Session.ID.make("ses_nested_g")
const p = Session.ID.make("ses_nested_p")
const c = Session.ID.make("ses_nested_c")
yield* seedSessions(database, [g])
yield* seedSessions(database, [p], { parent_id: g, time_suspended: Date.now() })
yield* seedSessions(database, [c], { parent_id: p })
const startP = Effect.gen(function* () {
yield* jobs.start({
id: "job_p", type: "subagent",
recovery: { kind: "subagent", parentSessionID: g, childSessionID: p, agent: "general", description: "P" },
run: Effect.never,
})
yield* jobs.background("job_p")
})
const startC = Effect.gen(function* () {
yield* jobs.start({
id: "job_c", type: "subagent",
recovery: { kind: "subagent", parentSessionID: p, childSessionID: c, agent: "general", description: "C" },
run: Effect.succeed("C finished"),
})
yield* jobs.background("job_c")
yield* jobs.wait({ id: "job_c" })
})
if (childFirst) { yield* startC; yield* startP } else { yield* startP; yield* startC }
console.log("pending before restart", (yield* jobs.pendingBackground).map((j) => [j.id, j.status]))
const drained: Session.ID[] = []
const scope = yield* Scope.make()
yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void))
const restarted = yield* Job.make.pipe(Scope.provide(scope))
const context = yield* buildExecution(
scope,
({ sessionID }) =>
Effect.sync(() => void drained.push(sessionID)).pipe(
Effect.andThen(SessionInbox.promote(database.db, bus, sessionID, "steer")),
Effect.asVoid,
),
{ maxAttempts: 2 },
restarted,
)
const restart = Context.get(context, SessionRestart.Service)
const execution = Context.get(context, SessionExecution.Service)
yield* restart.resumeSuspendedSessions
yield* Effect.yieldNow
yield* Effect.forEach([g, p, c], execution.awaitIdle, { discard: true })
yield* Effect.yieldNow
yield* Effect.forEach([g, p, c], execution.awaitIdle, { discard: true })
const inboxP = yield* SessionInbox.list(database.db, p)
const synthP = (yield* store.context(p)).filter((m) => m.type === "synthetic")
console.log(JSON.stringify({ childFirst, drained, inboxP: inboxP.map((i) => i.payload), synthP: synthP.map((m) => m.text), claims: yield* claims(database), pending: (yield* restarted.pendingBackground).map((j) => j.id) }, null, 1))
expect(inboxP).toEqual([])
}),
)
SNIP
python3 - "$F" <<'PY'
import sys
p=sys.argv[1]; s=open(p).read(); add=open('/tmp/repro-60245.snippet').read()
if 'repro-60245' not in s:
i=s.index(' it.effect("resumes a background subagent and notifies its parent exactly once"')
s=s[:i]+add+"\n"+s[i:]
open(p,'w').write(s)
PY
cd "$REPO/packages/core"
# childFirst=false (P's job recorded before C's, the natural order) FAILS:
# C's completion stays in P's inbox, P is idle, claims and markers are gone.
bun test test/session-execution.test.ts -t repro-60245
Run it: bash repro-60245.sh
changed the title [-]core: nested subagent parent gets an unwakeable completion — wake suppressed for a session the sweep cannot resume[/-] [+]core: orphaned background child keeps an admitted completion that nothing drains[/+] on Oct 29, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|