Skip to content

maintenance: resolve the workspace root by marker, not by sibling probe - #392

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/workspace-location-contracts
Sep 18, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/workspace-location-contracts

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Part of #391 (phase 1a). Changes no directory layout. Companions: PyAutoHeart, PyAutoHands, PyAutoMind — all on the same branch name, mergeable in any order (see Merge order).

The defect

agents/_pyauto_root.py:59 decided a directory was the workspace root when it held any of SIBLING_ORGANS, without checking it was a checkout. Group the organs into organs/ and <root>/organs itself satisfies that test — the root resolves one level too deep, silently, because every consumer degrades rather than raises.

Same fixture, old resolver vs new:

OLD: (PosixPath('/tmp/…/organs'), 'beside this checkout')   <-- one level too deep
NEW: (PosixPath('/tmp/…'),        '.pyauto-root marker')

The change is additive

Before After
1 $PYAUTO_ROOT verbatim $PYAUTO_ROOT, validated — the reason says whether a marker confirmed it
2 parent, if it holds a sibling organ nearest ancestor holding .pyauto-root ← new
3 parent regardless, "unverified" parent, if it holds a sibling organ — unchanged, demoted
4 — parent regardless, "unverified"

Keeping step 3 is load-bearing. A remote session often checks out a single repo with no root above it and therefore no marker; Brain CI lays Brain/Mind/Cortex side by side the same way. Demoting rather than deleting means no currently-correct resolution can become wrong — the change can only add correctness, and CI keeps resolving by the probe. A marker-only assertion would have gone red in CI.

bin/_pyauto_root.sh takes the identical order and exports PYAUTO_ROOT_REASON and PYAUTO_ROOT_MARKER. The module docstring requires the two halves to agree, so every test asserts it by running both.

bin/worktree.sh::worktree_create now writes a marker into each new task bundle — its sibling-symlink loop doesn't glob dotfiles, so the canonical marker was never propagated and bundles would otherwise be unmarked.

Witness

tests/test_workspace_root.py builds nested fixtures in tmp_path and pins the defect explicitly: organs/ tests true under the old rule, and writing the marker moves the answer to the real root.

  • Red before: resolvers stashed to HEAD, new tests run against them → 7 failed, 4 passed
  • Green after: 11 passed
  • Full suite: 929 passed, no regressions

Known limitation, stated deliberately

Step 3 is still wrong for a nested workspace with no marker, and a test pins that. It is the price of never breaking the remote single-repo case. The consequence matters for phase 3: whoever performs the actual regroup must create the marker in the same commit, or resolution silently goes one level deep again.

Merge order

Any. PyAutoHeart/PyAutoHands ship shims that tolerate a Brain predating this resolver (their set -u shell path would otherwise hit an unbound PYAUTO_ROOT_REASON), so the four PRs are not a lockstep.

Note for the issue

This makes the resolver a locator, not a writer's or grader's root: the reason strings say which rule fired, never that the root contains the caller. Three consumers needed that distinction during this phase — PyAutoMind's --write (a bundle with a symlinked Brain resolves to canonical), PyAutoHeart's health grading, and the dashboard regen. Downstream guards handle it; this module is unchanged by it.

🤖 Generated with Claude Code

https://claude.ai/code/session_0161NLKVzbBMzhaBfjpGogor

`_is_root()` decided a directory was the workspace root when it held any of
SIBLING_ORGANS, without checking it was a checkout. Group the organs into an
`organs/` directory and `<root>/organs` itself satisfies that test, so the root
resolves one level too deep — silently, because every consumer degrades rather
than raises.

Insert a `.pyauto-root` marker walk ABOVE that probe rather than replacing it:

  1  $PYAUTO_ROOT, now validated (the reason says whether a marker confirmed it)
  2  nearest ancestor holding .pyauto-root          <- new, authoritative
  3  parent, if it holds a sibling organ            <- unchanged, demoted
  4  parent regardless                              <- unchanged

Keeping 3 is load-bearing: a remote session often checks out a single repo with
no root above it and therefore no marker. Demoting rather than deleting means
no currently-correct resolution can become wrong — the change can only add
correctness, and CI (which lays repos out side by side with no marker) keeps
resolving by the probe.

The shell twin takes the identical order and exports PYAUTO_ROOT_REASON and
PYAUTO_ROOT_MARKER; the module's docstring requires the two to agree, and the
tests assert it on every case by running both.

worktree_create now writes a marker into each new task bundle: its sibling
symlink loop does not glob dotfiles, so the canonical marker was never
propagated and every bundle would otherwise be unmarked.

Witness: tests/test_workspace_root.py builds nested fixtures and pins the
defect — `organs/` tests true under the old rule, and the marker moves the
answer to the real root. Red before (7 failed), green after (11 passed).
Full suite 929 passed.

Part of PyAutoBrain#391 (phase 1a). No directory layout changes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161NLKVzbBMzhaBfjpGogor
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.

1 participant