Skip to content

feat: conflict guard warns on unregistered on-disk worktrees #470

Closed

Description

@Jammy2211

Overview

worktree_check_conflict only consults the Mind registry, so a worktree that exists on disk but is claimed nowhere is invisible to the guard and the repo looks free. This adds an on-disk view: the guard warns (exit code unchanged) about unregistered worktrees of the requested repo, and a report-only audit lists orphans and zero-work stale claims for human-confirmed cleanup.

Part of bundle pyautobrain-worktree-guards (one issue + one PR per member).

Plan

  • worktree_list_on_disk <repo>: parse git -C <repo> worktree list --porcelain (linked worktrees: path, branch).
  • worktree_check_conflict: after the registry loop, print to stderr WARNING: <repo> has unregistered worktree <path> (<branch>) for each requested repo's worktree not covered by any active.md claim. Exit code unchanged (WARNING, not hard conflict — a hard conflict would block nearly every task while 47 orphans exist).
  • Report-only worktree_audit_orphans: every repo × worktree unclaimed in any registry, with ahead/behind + dirty count; zero-commit/zero-change registered claims flagged STALE?. NO removals — output is a list for human confirmation (/repo_cleanup).
  • A parked.md claim exempts a worktree from "orphan".
  • Correct the docs/comments that say the guard reads planned/parked.

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/unregistered-worktree-guard

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.

Findings

scientific-workflow-language worktree no longer exists (witness uses a fabricated stand-in); the guard reads only active.md (via worktree_list_claimed ~L375 / worktree_registry_path ~L367), not planned/parked as the prompt says; Heart's worktree_drift.py only scans $PYAUTO_WT_ROOT + claimed paths and is another organ — do not import it. 47 orphans exist today (10 with commits or dirty files).

Implementation Steps

  • bin/worktree.sh: add the two functions; extend worktree_check_conflict (~L442). Claim coverage on resolved paths: claim's worktree: path equals the worktree path or is its parent (bundle roots like /PyAutoArray); expand ~. Iterate repos via pyauto_repo_list for the audit. Keep the audit out of the guard (speed).
  • New tests/test_worktree_orphan_guard.py reusing the _run idiom of tests/test_worktree_conflict_guard.py (fabricated PYAUTO_MAIN/PyAutoMind/active.md, env PATH/HOME/PYAUTO_MAIN/PYAUTO_WT_ROOT; git init synthetic RepoA, git worktree add tmp/x/RepoA -b feature/ghost). Check test_worktree_grouped.py for repo placement under the grouped layout. Synthetic names only (tenant firewall).
    • test_unregistered_worktree_warns_but_exit_0, test_registered_worktree_no_warning, test_bundle_root_claim_covers_child, test_parked_claim_not_orphan, test_other_repo_orphan_not_reported, test_audit_lists_orphan_with_ahead_behind_dirty, test_audit_flags_zero_commit_claim, test_missing_registry_still_fails_closed
  • Run: python -m pytest tests/test_worktree_orphan_guard.py tests/test_worktree_conflict_guard.py tests/test_worktree_claim_guard.py tests/test_worktree_grouped.py -q, then full suite.
  • Same file as member 1 (different function, ~300 lines apart): cut after member 1 merges, or rebase.

Original Prompt

Click to expand starting prompt

Unregistered worktrees are invisible to the conflict guard

Type: maintenance
Target: PyAutoBrain
Repos:

  • PyAutoBrain
    Difficulty: small
    Autonomy: supervised
    Priority: normal
    Status: formalised
    Consequence: notify
    Witness: a worktree that exists on disk but appears in no Mind registry is either reported by worktree_check_conflict (or an adjacent audit command) or is gone; demonstrated against the scientific-workflow-language HowToFit worktree named below.
    Review-minutes: 0
    Unattended: ready

worktree_check_conflict <task> <repo> decides whether a repo is claimed by
reading the PyAutoMind registries (active.md, planned.md, parked.md). A
worktree that exists on disk but is in none of them is therefore invisible to the
guard: it cannot report the conflict, because as far as the registry is concerned
the repo is free.

Concrete instance, found 2026-09-14:

/home/jammy/Code/PyAutoLabs/.worktrees/scientific-workflow-language/HowToFit
branch: feature/scientific-workflow-language  (8883fcc)
27 commits behind origin/main, 0 commits of its own, 0 changed files
present in no Mind registry

Harmless in itself — the branch is empty, so any parallel work is disjoint by
construction — but it is debris, and it is debris of a kind the guard is
structurally unable to warn about. The same session also found the registered
howtofit-mode claim on HowToFit had 0 commits and 0 changed files, i.e. a live
claim that had never been used; between them, the registry both over-reports
(stale claims) and under-reports (orphan worktrees).

Two pieces of work, separable:

  1. Sweep the debris. Remove scientific-workflow-language and audit for other
    worktrees on disk that no registry mentions, across all repos. git worktree list per repo versus the registries is the comparison.

  2. Close the blind spot. Give the guard, or a companion audit, a view of what
    is actually on disk, so an unregistered worktree is reported rather than
    silently treated as "repo free". Related and worth deciding together: whether a
    registered claim with 0 commits and 0 changed files should decay or be
    reported as stale, since that is the over-reporting half of the same problem.

Existing related memory: the guard fires at REPO granularity, so a human routinely
approves a parallel worktree when file sets are disjoint. That judgement depends on
the guard's picture being complete, which this shows it is not.

Type: maintenance
Target: PyAutoBrain
Difficulty: small
Priority: normal

Activity

  1. Jammy2211 commented on Oct 6, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    • PR: feat: conflict guard warns on unregistered on-disk worktrees #474 — merged 2026-10-06 into main (db2aa37)
    • Summary: worktree_check_conflict warns on unregistered on-disk worktrees (exit unchanged); new report-only worktree_audit_orphans.
    • Tests: new tests were red on the unfixed code first; full Brain suite green locally (PyAutoBrain has no PR test CI).
    • Part of bundle pyautobrain-worktree-guards; tier notify. No workspace impact (Brain tooling only); no release obligation.

    Closed by /prm close-out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions