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(subagent): Available subagents ignores session permissions and continued children keep stale parent permissions #64840
Session.create (packages/core/src/session.ts) copies parent?.permissions onto child sessions so host policies apply across the session family, and Permission.Service (packages/core/src/permission.ts) evaluates Permission.merge(agent.permissions, session.permissions ?? []).
In packages/core/src/tool/plugin/subagent.ts, two places drift from session.permissions:
The context / compaction / generate hook (subagent.ts:256) filters Available subagents: using Permission.evaluate(name, agent.id, selected.permissions) and ignores session.permissions. Subagents denied on the session are still advertised to the model, while subagents explicitly allowed on the session remain hidden if the agent default denies them.
Continuing an existing child (existing !== undefined, subagent.ts:163-174) syncs switchAgent and switchModel, but never updates existing.permissions when parent.permissions changed via Session.setPermissions, leaving resumed subagent sessions running under stale permission rules.
Plugins
None
OpenCode version
2.3.0 (dev)
Steps to reproduce
Create a parent session, call sessions.setPermissions to deny subagent for reviewer (or allow a subagent denied by agent defaults), and trigger the sessioncontext hook: Available subagents: ignores session.permissions.
Start a child session via subagent, tighten parent rules with sessions.setPermissions (e.g. deny bash), then continue the same child.id via subagent: child.permissions retains the old rules instead of the updated parent rules.
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the precise report. I reproduced both parts on 2.3.0, and both still happen on the latest dev (d33b578), run from source. A simulated model only triggered the subagent tool calls; the session rules were set and read back through the SDK.
1. Available subagents: ignores session permissions. With the agent allowing subagent:reviewer, I set a session rule denying it. The subagent tool description in the next model request still listed explore, general, reviewer. #48106 already tracks this part, and PR #56979 targets it.
2. A continued child keeps stale permissions. I spawned a reviewer child while the parent allowed shell, so the child copied [{shell,*,allow}]. I then changed the parent to deny shell and continued the same child via subagent with its sessionID. The child still had [{shell,*,allow}].
The script below reproduces both. Related: your PR #64841, and #48106 for part 1.
Reproduction script (drive.ts)
// Repro for anomalyco/opencode#64840// Part 1: the `subagent` tool's "Available subagents:" list ignores session permissions.// Part 2: continuing an existing child via `subagent` (sessionID) does not refresh the child's// permissions after the parent's permissions were changed.// Run: OPENCODE_DRIVE_MEDIA_DIR=/workspace/media opencode-drive run drive.tsimport{Effect,Stream}from"effect"import{Llm,OpenCodeDriver}from"opencode-drive"constlisted=(body: any): string=>{consttools: any[]=body?.tools??[]consttool=tools.find((t)=>(t.function?.name??t.name)==="subagent")if(!tool)return"(no subagent tool)"constdesc: string=tool?.function?.description??tool?.description??""constidx=desc.indexOf("Available subagents:")if(idx<0)return"(no 'Available subagents' list)"returndesc.slice(idx).split("\n").slice(1).map((l)=>l.split(":")[0].replace("- ","")).join(", ")}constlastUserText=(body: any): string=>{constmsgs: any[]=body?.messages??body?.input??[]consttext=JSON.stringify(msgs)returntext}exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true},config: {agents: {reviewer: {mode: "subagent",description: "Reviews code"},build: {permissions: [{action: "subagent",resource: "reviewer",effect: "allow"}]},},}asany,},({ ui, llm, opencode })=>Effect.gen(function*(){constparentBodies: any[]=[]letchildID: string|undefinedyield*llm.serve((request)=>{constbody: any=request.bodyif(!Array.isArray(body?.tools))returnStream.make(Llm.text("Title"))constall=lastUserText(body)if(all.includes("You are a subagent spawned"))returnStream.make(Llm.text("child done"))parentBodies.push(body)console.log("REQ last msg:",JSON.stringify((body.messages??[]).at(-1)).slice(0,300))constmsgs: any[]=body.messages??[]constlast=msgs[msgs.length-1]constlastStr=JSON.stringify(last??"")if(last?.role==="tool"||lastStr.includes("tool_result")||lastStr.includes("function_call_output"))returnStream.make(Llm.text("parent ack"))if(lastStr.includes("STEP_SPAWN"))returnStream.make(Llm.toolCall({index: 0,id: "call_spawn",name: "subagent",input: {agent: "reviewer",description: "review",prompt: "review it"}}),Llm.finish("tool-calls"),)if(lastStr.includes("STEP_CONTINUE"))returnStream.make(Llm.toolCall({index: 0,id: "call_cont",name: "subagent",input: {agent: "reviewer",description: "review again",prompt: "again",sessionID: childID??""}}),Llm.finish("tool-calls"),)constm=lastStr.match(/STEP_(\w+)/)returnStream.make(Llm.text(`ok ${m ? m[1] : "?"}`))})yield*Effect.sleep(process.env.OC_DEV ? 30000 : 5000)yield*ui.submit("STEP_A")yield*ui.waitFor("ok A",{timeout: 60000})constsessions: any=yield*opencode.session.list({}asany)constitems: any[]=sessions.data??sessions.items??sessionsconstparentID=items[0].idconsole.log("PART1 baseline (agent allows reviewer, no session rules):",listed(parentBodies.at(-1)))yield*opencode.session.update({sessionID: parentID,permissions: [{action: "subagent",resource: "reviewer",effect: "deny"}]}asany)constp1: any=yield*opencode.session.get({sessionID: parentID}asany)console.log("PART1 parent.permissions:",JSON.stringify(p1.permissions))yield*ui.submit("STEP_B")yield*ui.waitFor("ok B",{timeout: 60000})console.log("PART1 after session deny subagent:reviewer -> advertised:",listed(parentBodies.at(-1)))// Part 2: reset parent rules to allow, spawn a childyield*opencode.session.update({sessionID: parentID,permissions: [{action: "shell",resource: "*",effect: "allow"}]}asany)yield*ui.submit("STEP_SPAWN")yield*Effect.sleep(10000)constall: any=yield*opencode.session.list({}asany)constlist: any[]=all.data??all.items??allconstchild=list.find((s: any)=>s.parentID===parentID)childID=child?.idconstc0: any=yield*opencode.session.get({sessionID: childID??""}asany)console.log("PART2 child created:",childID,"child.permissions:",JSON.stringify(c0.permissions))yield*opencode.session.update({sessionID: parentID,permissions: [{action: "shell",resource: "*",effect: "deny"}]}asany)constp2: any=yield*opencode.session.get({sessionID: parentID}asany)console.log("PART2 parent.permissions after tightening:",JSON.stringify(p2.permissions))yield*ui.submit("STEP_CONTINUE")yield*Effect.sleep(8000)constc1: any=yield*opencode.session.get({sessionID: childID??""}asany)console.log("PART2 child.permissions after continuing via subagent:",JSON.stringify(c1.permissions))yield*ui.screenshot("final")}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Activity
opencodejr commentedon Nov 19, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the precise report. I reproduced both parts on 2.3.0, and both still happen on the latest
dev(d33b578), run from source. A simulated model only triggered thesubagenttool calls; the session rules were set and read back through the SDK.1.
Available subagents:ignores session permissions. With the agent allowingsubagent:reviewer, I set a session rule denying it. Thesubagenttool description in the next model request still listedexplore, general, reviewer. #48106 already tracks this part, and PR #56979 targets it.2. A continued child keeps stale permissions. I spawned a
reviewerchild while the parent allowedshell, so the child copied[{shell,*,allow}]. I then changed the parent to denyshelland continued the same child viasubagentwith itssessionID. The child still had[{shell,*,allow}].The script below reproduces both. Related: your PR #64841, and #48106 for part 1.
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.