Skip to content

Subagents inherit the Desktop browser grant but can't use the parent's attachment #61238

Open

Description

@carson2222

Description

When a Desktop session has the in-app browser attached, its subagents also get the browser.* tools and the Browser skill, but they can't use them. Every call from the child fails as disconnected, so the subagent wastes turns and then falls back to another tool.

Cause, as far as I can tell (dev @ 69269e4):

  • plugin-browser/src/connection.ts: attaching the browser to a session grants browser: * and the Browser skill by appending allow rules to that session's permissions. The attachment itself is stored only under that session ID.
  • core/src/session.ts (Session.create): a child copies parent.permissions when none are passed, so it inherits the allow rules.
  • core/src/session/context.ts: session permissions are merged after agent permissions, so the inherited allow beats the plugin's default deny. The child sees the tools as available, but there is no attachment for its own session ID.

In my local history, all 5 subagents that hit "disconnected" had the inherited browser allow rules on their session.

Possible fix: don't let attachment grants carry over to children (e.g. strip the browser and Browser-skill allows in child sessions unless the child has its own attachment), or check the attachment when building the tool list instead of relying on the permission alone.

Plugins

none relevant

OpenCode version

2.2.0 (also matches dev @ 69269e4)

Steps to reproduce

  1. In OpenCode Desktop, open a session and attach the in-app browser.
  2. Ask the main agent to start a subagent that takes a screenshot of a page.
  3. The subagent sees the browser.* tools and Browser skill, calls them, and gets disconnected errors.

Operating System

macOS

Activity

  1. opencodejr commented on Nov 2, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this on 2.2.0, and it still happens on the latest dev (ff90ed916).

    The Desktop app can't run in this sandbox, so I simulated the attach step. The script gives the parent session the same two allow rules the browser plugin adds when the Desktop browser attaches (browser: * and the Browser skill). It then has the main agent start a general subagent, which calls browser.tabs.list in a simulated run.

    • The subagent's session copies the parent's permissions, including both browser allows.
    • Its model request lists the browser.* tools and Browser skill.
    • The call fails with [browser.disconnected] No desktop browser is connected to this session..., because the attachment exists only for the parent's session ID.

    This matches your analysis: Session.create copies parent.permissions, and the session's allow rules override the plugin's deny rules for every agent. The recording and screenshot below are from the 2.2.0 run, and the script below reproduces it. A closely related issue is #54044 (browser tools exposed despite an agent-level deny browser), but it happens through a different path.

    recording.mp4

    Screenshot

    Reproduction script (drive.ts)
    // Repro for #61238: a subagent inherits the parent's browser grant (session permissions)
    // but has no browser attachment of its own, so browser.* calls fail as [browser.disconnected].
    // The Desktop "attach browser" step is simulated by applying exactly the allow rules that
    // plugin-browser's grant() (packages/plugin-browser/src/connection.ts) appends to the attached session.
    import { Effect, Stream } from "effect"
    import { Llm, OpenCodeDriver } from "opencode-drive"
    
    const seen: string[] = []
    
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        tui: { recording: true },
      },
      ({ ui, llm, opencode }) =>
        Effect.gen(function* () {
          yield* llm.serve((request: any) => {
            const messages: any[] = request.body?.messages ?? []
            const system = String(messages[0]?.content ?? "")
            if (system.includes("You name conversations")) return Stream.make(Llm.text("Browser test"))
            const body = JSON.stringify(request.body)
            const users = messages.filter((m) => m.role === "user").map((m) => JSON.stringify(m.content))
            const tool = messages.filter((m) => m.role === "tool").map((m) => JSON.stringify(m.content))
            const exposed = body.includes("browser.tabs") || body.includes("Desktop browser tools")
            const isChild = users.some((u) => u.includes("Take a screenshot of example.com"))
            const isParent = users.some((u) => u.includes("Start a subagent"))
            if (isChild) {
              if (tool.length === 0) {
                seen.push(`CHILD request: browser tools exposed to subagent = ${exposed}`)
                return Stream.make(
                  Llm.toolCall({ index: 0, id: "call_browser", name: "execute", input: { code: "return await tools.browser.tabs.list({})" } }),
                  Llm.finish("tool-calls"),
                )
              }
              const m = tool.join("\n").match(/\[browser\.[a-z_]+\][^"\\]*/)
              seen.push(`CHILD browser call result: ${m ? m[0] : tool.join("\n").slice(0, 400)}`)
              return Stream.make(Llm.text(`Subagent browser call failed: ${m ? m[0].slice(0, 80) : "unknown"}`))
            }
            if (isParent) {
              if (tool.length === 0) {
                seen.push(`PARENT request: browser tools exposed = ${exposed}`)
                return Stream.make(
                  Llm.toolCall({ index: 0, id: "call_sub", name: "subagent", input: { agent: "general", description: "Screenshot page", prompt: "Take a screenshot of example.com" } }),
                  Llm.finish("tool-calls"),
                )
              }
              return Stream.make(Llm.text("The subagent could not use the browser."))
            }
            return Stream.make(Llm.text("Ready."))
          })
          yield* Effect.log("step: hello")
          yield* ui.submit("hello")
          yield* ui.waitFor("Ready.", { timeout: 60_000 } as any)
          const sessions: any = yield* opencode.session.list({} as any)
          const list: any[] = Array.isArray(sessions) ? sessions : (sessions.data ?? sessions.items ?? [])
          const parent = list[0]
          // Same rules plugin-browser grant() appends when the Desktop browser attaches.
          yield* opencode.session.update({
            sessionID: parent.id,
            permissions: [
              ...(parent.permissions ?? []),
              { action: "browser", resource: "*", effect: "allow" },
              { action: "skill", resource: "browser", effect: "allow" },
            ],
          } as any)
          yield* Effect.log("step: subagent prompt")
          yield* ui.submit("Start a subagent that takes a screenshot of example.com")
          yield* ui.waitFor("could not use the browser", { timeout: 60_000 } as any).pipe(Effect.tapError(() => Effect.gen(function* () { yield* ui.screenshot("timeout"); for (const line of seen) yield* Effect.log(line) })))
          const child: any = yield* opencode.session.list({ parentID: parent.id } as any).pipe(
            Effect.map((r: any) => (Array.isArray(r) ? r : (r.data ?? r.items ?? []))[0]),
            Effect.orElseSucceed(() => undefined),
          )
          seen.push(`child session ${child?.id} permissions: ${JSON.stringify(child?.permissions)}`)
          yield* ui.screenshot("result")
          for (const line of seen) yield* Effect.log(line)
        }),
    )

    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.

  2. jimmyallinai commented on Nov 2, 2026

    @jimmyallinai
    Contributor

    I'll take this one. I plan to trace how Session.create copies the parent's permissions into a child session and why the browser attachment grant leaks across that boundary, then strip the session-scoped browser/skill allows from inherited permissions (keeping other inherited permissions intact) so a subagent no longer sees browser.* tools it cannot use. I'll add a regression test around child-session permission inheritance and run the adjacent core session tests plus typecheck before opening a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions