Skip to content

fix: intake --apply crashes on memory citations for a worktree Mind #723

Backlog

Description

@Jammy2211

Overview

pyauto-brain intake --apply classify --file <raw.md> crashes when PYAUTO_MIND points at a temporary PyAutoMind worktree under PyAutoLabs-wt (the doctrine route for Mind writes). _memory_home(mind) treats mind.parent as the workspace root; under the worktree root that parent holds several task folders, each with its own PyAutoMind, so bootstrap_repo_path raises ValueError: PyAutoMind: ambiguous checkouts and the write fails. The dry run works, and organ-targeted prompts skip memory citations, so only --apply on a non-organ target fails. Workaround: export PYAUTO_MEMORY.

Plan

  • Resolve PyAutoMemory from the workspace root (pyauto_root(), which honours PYAUTO_ROOT and the .pyauto-root marker) instead of the Mind checkout's parent, after the existing PYAUTO_MEMORY override. This matches the shell resolve_memory.
  • If resolution fails, file the prompt with no citations and say why on stderr, rather than crashing the write.
  • Drop the mind argument that no longer affects resolution.
  • Add a regression test for the apply path with a Mind whose parent holds several sibling */PyAutoMind checkouts, and a test for the degrade path.
  • Keep the test suite hermetic: tests that file into a temporary Mind must never read a real PyAutoMemory on a developer box.
  • Tier: notify. pyauto-brain merge-mode reports effective level: supervised; merge mode: auto-merge on green; the plan the human approved for this session leaves the merge to the human (/prm).
Detailed implementation plan

Affected Repositories

  • PyAutoBrain (primary)

Branch Survey

Repository Current Branch Dirty?
./organs/PyAutoBrain main (2 behind origin/main) clean

Suggested branch: feature/intake-memory-workspace-root
Worktree root: ~/Code/PyAutoLabs-wt/intake-memory-workspace-root/

PyAutoBrain is claimed by digest-review-table (#718, PR #719) and parked-hold-grace (#720). Neither branch touches the files below; starting needs human-approved coordination.

Implementation Steps

  1. agents/conductors/intake/_intake.py, _memory_home: take no argument. Return Path($PYAUTO_MEMORY) when set, else repo_path(pyauto_root(), "PyAutoMemory") (import pyauto_root from agents/_pyauto_root.py). Wrap the resolution in try/except (ValueError, OSError): print one stderr line naming the reason and return None. Return None when the path is not a directory, as now.
  2. memory_citations: drop the mind parameter; update the call in write_prompt.
  3. tests/test_intake_memory.py:
    • regression test: a Mind directory whose parent holds two or more sibling */PyAutoMind checkouts, a separate workspace root carrying .pyauto-root, a Mind with repos.yaml and a fixture PyAutoMemory; PYAUTO_ROOT at that root, PYAUTO_MEMORY unset; run main() with --apply classify --file on a non-organ target; assert the prompt is written with a Memory: line citing the fixture page. Confirm it fails on main before the fix.
    • degrade test: PYAUTO_ROOT pointed at the ambiguous directory; the write succeeds with no Memory: line.
    • existing tests: set PYAUTO_ROOT=tmp_path (the fixture Memory sits beside the fixture Mind there); update the two direct memory_citations(mind, ...) calls.
  4. tests/test_grouped_organ_consumers.py: call _memory_home() without the Mind argument.
  5. tests/conftest.py: autouse fixture pointing PYAUTO_MEMORY at a nonexistent path, so a test that files into a temporary Mind reads no real PyAutoMemory unless it opts in by deleting the variable.
  6. Run the full test suite.

Key Files

  • agents/conductors/intake/_intake.py — _memory_home, memory_citations, write_prompt
  • agents/_pyauto_root.py — pyauto_root() (read only)
  • agents/_repo_paths.py — repo_path, bootstrap_repo_path (read only)
  • tests/test_intake_memory.py, tests/test_grouped_organ_consumers.py, tests/conftest.py

Out of scope

looks-shipped and reconcile --strong default --root to mind.resolve().parent (_intake.py, two call sites). They do not crash (_shipped.local_repos catches the error), but with a worktree Mind they scan only the Mind, and with the canonical Mind they see the organ family only. Separate task.

Original Prompt

Click to expand starting prompt

intake --apply crashes on memory citations when the Mind is a worktree

Type: bug
Target: PyAutoBrain
Repos:

  • PyAutoBrain
    Difficulty: small
    Autonomy: safe
    Priority: normal
    Status: formalised
    Consequence: notify
    Witness: with a Mind directory whose parent holds several sibling */PyAutoMind checkouts, intake --apply classify --file writes the prompt with a Memory: line from the workspace-root PyAutoMemory (unit test pins it; the test fails on main before the fix)
    Review-minutes: 0
    Unattended: ready
    Lane: any

Source: human report in a Science session, 2026-11-25. Request copied verbatim below; the approved plan follows it.

PyAutoBrain bug (repo: ~/Code/PyAutoLabs/organs/PyAutoBrain). Follow ~/Code/PyAutoLabs/AGENTS.md and the PyAutoLabs dev workflow (plan first, wait for approval before editing source).

Symptom, observed 2026-11-25: pyauto-brain intake --apply classify --file <raw.md> crashes when PYAUTO_MIND points at a temporary PyAutoMind worktree created under ~/Code/PyAutoLabs-wt (the doctrine route for Mind writes: git worktree add --detach ~/Code/PyAutoLabs-wt/<name> origin/main). The dry run (no --apply) works; only the write path fails.

Traceback tail:

agents/conductors/intake/_intake.py:1036 write_prompt
agents/conductors/intake/_intake.py:933 memory_citations
agents/conductors/intake/_intake.py:919 _memory_home  ->  repo_path(mind.parent, "PyAutoMemory")
agents/_repo_paths.py:203 repo_path -> manifest_paths(root) -> manifest_text(root) -> bootstrap_repo_path(Path(root), 'PyAutoMind')
agents/_repo_paths.py:166 ValueError: PyAutoMind: ambiguous checkouts: ~/Code/PyAutoLabs-wt/digest-review-table/PyAutoMind, ~/Code/PyAutoLabs-wt/likelihood-lifecycle-p5f/PyAutoMind, ~/Code/PyAutoLabs-wt/parked-hold-grace/PyAutoMind

Cause: _memory_home(mind) treats mind.parent as the workspace root. For a worktree under /Code/PyAutoLabs-wt the parent holds many task folders each with their own PyAutoMind, so bootstrap_repo_path raises instead of resolving. Workaround that worked: export PYAUTO_MEMORY=/Code/PyAutoLabs/organs/PyAutoMemory.

Wanted: memory citations should resolve PyAutoMemory from the real workspace root (agents/_pyauto_root.py pyauto_root(), which honours PYAUTO_ROOT and the .pyauto-root marker) rather than from the Mind checkout's parent, or at least degrade to "no citations" instead of crashing the write, as the docstring of _memory_home ("or None when it is absent") implies. Add a regression test that runs the apply path with a Mind directory whose parent contains several sibling */PyAutoMind checkouts. Check whether other callers of repo_path(mind.parent, ...) in _intake.py have the same assumption.

Findings (read-only investigation, 2026-11-25)

  • Reproduced: _memory_home(<Mind worktree under PyAutoLabs-wt>) raises the ValueError above; the canonical Mind resolves.
  • Only non-organ targets reach memory_citations (_cites_memory(target)), so organ-targeted prompts file without crashing.
  • The lookup is wrong even when it does not raise: with exactly one task folder holding a PyAutoMind, it would read that task's feature-branch repos.yaml.
  • _intake.py:919 is the only repo_path(mind.parent, ...).

Approved plan (human approved 2026-11-25)

  1. _memory_home: PYAUTO_MEMORY override first, then repo_path(pyauto_root(), "PyAutoMemory"), matching the shell resolve_memory.
  2. Catch ValueError/OSError from resolution, return None, print one stderr line with the reason: no citations rather than a crashed write.
  3. Drop the unused mind argument from _memory_home and memory_citations (one source call site, the test call sites, tests/test_grouped_organ_consumers.py).
  4. Regression test in tests/test_intake_memory.py: a Mind directory whose parent holds several sibling */PyAutoMind checkouts, a separate marked workspace root with a fixture PyAutoMemory, --apply classify --file run through main(); the prompt is written with a Memory: line from the workspace Memory. It must fail on main first.
  5. Degrade test: PYAUTO_ROOT pointed at the ambiguous directory; the write succeeds with no Memory: line.
  6. The existing memory tests set PYAUTO_ROOT=tmp_path; a conftest.py autouse guard points PYAUTO_MEMORY at a nonexistent path unless a test opts in, so a test filing into a tmp Mind never reads the real PyAutoMemory on a developer box.

Out of scope (separate task, human decision)

looks-shipped and reconcile --strong default --root to mind.resolve().parent (_intake.py:4411, :4441). _shipped.local_repos catches the error, so they do not crash, but with a worktree Mind they scan only the Mind, and with the canonical Mind they see organs/ only (15 checkouts, no libraries; the workspace root has 54).

Activity

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