Skip to content

Confine worker writes to worktree + main-tree tripwire - #160

Merged
w4ffl35 merged 1 commit into
masterfrom
fix/worker-write-confinement
Oct 13, 2026
Merged

w4ffl35 merged 1 commit into
masterfrom
fix/worker-write-confinement

Conversation

@w4ffl35

@w4ffl35 w4ffl35 commented Oct 13, 2026

Copy link
Copy Markdown
Member

Closes #136.

Two halves, per the issue's suggestion (cwd guard / write-path policy in execute_command, failing loudly on escapes):

Part A — confinement gate. execute_command refuses before spawn when the command would leave the workspace root: cd outside the root (every later relative path would resolve outside), and write operands (cp/mv/touch/git -C/...) resolving outside the root. Shared ordered sub-command walk with chain-export overlay; poisoned variables fail closed; cd "" stays allowed (runtime no-op). Documented non-goals: sudo/su/ssh/xargs -exec/script contents — the tripwire below is the backstop.

Part B — main-tree tripwire. scripts/check-main-tree-clean.sh snapshots the main checkout before the run and diffs right after the worker exits; new entries (minus the orchestrator-owned .worktrees/ and plans/parallel-tasks/) are recorded in .harness.main-tree-dirty / .qa.main-tree-dirty plus loud log lines. Wired into all three run-worker.sh wrappers and run-qa.sh, before the .done marker. All diagnostics go to stderr (stdout stays clean for wrapper-PID capture). inspectGroup + reconcileGroups persist the finding as main_tree_dirty; status output shows a MAIN-TREE-DIRTY bit; cleanup removes the new markers. The marker is evidence for review, not an auto-fail (concurrent operator edits in the window match too).

Verification: 12 new tripwire tests + 7 gate tests + executor confinement test, full suite 266 files green, tsc clean, check-standards and check-architecture clean. Arch baseline regen is scoped (+2 clone keys, 3 x2→x3 membership updates, 1 fixed complexity finding dropped).

Follow-ups (not this PR): #138 owns the shared test-runner helper (this PR adds one more conventional test-main); src/permissions/commands.ts is overdue for a file split.

Part A - confinement gate (execute_command refuses before spawn):
- cd-escape guard: cd outside the workspace root is refused, since
  every later relative path would resolve outside the workspace
- write-operand policy: cp/mv/touch/git -C/... operands resolving
  outside the workspace root are refused (shared ordered walk with
  chain-export overlay, poisoned vars fail closed)
- documented non-goals: sudo/su/ssh/xargs -exec/script contents

Part B - main-tree tripwire (fails loudly on escapes):
- scripts/check-main-tree-clean.sh snapshots the main checkout
  before the run and diffs after; new entries (minus .worktrees/
  and plans/parallel-tasks/) land in .harness.main-tree-dirty /
  .qa.main-tree-dirty plus loud log lines. All diagnostics go to
  stderr (stdout stays clean for wrapper-PID capture).
- run-worker.sh (all 3 wrappers) + run-qa.sh wire snapshot/check.
- watch.ts inspectGroup + status.ts reconcileGroups persist the
  finding as main_tree_dirty; status output shows a MAIN-TREE-DIRTY
  bit. cleanup.ts removes the new markers.

Tests: 12 new main-tree-tripwire tests; 7 new permission-gate tests
plus executor confinement test. Full suite 266 files green; tsc
clean; check-standards and check-architecture clean (arch baseline
regen is scoped: +2 clone keys, 3 x2->x3 membership updates for the
new test file, 1 fixed complexity finding dropped).

Closes #136.
@w4ffl35
w4ffl35 merged commit 533972a into master Oct 13, 2026
2 checks passed
@w4ffl35
w4ffl35 deleted the fix/worker-write-confinement branch October 13, 2026 19:17
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.

Worker session wrote src changes to the main checkout instead of its worktree

1 participant