Skip to content

Git worktrees: three tools, subagents that run in their own checkout, sessions that remember where they worked - #612

Merged
FMXExpress merged 7 commits into
mainfrom
claude/opencode2-e-worktree
Oct 23, 2026
Merged

FMXExpress merged 7 commits into
mainfrom
claude/opencode2-e-worktree

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

PR E of docs/opencode2-plan.md. Targets main. It depends on #611 (permissions): worktrees add resource mappings to PasClaw.Permissions, the file #611 creates. So until #611 merges, this diff shows permissions + worktrees; once #611 is in, it is worktrees alone. Merge #611 first.

What

Two subagents editing the same tree collide: one's half-finished edit is the other's compile error. git's answer is a worktree, and PasClaw had no git awareness beyond stopping the AGENTS.md walk at .git.

  • Three tools in PasClaw.Tools.Worktree: worktree_create(branch, base?), worktree_list, worktree_remove(path, force?). Every git call goes through the active shell backend, so Docker and the denylist apply as they do to shell_exec. Worktrees live under worktree.directory or, by default, beside the repository in <repo>-worktrees/<branch>. create is idempotent; remove refuses a dirty worktree unless force, never removes the main checkout, and prunes a stale registration. Shell-shaped branch names are refused before they reach the command.
  • Subagents take a worktree. spawn / spawn_background accept worktree: "<branch>". The worktree is created on the parent's thread before the child starts (a git failure is the spawn's error). The child's loop config carries a new Workspace, and DispatchOneToolCall sets it as the thread's sandbox workspace around every dispatch, loop thread and parallel workers alike, restoring it after. CurrentWorkspace, ResolveWorkspacePath, the read/write boundary and the shell cwd all follow it, so a relative fs_write lands in the worktree and under restrict_to_workspace the child's boundary is the worktree. The parent's threads never see it.
  • Sessions remember their location. TSessionMeta.Location is stamped with the sandbox workspace on first save. session list shows it, session show prints it, and pasclaw resume makes it the workspace again when it still exists.
  • Registered when worktree.enabled (default true). false takes away the whole feature — the three tools and the worktree argument on spawn*. worktree_create / worktree_remove carry a resource (branch / path) for the permissions list, so {"tool":"worktree_remove","effect":"ask"} works.

Review fixes

P1 — under the Docker backend a worktree was built where the host could not see it. The worktree tools run git through the backend, and under Docker the container mounted the workspace and nothing beside it — while the default worktree directory is beside it. git worktree add built the checkout in the container's filesystem, registered it in the host's .git (which is mounted), and the host got back a path with nothing in it.

git stays in the backend. Running it on the host instead would be a sandbox escape: fs_write runs on the host, so a model can put a .git/hooks/post-checkout or a smudge filter into .git/config, and a host-side git worktree add runs either outside the container. Instead:

  • the container bind-mounts the worktree directory at the same path (WorktreeMountFor), unless it is already under the workspace mount, the feature is off, or the workspace is not a repository. The repository is found with FindRepoRootOnDisk, a walk up for .git — no git process, since the answer is needed while the container is still being built. POSIX only.
  • WorktreeCreate checks the host can see what git made, and if not refuses it and undoes everything the call made through the same backend: the registration, a prune, and the branch if this call created it (one that already existed is kept). That covers what the mount cannot — Windows, an unusual layout, a stale container.
  • the default image (debian:bookworm-slim) ships no git, which used to be reported as "not inside a git repository"; it now says git is missing where commands run.

The cost, documented in docs/security.md: with the default location, a Docker session in a git workspace creates an empty <repo>-worktrees/ beside the repository when the container starts. worktree.directory inside the workspace avoids it; worktree.enabled: false avoids all of it.

P2 — worktree.enabled:false only took away one door of three. spawn and spawn_background still advertised a worktree argument and still created a branch and a checkout when it was passed. WorktreeArgEnabled now gates both handlers, which refuse the argument, and both schemas, which stop offering it.

P2 — spawn_background created the worktree before checking the job cap. The slot is now reserved under the lock (FReserved, counted by SlotsInUse; shell_background's cap check counts it too), the slow git work runs outside the lock, and the reservation becomes the job or is handed back. spawn had the same shape with its cheap checks; EnsureWorktree now runs after every check that can reject the call.

Merge with the updated base

main (via #611's branch) is merged in. Three conflicts: docs/configuration.md; ResourceOf in PasClaw.Permissions (worktree_remove is covered by #611's generic path fall-through, worktree_create keeps a named case for its branch); and the spawn_background registration (#619's structure kept, the worktree property now conditional).

Tests

worktree_tests (make test-worktree) against a temp repository: the pure helpers, create / list / remove, idempotence, dirty refusal and force, the main-checkout refusal, shell-shaped names, the tool handlers, the per-thread override, the dispatch bracket, and a spawn whose child's relative fs_write lands in the worktree.

Added with the review fixes, each negative-verified by reverting it:

  • a worktree the host cannot see: a backend whose view of the worktree directory is not the host's (every command run on the host with that directory rewritten — what a container that does not mount it is). A new branch is refused with no registration, no branch and no backend-side checkout left; an existing branch is refused and unregistered but kept. Reverting the check fails on the refusal; reverting only the rollback fails on the registration left behind.
  • the Docker mount, read off the docker run argv without a daemon: none for a non-repository, <repo>-worktrees at the same path for a repository, not twice when worktree.directory is inside the workspace, none with the feature off. Reverting the mount fails; reverting the expanded path comparison fails on "not twice".
  • the flag: with worktree.enabled:false neither spawn tool offers or accepts the property, and nothing is created.
  • refused spawns: an unknown agent, no prompt, or spawn_background at a cap of 1 each leave no worktree and no branch.

Docs

docs/tools.md ("Git worktrees", worktree on spawn*, the flag, refused spawns, Docker and git), docs/configuration.md, docs/security.md ("Worktrees move the boundary", now with why git stays in the container and the mount), docs/sessions.md, docs/agent-features.md.


🤖 Generated with Claude Code

https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U

…surface, a policies file

PR D of docs/opencode2-plan.md. PasClaw had four unrelated gates --
plan mode's refusal of mutating tools, the sandbox denylist and path
rules, the family switches, the component's BeforeToolCall hook -- and
none of them let an operator say the ordinary thing: "ask me before
shell_exec, but git status and git diff are fine, and git push is
never fine". This adds that, in the shape OpenCode 2.0 settled on.

config.json "permissions" is an ordered list of {tool, resource?,
effect}. tool is a glob over the tool name; resource is a glob over the
call's primary resource (the command for shell tools, the path for file
tools, the url for fetch tools, the script for execute_code). The last
matching rule wins; no match means no opinion, so an empty list changes
nothing. PermissionGate runs in DispatchOneToolCall after the mode
gates and before preflight. deny lands in ResultText like the mode
refusals, naming the rule and telling the model not to retry. ask
blocks the dispatching thread on the loop config's OnAsk until a human
answers: allow once, allow for this session (remembered under the
session key for that tool + resource), or deny. With no asker wired --
a cron run, a piped agent, a gateway with no web UI connected -- an ask
rule denies. It never quietly becomes allow.

The askers: the Delphi TUI parks the request and shows it in the
footer (Y once, S session, anything else deny) while the loop thread
waits on an event; the FPC line TUI and the CLI REPL read one line on
stdin; the gateway publishes a permission_request desktop event and
waits for POST /v1/permissions/<id> (GET /v1/permissions lists what is
pending; no subscriber on the event feed means deny at once); the
TPasClawAgent component fires OnAsk on the dispatching thread.
permissions_ask_timeout_sec (300) bounds every wait.

<home>/policies.json holds a second list of the same shape. It is
evaluated first: a policy deny is final, a policy ask outranks a config
allow. PUT /v1/config writes config.json only, so a web UI session can
edit its own rules but cannot loosen the policies. The file is re-read
when its mtime moves, so an operator edit lands without a restart.

The rules live as a locked process-global in PasClaw.Permissions
(dispatch happens on loop threads and parallel workers) and are
installed by ApplyConfigGlobals, which every LoadConfig runs.
`pasclaw permissions list` prints both lists in evaluation order;
`pasclaw permissions test <tool> [resource]` prints the decision and
the rule that made it.

Tested in permissions_tests: glob semantics, ResourceOf per tool
family, last-match-wins with tool-only and resource rules, parse and
JSON round-trip with bad effects skipped, Decide precedence across the
two lists, the policy file appearing, changing and disappearing by
mtime, session allows per key and resource, and the dispatch gate
through MakeLoopDispatcher: deny never runs the handler, ask with no
asker refuses, an asker's deny / allow once / allow session behave,
and the plan-mode refusal still comes first.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
… sessions that remember where they worked

PR E of docs/opencode2-plan.md. Two subagents editing the same tree
collide: one's half-finished edit is the other's compile error. git's
answer is a worktree, and PasClaw had no git awareness beyond stopping
the AGENTS.md walk at .git.

PasClaw.Tools.Worktree adds worktree_create(branch, base?),
worktree_list and worktree_remove(path, force?). Every git call goes
through the active shell backend, so Docker and the denylist apply as
they do to shell_exec. Worktrees live under worktree.directory or, by
default, beside the repository in <repo>-worktrees/<branch>, so a git
status in the main tree never shows them. create is idempotent (an
existing worktree for the branch is returned), which is what a parent
that spawns the same branch twice wants; remove refuses a dirty
worktree unless force is set, never removes the main checkout, and
prunes a stale registration. Branch names that look like shell are
refused before they reach the command.

spawn and spawn_background take worktree:"<branch>". The worktree is
created on the parent's thread before the child starts, so a git
failure is the spawn's error. The child's loop config carries
Workspace, and DispatchOneToolCall sets it as the thread's sandbox
workspace around every dispatch -- loop thread and parallel workers
alike -- and restores the previous value after. CurrentWorkspace,
ResolveWorkspacePath, the read/write boundary and the shell cwd all
follow it, so a relative fs_write lands in the worktree and under
restrict_to_workspace the child's boundary is the worktree. The
parent's threads never see it: it is a threadvar, and the bracket
restores it. The child's prompt says which worktree and branch it is
in; the result is prefixed with the path so the parent knows where the
work is.

TSessionMeta.Location records the sandbox workspace at a session's
first save. session list shows it after the title, session show prints
it, and pasclaw resume makes it the workspace again when it still
exists, so a session resumed from $HOME keeps editing the tree it
started in.

The tools register when worktree.enabled (default true) on the CLI,
the TUI and the component; worktree_create / worktree_remove carry a
resource (branch / path) for the permissions list.

Tested in worktree_tests against a temp repository: BranchDirName and
WorktreeBaseDir, create / list / remove, idempotent create, the dirty
refusal and force, the main-checkout refusal, shell-shaped branch
names, the tool handlers through the registry, the per-thread override
(a worker sees it, the main thread does not), the dispatch bracket
(the handler sees Cfg.Workspace, the caller is restored), and a spawn
with a worktree whose child's relative fs_write lands in the worktree
and not in the parent tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T08:08:25.582705Z 6a18221 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a1822129b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Cmd: string;
begin
Cmd := 'git ' + Args;
Result := RunOneShotViaBackend(GetCurrentSessionId, Cmd, WorkDir, Output);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Run worktree management in the host filesystem

When shell_backend=docker, routing these Git commands through the active backend splits the checkout across filesystem namespaces. TDockerShellBackend.SpawnContainer only bind-mounts the configured home workspace, while the default worktree directory is its sibling <repo>-worktrees; consequently git worktree add creates the checkout inside the container while this function returns the corresponding host path, which is empty or nonexistent, and may leave the host repository registered to a container-only worktree. Execute repository-management Git on the host or explicitly mount and map the worktree directory before returning it.

Useful? React with 👍 / 👎.

Comment on lines +475 to +476
if Worktree <> '' then
if not EnsureWorktree(Worktree, WorkDir, WtErr) then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the worktree feature flag in spawn handlers

With worktree.enabled:false, callers omit only the standalone worktree_* tools; spawn and spawn_background remain registered and their handlers still unconditionally accept worktree, so a model can create branches and checkouts despite the documented opt-out. Gate the argument and EnsureWorktree call on FCtx.Cfg.Worktree.Enabled (and ideally stop advertising the schema property when disabled) in both handlers.

Useful? React with 👍 / 👎.

Comment on lines +725 to +726
if Worktree <> '' then
if not EnsureWorktree(Worktree, WorkDir, WtErr) then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the background-job cap before creating a worktree

When the coordinator is already at MaxJobs, this call creates the requested branch/worktree before acquiring the lock and checking RunningCount, then returns the capacity error without starting a job. Thus an ordinarily rejected spawn still mutates the repository and consumes disk; reserve/check capacity before EnsureWorktree, or remove the newly created worktree when the request is rejected.

Useful? React with 👍 / 👎.

Four conflicts, all from both sides touching the same lines:

  Makefile / docs/configuration.md -- this branch's new rows and target
  sit where #608's tree-kill rewording landed. Kept both.

  PasClaw.Config.pas -- ApplyConfigGlobals: main renamed the shell
  timeout setter to SetShellToolTimeoutMs, this branch added the
  permission-rule wiring right beside it. Kept both.

  PasClaw.TUI.pas -- TTUI.Destroy. #610 moved FBgFlashLock.Free to the
  end (after the thread hand-off) and this branch had added the ask
  state's Free beside it at the top. Resolved by not freeing the ask
  lock or event at all: a worker parked in AskPermission leaves it
  within a poll slice of FQuit, but the bounded wait hands the thread to
  FreeOnTerminate after the same 250 ms, so Destroy cannot know it has
  left -- the same reasoning the file already records for
  FToolActivityLock.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
…reach every tool, one prompt at a time

Four review findings, all P1, all confirmed.

**A policy file that could not be read left no policy denies at all.**
ReadPoliciesLocked cleared the rule list up front and then returned
early on every failure -- missing, unreadable, truncated, not JSON, no
"permissions" array -- so a policies.json being rewritten
non-atomically left the process with nothing enforced for the length of
that window. Worse, RefreshPolicies had already consumed the mtime, so
a recovery write landing in the same filesystem timestamp looked
identical to the bad one and the empty state became permanent. The file
a team gateway owns is exactly the file that gets rewritten under a
running agent.

Now the rules are replaced only after a successful read, and only a
file that is GONE clears them (an empty array clears them too -- that
is a file saying so). An unusable read keeps what is in force, counts
itself, and says so in the log; `permissions list` warns that what is
in force is not what is on disk. The change stamp is mtime AND size,
because size is what lets the recovery be seen inside one timestamp.
Telling `[]` apart from a truncated array needs the array to have
parsed, so that is checked before the (possibly empty) parse result is
trusted.

**Resource-scoped rules did not reach the search tools.** ResourceOf
mapped a hard-coded list of file-tool names, which went stale the moment
the Glob/Grep pair landed: grep_files and find_files both take a path,
neither was listed, so a policy denying `/etc*` for every tool did not
match grep_files({"path":"/etc"}) and the search went ahead on whatever
the sandbox allowed. A list of names has to be revisited by whoever adds
a tool -- including an MCP server, whose tools nobody here will ever
name -- and nothing makes them. The named special cases stay (command
for the shell tools, code for execute_code, url for the fetch tools) and
everything else now reads its `path`, else `url`, else `command`. That
is shorter than the list it replaces and cannot go stale.

apply_patch is the one real gap left and no field closes it: its paths
are inside the patch body, several of them, and a glob over that text
would match by accident as often as on purpose. Scope it by tool; the
sandbox's path rules still bound where it writes. Said so in the code
and in the docs.

**Two parallel asks shared one prompt, on both console surfaces.** Tool
calls dispatch in parallel, so one batch can hold two ask-gated calls.
The TUI kept a single pending slot and one manual-reset event: the
second request overwrote the first, and one keypress woke both waiters
with the same answer -- approving a call the operator never saw. The CLI
had two threads printing to one terminal and calling ReadLn on one
stdin, so the line meant for the prompt on screen could be consumed by
the other thread.

Both now hold BeginInteractiveAsk/EndInteractiveAsk for the whole of one
ask, so requests are presented in turn and an answer always belongs to
the request that was shown. The gateway deliberately does not take the
turn: its requests carry ids, each has its own event, and the web UI can
answer several individually -- that surface was already correct.

**Not in the review:** TTUI.Destroy freed FAskLock and FAskEvent. A loop
thread parked in AskPermission leaves within a poll slice of FQuit, but
the bounded wait above hands the thread to FreeOnTerminate after the
same 250 ms, so Destroy cannot know it has left -- freeing the event it
may be waiting on is the use-after-free the hand-off is designed around.
They are left alone now, like FToolActivityLock, with the reasoning
recorded next to it.

Tested (test-permissions), each fix negative-verified by reverting it:

  - a truncated, empty or wrong-shaped policy file keeps the rules in
    force; `[]` and deleting the file clear them; the recovery write is
    adopted with no sleep between writes, which only works because the
    stamp includes the size. Reverting the clear-up-front fails on the
    truncated case; reverting the size half fails on the stamp.
  - ResourceOf for grep_files, find_files, the whole file family and its
    fs_* aliases, kb_get, an unknown MCP-shaped name, url and command
    fall-through, and nothing for a tool with none of them; plus the
    review's own scenario end to end (deny `/etc*` for `tool:"*"` now
    denies grep_files on /etc and still allows /home/me).
  - two threads taking the ask gate five times each never overlap;
    reverting the gate to a no-op reports nine overlaps.
  - both console askers are checked to hold the gate, since neither can
    be driven from a test (one paints a footer and answers from a key
    handler, the other blocks in ReadLn). The check strips comments
    first, so a comment that names the call cannot satisfy it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
…lag, and refuse before touching the repo

This branch now targets main. It brings in the updated #611 branch,
which carries main -- #609 code mode and #619 background jobs, both
merged -- so the PR's diff against main is permissions plus worktrees
until #611 lands, then worktrees alone. Worktrees depend on #611: they
add resource mappings to PasClaw.Permissions, the file #611 creates.

Three conflicts:

  docs/configuration.md -- this branch's worktree rows sat where main
  reworded shell_timeout_sec. Kept both, and said that
  worktree.enabled:false takes the spawn argument away too.

  PasClaw.Permissions.pas, ResourceOf -- this branch added
  worktree_remove/worktree_create cases to the old name list that #611
  replaced with a generic path/url/command fall-through. worktree_remove
  takes a `path`, which the fall-through already reads; worktree_create
  is named by its `branch`, which no generic field covers, so it keeps a
  named case.

  PasClaw.Agent.SubagentBg.pas, the spawn_background registration --
  #619 put it inside `if Length(Specs) > 0` so the shell tools survive
  subagents being off; this branch added a `worktree` schema property.
  Kept #619's structure; the property is now conditional (below).

And the two review findings, both P2, both real:

**worktree.enabled:false only took away one door of three.** Callers
dropped the worktree_* tools, but spawn and spawn_background still
advertised a `worktree` argument and still created a branch and a
checkout when it was passed. WorktreeArgEnabled (a nil Cfg reads as the
documented default, on) now gates both handlers, which refuse the
argument with a message saying how to proceed, and both schemas, which
stop offering it.

**spawn_background created the worktree before checking the job cap.**
A spawn the cap was always going to refuse still made a branch and a
checkout on disk, then returned the capacity error. Checking first is
not enough by itself -- two spawns in one parallel batch would both pass
and both create -- so the slot is reserved under the lock (FReserved,
counted by SlotsInUse alongside running jobs, and shell_background's cap
check counts it too), the slow git work runs outside the lock, and the
reservation becomes the job or is handed back on failure.

spawn had the same shape with its cheap checks: an unknown agent or an
empty prompt made a worktree on its way to being refused. EnsureWorktree
now runs after every check that can reject the call.

Tested (test-worktree), each fix negative-verified by reverting it:

  - with worktree.enabled:false, neither spawn nor spawn_background
    offers the property, both refuse it, and no directory or branch
    appears; with it on, spawn offers it again. Reverting the gate fails
    on the schema assertion.
  - spawn with an unknown agent or no prompt, and spawn_background at a
    cap of 1 held by a running shell job, each leave no worktree
    directory and no branch. Reverting the reservation fails on the cap
    case. Reverting spawn's ordering fails too -- on the flag test first,
    since the reverted order also runs ahead of the flag check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@FMXExpress
FMXExpress changed the base branch from claude/opencode2-d-permissions to main October 23, 2026 05:32
…eckout the host cannot see

The worktree tools run git through the active shell backend. Under
Docker that is the container, which mounted the workspace and nothing
beside it -- and the default worktree directory IS beside it,
<repo>-worktrees. So `git worktree add` built the checkout in the
container's own filesystem, registered it in the host's .git (which is
mounted), and WorktreeCreate returned the host path, where there was
nothing. A subagent then ran in an empty directory and the repository
was left pointing at a checkout only a container had. (Codex P1 on
#612.)

git stays in the backend. The review offered running it on the host
instead, and under Docker that would be a sandbox escape: fs_write runs
on the host, so a model can put a .git/hooks/post-checkout or a smudge
filter into .git/config, and a host-side `git worktree add` runs either
outside the container. Routing every git call through the backend is
what keeps Docker's isolation meaning something here.

So the container mounts the worktree directory instead, at the same
path, so its checkout and the host's are one:

  - TDockerShellBackend.BuildRunArgv bind-mounts WorktreeMountFor(the
    workspace) -- unless it is already under the workspace mount, the
    feature is off, or the workspace is not a repository. POSIX only; a
    same-path mount cannot hold a C:\ path.
  - WorktreeMountFor finds the repository with FindRepoRootOnDisk, which
    walks up for a .git entry rather than running git: the answer is
    needed while the container git would run in is still being built.

And the host checks what it was given. After `git worktree add` says
yes, WorktreeCreate looks for the checkout's .git file on the host; if
it is not there the worktree is refused and everything the call made is
undone through the same backend -- the registration, a prune, and the
branch if this call created it (one that already existed is kept). That
covers what the mount cannot: Windows, an unusual mount layout, a stale
container started before the mount existed.

The cost, documented: with the default location, a Docker session in a
git workspace creates an empty <repo>-worktrees/ beside the repository
when the container starts (the mount source has to exist, or Docker
makes it as root). worktree.directory inside the workspace avoids that;
worktree.enabled:false avoids all of it.

Also: the default Docker image ships no git, and GitRepoRoot then failed
the same way as for a directory outside any repository, so the message
said "not inside a git repository". It now probes `git --version`
through the backend on that failure path and says git is missing where
commands run.

Tested, each part negative-verified by reverting it:

  - worktree_tests: a backend whose view of the worktree directory is
    not the host's (every command run on the host with that directory
    rewritten to another one -- what a container that does not mount it
    is). A new branch: refused, no registration, no branch, no
    backend-side checkout left. An existing branch: refused and
    unregistered, branch kept. Reverting the check fails on the refusal;
    reverting only the rollback fails on the registration left behind.
    Plus FindRepoRootOnDisk / WorktreeMountFor directly.
  - shell_backend_tests: the `docker run` argv, without a daemon. Not a
    repository: no mount. A repository: <repo>-worktrees mounted at the
    same path. worktree.directory inside the workspace: not mounted
    twice. worktree.enabled:false: none. Reverting the mount fails;
    reverting the expanded path comparison fails on "not mounted twice"
    -- the workspace path can be relative (PASCLAW_HOME is), the mount
    never is, and the first cut compared them as written.

The mount test also cleans up before it runs, not only after: a failed
assertion is a Halt, which skips the finally, and a config.json left by
a previous failure changed what the next run saw.

Not fixed here, noticed on the way: the Docker backend's existing
workspace/tmp/run mounts pass PASCLAW_HOME through unexpanded, and
Docker reads a relative bind source as a volume name. Pre-existing and
only reachable with a relative PASCLAW_HOME.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@FMXExpress
FMXExpress merged commit 11a93dd into main Oct 23, 2026
FMXExpress pushed a commit that referenced this pull request Oct 23, 2026
#611 (permissions) and #612 (worktrees) are both in main now, so this
PR's diff against main is attach mode alone.

One conflict, docs/configuration.md: this branch's cli.attach row sat
where main reworded shell_timeout_sec (the tree-kill wording). Kept
both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants