The attach grant is a stored session rule, but its revoke runs only from the
plugin's finalizer. After SIGKILL, a crash or a stop timeout, the session kept
browser:* and skill:browser allows with no attachment behind them, so the next
server listed the browser tools and every call failed with
[browser.disconnected].
Each grant is now recorded in plugin storage with the server process that wrote
it (host and process ID) and its location, before the grant is written; a
successful revoke removes the record. When the plugin starts for a location, and
before it registers the browser RPC so no attach can race it, it revokes the
grants recorded for that location by a process that no longer runs.
Several server processes can share one database (a desktop's server and a
manual `opencode serve` both use opencode.db), so a sweep of every session in
the location could revoke another server's live grant. The sweep skips records
of a running process and of another host, which cannot be checked. Grants
written before this change have no record and are left alone; the next attach
and detach of their session removes them.
The startup sweep before RPC registration, its location scoping and ignoring
per-session failures come from #61639.
Fixes#61609
Co-authored-by: Chen Yufeiyang <fei76161@gmail.com>
A child session copies its parent's permissions, so a subagent spawned from an
attached session got the browser:* and skill:browser allows but no attachment.
It listed the browser tools and the Browser skill, every call failed with
[browser.disconnected], and the copied allow outlived the parent's attachment.
The plugin now revokes the grant from a child session while the child's prompt
is admitted (session prompt hook), before any step of the child can list the
tools, so there is no race with its first step. It holds the attachment lock
while it checks and writes, and skips a child that has an attachment of its own.
A subagent whose agent denies the browser stays denied even when the desktop
attaches to it, through the check from the previous commit.
Refs #61238
Attaching a desktop browser writes browser:* and skill:browser allows into the
session's permissions. Session rules are evaluated after agent rules, so the
grant overrode a browser deny from config, an agent definition (for example a
"*" deny) or the session itself. Browser tools never called the permission
check either, so tool.use policies did not apply.
The plugin now records each agent's rules before it appends its own default
deny. A browser call is refused when those rules, plus the session's rules
without the grant, deny the browser, decided the way core's tool filter decides.
The call then runs the permission check with the operation as its resource, so
permission.evaluate hooks such as tool.use policies apply. Sessions without a
deny behave as before: the grant allows the check, so nothing prompts.
Refs #54044, #53294, #56869