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: interrupted subagent dispatch loses the child session ID #67948
If the server dies while dispatching a subagent, the child session and its queued prompt can survive without a link from the parent's tool call. On the parent's next model request, the tool error says Tool execution interrupted: subagent without the child session ID. The parent can't use that result to continue the existing child.
The interrupted tool result should include the original child session ID.
Plugins
Built-in subagent tool. No third-party plugins needed.
OpenCode version
Reproduced from source on dev at f1b673ca82.
Steps to reproduce
In a parent session, ask the agent to delegate a small task to a subagent.
Stop the server after the child's prompt is saved but before the background job is recorded. To hit this window reliably in a local test, take a SQLite snapshot at entry to Job.start for that subagent and start a fresh server from the snapshot.
Confirm the snapshot has the child session and its queued prompt, with no background job for that child.
After restart, ask the parent what happened to the delegated task. Inspect the subagent tool result sent with the next model request. It says Tool execution interrupted: subagent and omits the child ID.
Screenshot
Operating System
macOS arm64.
Terminal
Not required. Reproduced through the core integration test harness with a scripted model.
The existing restart fixes work once a subagent has a durable job record. I verified that an already-running child resumed and reported back once. This issue is about the earlier dispatch window: the child and its prompt are saved, but there is no job record yet and the interrupted parent tool result loses the child ID.
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
This still happens on the latest dev (c8bf9d5), and I reproduced it on 2.4.3 with opencode-drive's simulated model.
Setup:
A project plugin's prompt hook holds the child's prompt admission, so the child session exists but no job has started.
I froze the server and snapshotted its SQLite database, as you describe, then stopped it, restored the snapshot and relaunched.
I then asked the parent what happened.
After the restore, the parent's next model request carried Tool execution interrupted: subagent with no child ID, even though the child session had been created. With a normal shutdown instead, 2.4.3 does include the ID (Tool execution interrupted (sessionID: ses_…)), so only a hard crash loses it. My stop point is slightly earlier than yours (the child's prompt wasn't saved yet), but the missing link is the same. The script and recording are below.
Likely cause (not confirmed): the child ID is only reported as in-memory tool progress, which isn't saved. After a crash, settleStaleToolCalls in packages/core/src/session/runner/llm.ts (lines 438–446) finds no sessionID in the saved metadata. Your open PR #52296 addresses this; I haven't tested it.
// Repro for #67948: server dies after the subagent child session is created but before its// background job is recorded. A project plugin's `prompt` hook parks the child's prompt// admission (marker file), the script snapshots the database there (like a hard crash),// stops the server, restores the snapshot, relaunches it, and logs the// parent's next model request to show the settled `subagent` tool error.import{Effect,Stream}from"effect"import{appendFileSync,copyFileSync,existsSync,readdirSync,readFileSync,readlinkSync,rmSync}from"node:fs"import{defineScript,Llm}from"opencode-drive"constMARK="/workspace/repro/child-prompt.marker"constLOG="/workspace/repro/requests.jsonl"rmSync(MARK,{force: true})rmSync(LOG,{force: true})constplugin=`import { existsSync, writeFileSync } from "node:fs"export default { id: "park-child-prompt", async setup(ctx) { await ctx.session.hook("prompt", async (event) => { if (!event.prompt.text.startsWith("You are a subagent spawned")) return if (existsSync(${JSON.stringify(MARK)})) return writeFileSync(${JSON.stringify(MARK)}, event.sessionID + " " + process.pid) await new Promise(() => {}) // park here until the server is killed }) },}`// Run: OPENCODE_DRIVE_DB=restart.sqlite opencode-drive start --name r67948 --script ./drive.ts [--dev /path/to/opencode-checkout]// The parent's model requests are written to requests.jsonl; look at the `subagent` tool result after the restart.exportdefaultdefineScript({launch: "manual",project: {git: true,files: {".opencode/plugins/park/index.js": plugin}},run: ({ server, tuis, llm })=>Effect.gen(function*(){yield*llm.serve((request,index)=>{appendFileSync(LOG,JSON.stringify({ index, request })+"\n")if(index===0)returnStream.make(Llm.toolCall({index: 0,id: "call_sub",name: "subagent",input: {agent: "general",description: "Small task",prompt: "Say hi"}}),Llm.finish("tool-calls"),)returnStream.make(Llm.text(`Response ${index}`))})yield*server.launch()consttui=yield*tuis.launch("main",{recording: true})yield*tui.ui.submit("Delegate a small task to a subagent")for(leti=0;i<300&&!existsSync(MARK);i++)yield*Effect.sleep("100 millis")if(!existsSync(MARK))returnyield*Effect.die(newError("child prompt hook never reached"))yield*tui.ui.screenshot("before-kill")// Hard crash, as in the report: freeze the server at this point, snapshot its SQLite// database (with WAL), let it stop, then restore the snapshot before relaunching.constpid=Number(readFileSync(MARK,"utf8").split(" ")[1])constdb=readdirSync(`/proc/${pid}/fd`).map((fd)=>{try{returnreadlinkSync(`/proc/${pid}/fd/${fd}`)}catch{return""}}).find((f)=>f.endsWith("restart.sqlite"))!process.kill(pid,"SIGSTOP")constfiles=[db,db+"-wal",db+"-shm"].filter((f)=>existsSync(f))for(constfoffiles)copyFileSync(f,f+".snap")process.kill(pid,"SIGCONT")yield*server.kill()for(constfof[db+"-wal",db+"-shm"])rmSync(f,{force: true})for(constfoffiles)copyFileSync(f+".snap",f)appendFileSync(LOG,JSON.stringify({snapshot: db, files })+"\n")yield*Effect.sleep("1 second")yield*server.launch()yield*Effect.sleep("3 seconds")yield*tui.ui.submit("What happened to the delegated task?")yield*tui.ui.waitFor("Response")yield*Effect.sleep("1 second")yield*tui.ui.screenshot("after-restart")}),})
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH.
Activity
OpeOginni commentedon Dec 3, 2026
The existing restart fixes work once a subagent has a durable job record. I verified that an already-running child resumed and reported back once. This issue is about the earlier dispatch window: the child and its prompt are saved, but there is no job record yet and the interrupted parent tool result loses the child ID.
opencodejr commentedon Dec 3, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
This still happens on the latest
dev(c8bf9d5), and I reproduced it on 2.4.3 with opencode-drive's simulated model.Setup:
prompthook holds the child's prompt admission, so the child session exists but no job has started.After the restore, the parent's next model request carried
Tool execution interrupted: subagentwith no child ID, even though the child session had been created. With a normal shutdown instead, 2.4.3 does include the ID (Tool execution interrupted (sessionID: ses_…)), so only a hard crash loses it. My stop point is slightly earlier than yours (the child's prompt wasn't saved yet), but the missing link is the same. The script and recording are below.Likely cause (not confirmed): the child ID is only reported as in-memory tool progress, which isn't saved. After a crash,
settleStaleToolCallsinpackages/core/src/session/runner/llm.ts(lines 438–446) finds nosessionIDin the saved metadata. Your open PR #52296 addresses this; I haven't tested it.https://anoma.ly/team/github-bot/media/8c1c68cd6c852c0389303c997150bee4333d25206ba62cf03e6ca961043e064d.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH.