Repository navigation
Description
Overview
worktree_create in bin/worktree.sh symlinks every non-repo top-level workspace entry into a new bundle, including activate.sh, then writes the bundle's activate script through that symlink — clobbering the unversioned root ~/Code/PyAutoLabs/activate.sh and silently retargeting every earlier bundle whose activate.sh is that symlink. This fix makes the write never follow a symlink, adds an opt-in repair for bundle paths, and pins it with a hermetic test.
Part of bundle pyautobrain-worktree-guards (one issue + one PR per member).
Plan
- worktree_create skips every name it writes itself (activate.sh, the .pyauto-root marker) in both sibling-symlink loops.
- Belt-and-braces:
rm -f "$root/activate.sh"immediately before writing it, so the write can never follow a symlink into the workspace root. - Opt-in
worktree_repair_activate [task...]regenerates symlinked bundle activate.sh files as real files — bundle paths only, never the root, never called automatically. - Hermetic pytest on a fabricated PYAUTO_MAIN / PYAUTO_WT_ROOT; never touches the real workspace.
Tier: notify — merge mode: auto-merge on green (in-turn wait, then /prm close-out). Brain has no PR test CI, so "green" = full Brain pytest suite passing locally in the worktree, reported before merge.
Detailed implementation plan
Affected Repositories
- PyAutoBrain (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoBrain | main | clean |
Suggested branch: feature/worktree-sh-root-activate-clobber
Shared bundle worktree: ~/Code/PyAutoLabs-wt/pyautobrain-worktree-guards/ (PyAutoBrain only); members worked sequentially 1 → 4, each branch cut from origin/main. Human approved running in parallel with Codex's dashboard-minimal-text claim on PyAutoBrain.
Implementation Steps
- bin/worktree.sh
worktree_create(~L121-200): near L175local -A own=([activate.sh]=1 ["$PYAUTO_ROOT_MARKER"]=1)(marker from bin/_pyauto_root.sh:58); in the"$PYAUTO_MAIN"/*loop (~181-187) and repo_listing loop (~188-193)[[ -n "${own[$name]:-}" ]] && continue; at ~195rm -f "$root/activate.sh"beforeworktree_activate_script "$task" > "$root/activate.sh"; update header comment (~113-120). - New
worktree_repair_activate: defaults to every$PYAUTO_WT_ROOT/*/; for[[ -L $b/activate.sh ]]: rm -f then regenerate via worktree_activate_script. Never resolve/write the link target. - New tests/test_worktree_activate.py (copy scaffold from tests/test_worktree_grouped.py: bare remote, Demo repo, PyAutoMind/repos.yaml):
- test_create_leaves_root_activate_untouched (root bytes unchanged; bundle activate.sh regular file with export PYAUTO_TASK="task" and the per-task PYTHONPATH)
- test_second_bundle_does_not_retarget_first
- test_repair_converts_symlinked_bundle_activate (root bytes unchanged)
- env = os.environ | {PYAUTO_MAIN: tmp/main, PYAUTO_WT_ROOT: tmp/bundles, PYAUTO_WT_FORCE: 1}; assert bundle path under tmp_path.
- Run: python -m pytest tests/test_worktree_activate.py tests/test_worktree_grouped.py -q, then the full suite.
- Out of scope: restoring the currently-clobbered root ~/Code/PyAutoLabs/activate.sh (human action); running the repair on live bundles (human action).
Original Prompt
Click to expand starting prompt
worktree.sh bundle creation clobbers the unversioned root activate.sh
Type: bug
Target: PyAutoBrain
Repos:
- PyAutoBrain
Difficulty: small
Autonomy: safe
Priority: medium
Lane: local-dev
Status: formalised
Consequence: notify
Witness: hermetic test — a fabricated PYAUTO_MAIN (tmp dir) containing a rootactivate.shwith known bytes; afterworktree_create <task>the rootactivate.shis byte-identical to before and the bundle'sactivate.shis a regular file (not a symlink) holding the per-task PYTHONPATH; the test never touches the real workspace root
Review-minutes: 0
Unattended: ready
Updated: 2026-09-28
Bug
organs/PyAutoBrain/bin/worktree.sh bundle creation clobbers the unversioned root
~/Code/PyAutoLabs/activate.sh.
The loop at lines ~181-187 (for entry in "$PYAUTO_MAIN"/* … ln -s "$entry" "$root/$name")
symlinks every non-repo top-level entry of the workspace root into the bundle, including
activate.sh. Line ~195, worktree_activate_script "$task" > "$root/activate.sh", then
writes through that symlink into the root file.
Effect
- Every new bundle rewrites the root activate.sh to point at itself.
- Every earlier bundle whose activate.sh is that symlink silently switches its env to the
newest bundle. 10 bundles were affected on 2026-09-27: eyes-organ-order,
mass-field-{chaining-helper,inference-sim,profiling-live,reduce,sibling-sweep},
multistart-cpu-memory-probe, point-source-cpu-p4, point-source-source-plane-p2b (already
hand-repaired to a real file), remove-empty-modeling-headings. - The canonical root template is
organs/PyAutoBrain/bin/regroup_workspace.py:193-205
(the root file was restored from it on 2026-09-27).
Fix
- Exclude
activate.sh(and any other file worktree.sh later writes into the bundle root)
from the symlink loop, orrm -f "$root/activate.sh"before writing so the write never
follows a symlink. - Add a test: creating a bundle leaves the root activate.sh byte-identical, and the bundle's
activate.sh is a regular file. - Optional one-shot repair: convert existing bundle activate.sh symlinks into regenerated
real files (worktree_activate_script <task>).
Witness
ls -l ~/Code/PyAutoLabs-wt/*/activate.sh currently shows symlinks → the root activate.sh.
Recurrence 2026-09-28
- Recurred today for task
autolens-visualization-rebirth: the root activate.sh (restored
on 2026-09-27) was again overwritten with that task's per-task PYTHONPATH file, and the new
bundle got a symlink instead of its own activate.sh. - Origin of the root file: the 2026-09-18 root backup has no
activate.sh, so the root
file was itself created by an earlier run of this same defect. This explains the standing
memory that "root activate.sh points PYTHONPATH at a stale library worktree". - Witness is hermetic: test against a fabricated
PYAUTO_MAINwith a rootactivate.sh,
never the real~/Code/PyAutoLabs(see header Witness). Checkorgans/PyAutoBrain/tests
for existing worktree.sh tests and extend them. - The helper must never touch the root. The auto-mode classifier treats restoring the
unversioned root file as irreversible, so the fix is purely preventive: skipactivate.sh
(and generally any nameworktree_createitself writes) in the sibling loop, and
rm -f "$root/activate.sh"(removing any symlink) before writing it. Any repair of existing
bundle symlinks acts on bundle paths only. - Priority raised normal → medium on the recurrence.
Activity
Jammy2211 commentedon Oct 6, 2026
Shipped
pyautobrain-worktree-guards; tiernotify. No workspace impact (Brain tooling only); no release obligation.Closed by /prm close-out.