Repository navigation
Share one sandbox bridge across Leaf copies, so plugin updates stop multiplying them - #5982
Merged
Merged
Conversation
…ultiplying them A bridge was keyed by the install it ran from, and each served every session registered with it for that session's whole lifetime: for a background job, until the job is deleted. Since #4557, `hooks.main` hands each hook to the session's delivering Leaf (the copy Claude Code installed since, or a selected checkout) before `cmd_hook` started the bridge, so every plugin update, one per commit on main, started another bridge, keyed by the newer copy. None of those could serve the session: a sandboxed bare `leaf` runs the client of the copy Claude Code loaded, which looks only for its own install's bridge. On a machine with many background jobs this left 85 bridges running, some 20 days old, about 1.85 GB in all. 79 stayed up for a job's registration. Each bridge's environment names the CLAUDE_PLUGIN_ROOT of the hook that started it: 78 were started by a copy the hook had been handed to. One job was registered with 19 bridges in under six days. Of the 70 installs still on disk, 68 ship the same `bridge.py`. Now: - `bridge.KEY` hashes `bridge.py` itself, so every copy that ships the same file, a newer plugin copy, a checkout run by path or a host launcher's, reaches one bridge. A copy that changes the file, and so perhaps its frames, starts its own. - A request carries the client's interpreter and the bridge runs it, so a command runs as the Leaf of the copy that sent it, whichever copy started the bridge. The token already let its holder choose a command's environment, so naming the interpreter adds no reach. - `hooks.main` opens the sandbox's road out before the hand-off, so the copy Claude Code loaded registers the session even where its `bridge.py` differs from the delivering Leaf's; the delivering Leaf registers too. - A registration is named by its session and lifetime, so two processes of one session, each living as its own pid, keep the bridge until both end; copies now share registrations, which made the overwrite more reachable. - `serve` loads the sweep's lifetime rule as it starts, since a shared bridge may outlive the install that started it, and a sweep that failed to import would leave it serving for good. A background job's next sitting on a worker that loaded a newer copy now reaches the bridge its earlier sitting kept, wherever `bridge.py` is unchanged, which the job lifetime promised and per-install keys did not deliver. Where `bridge.py` changed, a script run before that sitting's first hook still finds no bridge, as before.
leaf-agent
previously approved these changes
Nov 14, 2026
# Conflicts: # src/leaf/hooks.py
leaf-agent
approved these changes
Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every plugin update started another sandbox bridge that never retired. A bridge was keyed by the install it ran from and served each registered session for that session's whole lifetime, which for a background job lasts until the job is deleted. Since #4557 a hook hands itself to the newest installed copy before it starts the bridge, so each commit on main that a long-lived session lived through left one more bridge, none of which that session's sandboxed
leaf(the loaded copy's client) could reach. On Max's Mac this left 85 bridges, up to 20 days old and about 1.85 GB in all; 78 had been started by a copy the hook was handed to, and 68 of the 70 installs still on disk ship the samebridge.py.Now the bridge is keyed by a hash of
bridge.pyitself, so every copy that ships the same file shares one bridge, and a request carries the client's interpreter, which the bridge runs, so each command still runs as its own copy's Leaf. The hook registers the session before the hand-off as well as after it, so a loaded copy whosebridge.pydiffers still gets its bridge. Registrations are named by session and lifetime, so two processes of one session each keep the bridge, andserveimports the lifetime check at start, since a shared bridge can outlive the install that started it.To weigh: copies now share a wire contract, scoped by the file hash. A request naming its interpreter adds nothing to what the token already allowed, since the token holder already set each command's environment. Untested: a bridge outliving its own install; the eager import covers that case.
Independent review by Codex, two rounds; its first round rejected an earlier version that started bridges only from the copy Claude Code loaded. Tests:
tests/process/test_bridge.py, the hook model and registration tests,pnpm run check:browser; each new test fails with its part of the fix reverted.Requested by Max via a dispatched investigation into processes outliving their sessions.