Repository navigation
Decide agent writable folders per session; grant each thread only its own storage - #7994
Merged
Merged
Conversation
The server now sends each session's extra workspace folders to the daemon (empty for now). The daemon adds the workspace's git metadata, each extra folder's git metadata and the thread's own storage folder, and passes that list per thread instead of baking one list into the environment runtime. Agents are told their folders when there is more than one. - Thread storage: grant <root>/<threadId>, not the shared root (#7625) - Worktrees: grant <commonDir>/packed-refs and packed-refs.lock so ref deletion and stash pop work in the sandbox (#4488) - Claude Code: pass only existing directories to --add-dir; file roots stay in the sandbox allowWrite list - HOST_DAEMON_PROTOCOL_VERSION 277 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…manager test Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n resume Git deletes a packed ref by writing packed-refs.new and renaming it over packed-refs, so the shared git write roots now include packed-refs.new. Without it, Codex failed `git branch -D` on any packed branch. The thread's own storage folder is now created whenever its write roots are resolved, so resume and rewind recreate it after archive wipes storage, not only thread start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks done
k0d3r1s
added a commit
to valksor/vbb
that referenced
this pull request
Nov 24, 2026
Brings upstream get-bb#8006 (Android timeline text selection) and get-bb#7994 (per-session agent writable folders). Conflict resolution keeps the fork's protocol numbering at 286 with upstream's 277 incompatible, adopts the per-thread resolveThreadWorkspaceWriteRoots flow alongside the fork's MCP session binding in the daemon thread handlers, updates fork test fixtures for the new required additionalWorkspaceFolders and folders contract fields, and keeps both sides' bridge test fixtures.
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.
Human comments
What was wrong
The daemon built one list of extra writable folders per environment runtime (
runtimeWorkspaceWriteRootsinapps/host-daemon/src/runtime-manager.ts) and handed it to every provider process as static provider options. Because the list was per environment, it could not name a thread's own storage folder, so it named the shared<data-dir>/thread-storageroot instead (#7625). That let every thread write into every other thread's storage, and it showed Claude Code the root as an extra working directory. The git list for linked worktrees coveredobjects/,refs/andlogs/but not<commonDir>/packed-refs.lock, which git takes for every ref deletion, sogit branch -Dfailed andgit stash popleft a strayrefs/stash(#4488). The server had no way to add folders of its own, which multi-repo and non-git projects need.What changed
HOST_DAEMON_PROTOCOL_VERSION276 → 277. The thread runtime context (thread.start,thread.rewind.prepare,turn.submit/thread.goal.clearresumeContext) gains a requiredadditionalWorkspaceFolders: string[].host.read_workspace_agent_contextgainsfolderPathsand returnsfolders: {path, isGitRepo}[].thread-runtime-config.ts). It decides each session's extra folders. The list is empty in this PR, so these folders come later from project/environment folders. When it is not empty, the server asks the daemon whether each folder is a git repo and adds a "You are working across these folders" block to the instructions (workspace-folder-instructions.ts). Single-folder threads see no change: the RPC getsfolderPaths: []and no block is added.RuntimeManager.resolveThreadWorkspaceWriteRoots). For each session start, resume or rewind it builds the list from the workspace's worktree git roots, the server's folders, each extra folder's worktree git roots and the thread's own<thread-storage>/<threadId>folder, with duplicates removed.AgentRuntimeOptionsand the static adapter options to per-threadStartThreadArgs/ResumeThreadArgs/rewind args. They are stored in the thread's runtime config and sent inproviderOptions.additionalWorkspaceWriteRootson session start, turn start and steer. The wire key is unchanged, so no bridge needed a protocol change. Model listing and other provider-level calls no longer carry roots.<commonDir>/packed-refsand<commonDir>/packed-refs.lock.configandhooks/stay protected.session-options.ts).additionalDirectories(--add-dir) now gets only existing directories. File roots stay in the sandboxallowWritelist. Live testing showed that passingpacked-refs.lockthrough--add-dirstops theallowWritegrant from taking effect.Where this differs from the plan
claude -p --setting-sources … --settings <bb sandbox json>, the same--settingsJSON the Agent SDK builds from itssandboxoption) on Claude Code 2.1.325 and on the reporter's 2.1.259. WithallowWriteset in user settings (absolute path and~/Library/Caches) and in project settings, the user's path stayed writable alongside bb's roots every time. ReadingallowWritefrom settings files and merging it in would duplicate what Claude Code already does, and would risk changing how relative paths resolve. I suggest closing fix(provider-claude-code): SDK sandbox option drops the user's sandbox.filesystem.allowWrite #3034 as not reproducible.bwrap.rs:writable_roots.retain(... .exists()); sandbox-runtime: "Skipping non-existent write path"). So the new entries are harmless there but don't help. A Linux fix would need<commonDir>writable withconfig/hooksdenied, which Codex's legacysandboxPolicycan't express.gitWritableRootsForWorkspace(inplugins/provider-codex/src/session-params.ts) is not removed. It computes a subset of what the daemon now sends, so it never conflicts. Removing it is a separate simplification.How you verified
codex sandboxwith today's roots:git branch -Dfails withUnable to create '<commonDir>/packed-refs.lock': Operation not permitted, andstash popleavesrefs/stash.packed-refsandpacked-refs.lock: the branch is deleted,refs/stashis cleared, andconfigandhooks/are still denied.--add-dirbreak it.pnpm start:worktreefrom this branch (isolated dev data dir), with a Claude Code thread and a Codex thread, each in a new worktree environment:…/thread-storage/thr_f56qdzz4h7, the thread's own folder, which matches$BB_THREAD_STORAGE.git branch qa-tmp && git branch -D qa-tmpgivesDeleted branch qa-tmp.Deleted branch qa-tmp,stash-ref=[], its own storage folder is writable, andtouch <thread-storage>/other-thread.txtgivesOperation not permitted.runtime.command-contract.test.ts: two threads in one runtime get different roots onthread/start, andturn/startcarries the thread's own roots.runtime-manager.test.ts: per-thread storage folder, git roots for the main and extra worktree folders, duplicates removed.workspace-agent-context.test.ts: git status for a plain folder, a repo, a subfolder of a repo and a missing folder.workspace-folder-instructions.test.ts: the folders block.thread-runtime-config.test.ts: single-folder threads unchanged.--add-dir, and every root goes toallowWrite.pnpm exec turbo run typecheckfor@bb/agent-runtime,@bb/host-daemon,@bb/server,@bb/host-daemon-contractandbb-plugin-provider-claude-code. Targetedturbo run testfor those packages and@bb/host-workspace(full@bb/agent-runtimeunit suite).turbo run linton the touched packages.Fixes #7625
Fixes #4488
🤖 Generated with Claude Code