Repository navigation
Description
What happened
On 2026-09-03 at dev@9b996edb, the task engine can hold two contradictory truths at once:
Project working directory: <session>/trees/1
WHAT TO PRODUCE
<source-checkout>/internal/widget.go
<source-checkout>/internal/widget.go is outside your copy — this task works in <session>/trees/1; read anywhere, write only there.
The isolation itself is correct: prepareTaskTreeOn cuts a private worktree and newTaskAgentOn gives that directory to the worker as Config.Workspace. The contract is not rebound to that directory. A parent follows prompts/system.md's absolute-deliverable rule using its Project working directory, groundLint treats that source-checkout path as evidence for the ground, and composeBrief later hands the same absolute path to a worker whose Project working directory is the private worktree.
That sends the worker to read the changing source checkout rather than its frozen copy. When it follows the same address for an edit, taskGroundGuard correctly rejects it as outside your copy. The guard is doing its job; the task handoff gave the worker an impossible contract.
This is a logic bug in path/context construction, not a reason to weaken isolation. Every task continues to get its own worktree unless the person explicitly requests otherwise. A task must never be redirected to write in the person's checkout just because a generated brief or deliverable names that checkout.
Replication
Deterministic (no model).
Add a fixture test named TestAWorktreeTaskBindsContractPathsToItsPrivateCopy in internal/session. It uses only newTestRepo, scriptedCompleter, and the real task doors:
- Make a temporary source repository containing
internal/widget.gowithold\n, and aPlacewith its own session directory. - Submit through
Agent.Submita scriptedpropose_taskwhosegroundis the source repository and whose model-authoredbrief,deliverable, andacceptancename the absolute source path tointernal/widget.go—the shape the parent prompt currently asks for. - Let
prepareTaskTreeOncreate the node's private worktree. After it is cut, change the source checkout's file tonew-in-source\nso the two directories are observably different. - Capture the worker's opening request through the scripted worker provider, then let the worker follow the contract with a
readandeditat the address it was given.
Run:
go test ./internal/session -run TestAWorktreeTaskBindsContractPathsToItsPrivateCopy -count=1Expected today: the captured contract still contains <source-checkout>/internal/widget.go; the read observes new-in-source, and the edit result contains is outside your copy — this task works in <session>/trees/1.
Expected after the fix: the worker-facing contract resolves that target to <session>/trees/1/internal/widget.go; the read observes old, the edit succeeds in the private worktree, and the source checkout does not change until the normal landing road runs.
Field (real models).
With OPENROUTER_API_KEY, run the real TUI from a disposable fixture repository and ask it to hand off one edit while naming the repository's absolute path in the requested output. The failure fires when the parent repeats that absolute source path in brief or deliverable: the task card correctly shows a private trees/<id> worktree, while the worker reads the source path and its first attempted write there gets the exact outside your copy refusal. Budget one task run. The deterministic fixture is authoritative; no owner's private logs are needed.
Where
- Parent-side absolute deliverable instruction:
internal/session/prompts/system.md(searchDELIVERABLES ARE FILES). - Proposal contract and the distinct
where/groundmeanings:internal/session/task.go(searchGROUND AND WHERE ARE TWO QUESTIONS). - Contract path inference:
groundLintininternal/session/taskstands.go. - Worker-facing contract composition:
composeBriefininternal/session/task_brief.goandTaskNode.instructionininternal/session/task_run.go. - Private worktree construction and worker workspace:
prepareTaskTreeOnandnewTaskAgentOnininternal/session/task_run.go. - The correct final safety net:
taskGroundGuardandoutsideGroundRefusalininternal/session/taskoutside.go.
The fix
A worktree task has one worker-facing path namespace: its private worktree.
- Preserve the source repository as the node's
Ground; that is provenance and the landing target, not the directory the worker should operate in. - Before the first worker call, bind any generated contract path at or below that ground to the equivalent path in the actual task worktree. The worker may still see the source ground as labelled provenance, but it must not be described as its working or deliverable directory.
- Keep the person's own words verbatim. If their message names the source path, the handoff must state the source-to-copy mapping authoritatively rather than silently changing their quote.
- Keep
taskGroundGuardstrict. Do not solve this by allowing source-checkout writes, by running the task in the shared checkout, or by copying changes into the person's folder during the run. - Apply the same binding to nested task families: each child resolves inherited ground-relative targets against its own private worktree, not its parent's mutable directory or the original source checkout.
This closes the seam left between #77 (ground/brief lint) and #78 (outside-ground guard): the former chooses what the copy is of, while the worker handoff must say where that copy actually is.
Acceptance
- e2e: through
Agent.Submit→propose_task→workTaskNodewith scripted parent and worker providers, an absolute target beneath the source ground is presented to the worker at the equivalent path beneath its realtrees/<id>worktree. After the source file is changed post-carve, the worker'sreadreturns the worktree's originaloldcontent, itseditsucceeds, and no result containsis outside your copy. - e2e: in the same fixture, the source checkout remains byte-identical throughout the worker run and changes only when the task's ordinary landing is accepted; the task ends
doneand its notice keepsGround=<source-checkout>,Where=<session>/trees/<id>, andMode=worktree. - e2e: a nested child whose inherited contract names a ground-relative absolute target reads and edits its own child worktree; neither the parent worktree nor the source checkout changes before that child's normal landing.
- Unit: worker-facing path binding maps the ground itself and descendants to the actual worktree, preserves relative suffixes, does not rewrite unrelated absolute paths, and cannot turn an outside path into an allowed write.
- Structural: every ordinary task worker is constructed with a workspace distinct from its repository ground; only explicit person-authored in-place placement may bypass that rule.
- The manual page that covers task copies says that absolute project paths in a handed-off contract resolve inside the task's private copy, and the change entry's
invalidatesnames the old belief that the contract's absolute source path was safe for a worktree worker to follow.
Drafted with CodeAF · reviewed and owned by the author
Activity
e2e: the two contract shapes, on a real model, before and after (#566, …
session: a task's contract is written in the addresses of its own copy (
e2e: the two contract shapes, on a real model, before and after (#566, …
session: a contract is written in the worker's own copy, and a check …
A later task is not pointed at an earlier task's copy (#839) (#847)