Summary
A session that once had a desktop browser attached keeps all 45 browser.* tools after the OpenCode server is killed hard and restarted. No browser is attached after the restart, so every call fails with [browser.disconnected]. A normal SIGTERM shutdown removes the grant; SIGKILL (including systemd killing the service after its stop timeout) does not.
Where the tools come from
This is an OpenCode/desktop integration, so the moving parts matter:
- The agent server is OpenCode 2.2.5. T3 Code is the desktop client; the server runs under systemd.
browser.* is registered by OpenCode's built-in opencode.browser plugin (packages/plugin-browser/src/index.ts), not by T3 Code. BrowserTools.register adds each operation with namespace: "browser" and permission: "browser" (packages/plugin-browser/src/tools.ts).
- T3 Code's own preview automation is a separate namespace (
t3_preview_*). Its "Agent browser access" setting only gates those tools; turning it off leaves browser.* listed.
- The desktop client attaches a browser to a session through the
experimental.browser/attach RPC. BrowserConnection.attach keeps the attachment in memory (browsers) and calls grant(sessionID), which appends { action: "browser", resource: "*", effect: "allow" } and { action: "skill", resource: "browser", effect: "allow" } to the session's permissions (packages/plugin-browser/src/connection.ts).
- Tool visibility is decided by
whollyDisabled in packages/core/src/tool.ts: the last matching permission rule wins. The plugin appends an agent-level deny to every agent, so the namespace is hidden unless the session has a later allow.
The grant is persisted session state; the attachment is in-memory state. They can diverge.
Steps to reproduce
- Start
opencode serve and create a session.
- Call
experimental.browser/attach for that session, the way the desktop pane does. The session permissions gain the two allows.
kill -9 the server and start it again.
- The
state RPC reports no attachment, but the session still has both allows and lists all 45 browser.* tools. Calling one fails with [browser.disconnected].
With SIGTERM instead of SIGKILL, the allows are removed and the namespace disappears.
A complete repro.sh is in the comment below.
Cause
grant() is an Effect.acquireRelease inside the attach handler's scope. The release removes the allows when the attachment scope closes: a normal client detach, close(), or the plugin finalizer on shutdown. SIGKILL/crash never runs it. The allow is stored on the session; the attachment is not. After restart browsers is empty, but the stored allow is still the last matching rule, so the tools remain visible.
Why this is an OpenCode issue
OpenCode writes, stores, and interprets the permission rules. T3 Code does not write browser:*; its setting cannot remove it. The client only calls attach/close. A clean T3 Code shutdown would avoid the trigger, but the invariant would still be wrong: a crash can leave a session advertising tools for an attachment that no longer exists. The server-only repro in the comment shows the bug does not depend on T3 Code.
Suggested fix
Pick one:
- decide availability from the live attachment (
browsers.has(sessionID)) instead of only from stored rules;
- reconcile on startup: drop
browser:* / skill:browser allows for sessions with no attachment;
- persist attachment state so a restart either reattaches or revokes the grant.
Revoking the session allow when the attachment goes away would likely also cover #61238.
Related
#54044 (session allow overrides an explicit agent deny), #61238 (subagents inherit the grant), #55795 (tools listed with no attachment).
Environment
T3 Code 0.1.8-nightly.20261104.4165, OpenCode 2.2.5, Linux/Wayland, server as a systemd service, no desktop browser attached to the session when the report was made.