Skip to content

fix(core): fully denied skill tool stays in the model's tool list #65892

Done

Description

@coygeek

Summary

Description

With the built-in browser plugin enabled and no browser attached, a blanket skill deny leaves the skill tool in the first model request. Calling it returns Permission denied: skill, costing an unnecessary model step.

Steps to reproduce

  1. Save the script below as reproduce.py and run it with Python 3 and OpenCode on PATH. It creates a fresh project and HOME/XDG directories for each case and uses a loopback model with a dummy key.
  2. The script applies {"action":"skill","resource":"*","effect":"deny"} either in permissions or in agents.build.permissions. It sends one prompt via opencode run --standalone, prints which tools appear on the first model request, and records the result of a test call if skill was listed.
  3. The script runs each case again with "plugins": ["-opencode.browser"] as a control.
python3 reproduce.py
Reproduction script: reproduce.py
import json
import os
import pathlib
import shutil
import subprocess
import tempfile
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

class Model(BaseHTTPRequestHandler):
    def log_message(self, *args):
        pass

    def do_POST(self):
        body = json.loads(self.rfile.read(int(self.headers["Content-Length"])))
        names = [tool["function"]["name"] for tool in body.get("tools", [])]
        self.server.requests.append(names)
        delta, reason = {"content": "OK"}, "stop"
        if len(self.server.requests) == 1 and "skill" in names:
            call = {"index": 0, "id": "call_probe", "type": "function",
                    "function": {"name": "skill", "arguments": '{"id":"probe"}'}}
            delta, reason = {"tool_calls": [call]}, "tool_calls"
        self.send_response(200)
        self.send_header("Content-Type", "text/event-stream")
        self.end_headers()
        for payload, finish in [({"role": "assistant", **delta}, None), ({}, reason)]:
            chunk = {"id": "probe", "object": "chat.completion.chunk", "model": "m",
                     "choices": [{"index": 0, "delta": payload, "finish_reason": finish}]}
            self.wfile.write(f"data: {json.dumps(chunk)}\n\n".encode())
        self.wfile.write(b"data: [DONE]\n\n")

def run(cli, model, scope, browser):
    model.requests = []
    with tempfile.TemporaryDirectory() as directory:
        root = pathlib.Path(directory).resolve()
        env = {"PATH": os.defpath, "PWD": str(root), "OPENCODE_DISABLE_MODELS_FETCH": "1"}
        for key in ("HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CACHE_HOME", "TMPDIR"):
            path = root / key
            path.mkdir()
            env[key] = str(path)
        skill = root / ".opencode/skills/probe"
        skill.mkdir(parents=True)
        (skill / "SKILL.md").write_text("---\nname: probe\ndescription: Test skill\n---\n\nProbe.\n")
        rules = [{"action": "skill", "resource": "*", "effect": "deny"},
                 {"action": "read", "resource": "*", "effect": "allow"}]
        config = {"providers": {"probe": {
            "package": "@opencode/ai/providers/openai-compatible",
            "settings": {"baseURL": f"http://127.0.0.1:{model.server_port}/v1", "apiKey": "dummy"},
            "models": {"m": {}}}}}
        config.update({"permissions": rules} if scope == "config"
                      else {"agents": {"build": {"permissions": rules}}})
        if not browser:
            config["plugins"] = ["-opencode.browser"]
        (root / "opencode.json").write_text(json.dumps(config))
        result = subprocess.run([cli, "run", "--standalone", "--auto", "--title", "Probe",
                                 "--agent", "build", "--model", "probe/m", "--format", "json"],
                                cwd=root, env=env, input="Hello", text=True,
                                capture_output=True, timeout=30, check=True)
    first = model.requests[0]
    print(scope, f"browser={browser}", f"skill_listed={'skill' in first}",
          f"read_listed={'read' in first}", f"denied={'Permission denied: skill' in result.stdout}")

cli = shutil.which("opencode")
assert cli, "OpenCode executable not found"
with ThreadingHTTPServer(("127.0.0.1", 0), Model) as model:
    thread = threading.Thread(target=model.serve_forever)
    thread.start()
    try:
        for scope in ("config", "agent"):
            for browser in (True, False):
                run(cli, model, scope, browser)
    finally:
        model.shutdown()
        thread.join()

Expected behavior

When every skill ID is denied, the model's tools list omits skill, as it does for other tools whose permissions deny every resource.

Actual behavior

In both deny scopes, the first request contains skill and the test call returns Permission denied: skill. Disabling the browser plugin removes skill from both requests. The allowed read tool appears in all four runs.

Evidence

  • Expected source: Skills permissions describes hiding denied skills. The registry test shows that tools denied across all resources are filtered from model definitions.
  • Failure source: The loopback provider's first request and the standalone CLI's JSON tool error in the reproduction above.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

The browser plugin appends a narrower deny for skill: browser. The registry predicate checks only the last rule matching the tool's action, so the narrower deny makes it miss the earlier wildcard deny. Both code paths are present in the release and on dev.

Restoration check

Run the same fixture with the browser plugin enabled. skill should be absent from the first request for both deny scopes, and read should still be present.

Runtime or environment

OpenCode version

2.4.1, current npm release at verification. The code links above are pinned to the inspected dev head.

Operating System

macOS arm64.

Plugins

Built-in opencode.browser and the fixture's OpenAI-compatible provider.

References

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: The model receives a tool definition and can spend a step calling it even though a blanket deny makes every call fail in the tested standalone session.
  • Workaround status: available
  • Workaround basis: Disabling the browser plugin removes the unwanted tool in both tested scopes, for users who do not need the plugin.

Activity

  1. added
    area/core
    type/bug
    version/v2
    on Nov 23, 2026
  2. opencodejr commented on Nov 23, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report and script. I reproduced this on 2.4.1 using your script with a local mock model (no real provider). With the built-in browser plugin enabled, a {"action":"skill","resource":"*","effect":"deny"} rule leaves skill in the first request's tools. This happens in both top-level permissions and agents.build.permissions, and the model's call returns Permission denied: skill. With "plugins": ["-opencode.browser"], skill is not offered.

    It still happens on the latest dev (2002026a), run from source. There the first request's tools are generate_image, generate_video, question, skill, subagent, execute with the plugin on, and the same list without skill with it off. (read is not a top-level tool on dev because Code Mode's execute is listed, so that column of the script doesn't apply there.)

    The script below is your reproduction, lightly adapted so it can also run against a source checkout.

    Reproduction script (reproduce.py)
    # Reproduces anomalyco/opencode#65892: a blanket `skill` deny leaves the `skill`
    # tool in the model's tool list while the built-in browser plugin is enabled.
    # Usage: python3 reproduce.py            (uses `opencode` from PATH)
    #        OC_CMD="bun ... index.ts" python3 reproduce.py   (run from source)
    import json, os, pathlib, shlex, shutil, subprocess, tempfile, threading
    from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
    
    class Model(BaseHTTPRequestHandler):
        def log_message(self, *args): pass
        def do_POST(self):
            body = json.loads(self.rfile.read(int(self.headers["Content-Length"])))
            names = [t["function"]["name"] for t in body.get("tools", [])]
            self.server.requests.append(names)
            delta, reason = {"content": "OK"}, "stop"
            if len(self.server.requests) == 1 and "skill" in names:
                call = {"index": 0, "id": "call_probe", "type": "function",
                        "function": {"name": "skill", "arguments": '{"id":"probe"}'}}
                delta, reason = {"tool_calls": [call]}, "tool_calls"
            self.send_response(200)
            self.send_header("Content-Type", "text/event-stream")
            self.end_headers()
            for payload, finish in [({"role": "assistant", **delta}, None), ({}, reason)]:
                chunk = {"id": "probe", "object": "chat.completion.chunk", "model": "m",
                         "choices": [{"index": 0, "delta": payload, "finish_reason": finish}]}
                self.wfile.write(f"data: {json.dumps(chunk)}\n\n".encode())
            self.wfile.write(b"data: [DONE]\n\n")
    
    def run(cmd, model, scope, browser):
        model.requests = []
        with tempfile.TemporaryDirectory() as d:
            root = pathlib.Path(d).resolve()
            env = {"PATH": os.environ["PATH"], "PWD": str(root), "OPENCODE_DISABLE_MODELS_FETCH": "1"}
            for key in ("HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CACHE_HOME", "TMPDIR"):
                p = root / key; p.mkdir(); env[key] = str(p)
            skill = root / ".opencode/skills/probe"; skill.mkdir(parents=True)
            (skill / "SKILL.md").write_text("---\nname: probe\ndescription: Test skill\n---\n\nProbe.\n")
            rules = [{"action": "skill", "resource": "*", "effect": "deny"},
                     {"action": "read", "resource": "*", "effect": "allow"}]
            config = {"providers": {"probe": {
                "package": "@opencode/ai/providers/openai-compatible",
                "settings": {"baseURL": f"http://127.0.0.1:{model.server_port}/v1", "apiKey": "dummy"},
                "models": {"m": {}}}}}
            config.update({"permissions": rules} if scope == "config" else {"agents": {"build": {"permissions": rules}}})
            if not browser: config["plugins"] = ["-opencode.browser"]
            (root / "opencode.json").write_text(json.dumps(config))
            if os.environ.get("OC_BUNFIG"):  # running from source: the standalone child needs the TUI preload
                (root / "bunfig.toml").write_text(os.environ["OC_BUNFIG"])
            r = subprocess.run(cmd + ["run", "--standalone", "--auto", "--title", "Probe", "--agent", "build",
                                      "--model", "probe/m", "--format", "json"],
                               cwd=root, env=env, input="Hello", text=True, capture_output=True, timeout=90)
        first = model.requests[0] if model.requests else None
        print(scope, f"browser={browser}", f"exit={r.returncode}",
              f"skill_listed={first is not None and 'skill' in first}",
              f"read_listed={first is not None and 'read' in first}",
              f"denied={'Permission denied: skill' in r.stdout}")
        if first is None: print(r.stdout[-2000:], r.stderr[-2000:])
    
    cmd = shlex.split(os.environ["OC_CMD"]) if os.environ.get("OC_CMD") else [shutil.which("opencode")]
    with ThreadingHTTPServer(("127.0.0.1", 0), Model) as model:
        t = threading.Thread(target=model.serve_forever); t.start()
        try:
            for scope in ("config", "agent"):
                for browser in (True, False):
                    run(cmd, model, scope, browser)
        finally:
            model.shutdown(); t.join()

    Run it: python3 reproduce.py

  3. added
    status/repro-simulated
    on Nov 23, 2026
  4. self-assigned this
    on Nov 23, 2026
  5. ccclucky commented on Nov 23, 2026

    @ccclucky

    Root cause confirmed on dev (9a8a656e): Tool.whollyDisabled (packages/core/src/tool.ts) decides from the last rule matching the tool's action. The browser plugin appends { action: "skill", resource: "browser", effect: "deny" } after every agent's rules, so for a config skill: * deny the last match is that narrow rule and the tool is advertised again even though the wider rule denies every resource.

    The fix decides from the last resource: "*" rule for the action, and keeps the tool hidden unless a later rule allows some resource again. That keeps the existing ordered-wildcard cases (*: * deny then a narrow allow, and the reverse) and covers the narrower-deny case. packages/core tool-registry tests pass (51, including a new case for this shape) and bun typecheck is clean. PR to follow.

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

Metadata

Metadata

Assignees

Labels

area/coreplatform/macosstatus/repro-simulatedtype/bugversion/v2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions