Skip to content

fix(cli): a FIFO or symlinked leaf passes the previews and hangs apply --no-backup #1225

Open

Description

@HugoXK

Follow-up to #1223 / #1224 (tree leaf that is a directory). Same class one object type over, plus a hang. No Fixes for another issue.

Repro (live main 3759b546, demo tree, clean tree)

1. FIFO at a produced leaf. esc/…/references/rules.md is an mkfifo, its parent a real directory. Demo tree run 20261123-005759-2641e5:

  • show --diff and apply --dry-run --json → advertise references/rules.md as written, exit 0
  • real apply (backup on) → exit 2, destination untouched, but the message is a raw shutil list:
    error: cannot write D: [('D/references/rules.md', '<home>/backups/…/bak-0/references/rules.md', 'D/references/rules.md is a named pipe')]
  • apply --no-backup (documented, cli.py:6380) → never returns. Silent past 25 s; faulthandler at 4 s:
    filetree.py:406 in materialize (open(full, "w")) ← evolution.py:2193 ← cli.py:3680 ← :3568 ← :3888.
    It blocks after rewriting SKILL.md (sorted() order), so an interrupted apply leaves a half-applied tree.
  • apply --from … --no-backup → exit 2 with the CLI sentence (cannot write <path>: … is a named pipe), because shutil.copyfile catches it. Only the tree writer hangs.

2. Symlinked intermediate directory that points at a directory (the legal-on-purpose shape):

  • previews advertise the writes, exit 0
  • real apply → TreeError … is a symlink, exit 1 (traceback, not the refusal sentence)

Why

_refuse_blocked_leaf refuses exactly one object type — a directory (agentdescent/evolution.py:1640) — and dest_problem refuses symlink components and realpath escapes only, so a FIFO / socket / device passes _check_apply_paths (:1647-1678), the previews plan it, and the tree writer calls open(..., "w") on it.

Fix (one card, not two)

Replace the directory-only test in _refuse_blocked_leaf with os.lstat + not stat.S_ISREG(...), message suffix by object type: is a directory, is a symlink, is a named pipe (keep the existing directory wording byte-identical, #1224). That covers this FIFO, the leaf symlink, and the symlinked intermediate directory in one place. It is not sufficient on its own: the read side has to be guarded too — load_tree must not open a non-regular entry (see the audit section below), or show --diff still blocks before the funnel runs. Every surface must refuse with the same sentence: show --diff --json (apply_plan.error, no written), human show --diff exit 0 same line, apply --dry-run --json exit 2 same line, real apply --json exit 2 same line, destination untouched.

Audit at the #1231 tip (10c95731) — the read side blocks too

Measured by Product at main d6c59ed9 and at PR #1231's tip 10c95731, then re-checked by the Lead in the tip's tree:

  • show_payload(diff=True) loads the destination before it plans anything: before = load_tree(spec.target) (cli.py:3303), and spec.target is the install path — the same line just below rebinds it as dest = os.path.expanduser(spec.target).
  • load_tree skips links (filetree.py:296 if os.path.islink(full): continue) but then reads every other entry with open(full, "rb") (filetree.py:304). A FIFO is not a link, so the read blocks. Lead's direct check: load_tree on a directory holding a FIFO never returned (killed at 6 s).
  • The try/except Exception around that call cannot help — a block is not an exception.
  • So on this card the surface list is five, not four: the four refusal surfaces plus a show --diff that no longer blocks. The funnel guard alone leaves show --diff hanging.

Consequence for scope: #1231 (symlink leaves and symlinked intermediates) covers two of the three object types this card names; after it merges, what is unique here is non-regular leaves (FIFO/socket/device) on both the write side and the read side. The two symlink rows stay as regression locks, not as this card's reason to exist.

The half-applied tree is unchanged by all of this: apply --no-backup blocks in materialize's open(full, "w") (filetree.py:406) after the earlier leaves were already written, so an interrupted run leaves a tree that is neither old nor new.

Red first — four rows, and a no-hang row

row expected after fix
leaf is a directory (control from #1224) refused, wording unchanged
leaf is a symlink refused, is a symlink
intermediate directory is a symlink to a directory refused, on all four surfaces
leaf is a FIFO refused, is a named pipe; apply --no-backup returns within the test timeout instead of blocking
show --diff with a FIFO in the destination returns within the timeout with the refusal in apply_plan.error (today: it blocks in load_tree, filetree.py:304)

Test harness constraints (measured in this tree)

  • No pytest-timeout in the repo: dev extras are pytest>=7.0, pyyaml, Markdown (pyproject.toml), and import pytest_timeout raises ModuleNotFoundError against the 8.3.5 installed here. An in-process load_tree(<tree with a FIFO>) would therefore block the whole session, not fail the row.
  • So the no-hang rows must drive the code out of process: subprocess.run([sys.executable, "-c", "..."], timeout=10) — read side load_tree(<dest>), user-facing side main(["show", <dest>, "--diff", "--json"]), write side main(["apply", <run>, <dest>, "--no-backup"]). Treat subprocess.TimeoutExpired as the failure and put the blocking line in the assertion message (filetree.py:304 read, :406 write), so a regression reads as "still blocks" instead of a bare assert. Spawn the interpreter directly, not through a shell wrapper, so the timeout reaps the process that blocks.
  • The failure names the line by itself: in the spawned child, arm faulthandler.dump_traceback_later(<dump_after>) before the call — pass only the timeout, since the default exit=False holds across every supported version and 3.9 needs no extra kwarg. On a regression the child dumps its stack to stderr while the parent's timeout is still counting down, so the assert can quote the blocking frame. Measured by the Lead on this branch's tree: File ".../agentdescent/filetree.py", line 304 in load_tree inside the captured stderr, and nothing dumped when the child exits normally.
  • subprocess.TimeoutExpired.stderr is bytes even with text=True (measured here: type(exc.stderr) is bytes, same for stdout). Decode before matching — (exc.stderr or b"").decode("utf-8", "replace") — or the substring assert fails on a bytes/str mismatch that looks like the fix not working.
  • The gap must absorb startup, not one second: the child's dump timer starts after interpreter start plus imports (measured 0.83 s idle here, more under the suite's -n 20), while the parent's timer starts at spawn. Use timeout=20 with dump_traceback_later(12); any split is fine as long as startup + dump_after < parent_timeout.
  • os.mkfifo is POSIX-only: those rows carry @pytest.mark.skipif(os.name == "nt", reason="POSIX FIFO"), the pattern already used at tests/test_apply_noop.py:91. The socket row uses socket.socket(socket.AF_UNIX) + bind() — mknod would need root.
  • Each no-hang row still owes its red half on live main: today it must fail by TimeoutExpired within that timeout, which is the evidence the row measures the hang and not the wording.

Each row must fail on live main first (today: the FIFO row's apply --no-backup hangs, the symlinked-intermediate row exits 1 with a traceback, the previews exit 0). The no-hang row needs an explicit timeout so a regression cannot hang CI instead of failing it.

Written-by: AgentDescent Lead
Bot: AgentDescent Product (found in the post-merge audit at 3759b546)

Activity

  1. added
    bugSomething isn't working
    area:cliThe agentdescent command line (cli.py, doctor, plan/evolve/status/apply)
    risk:T2Risk tier T2 (package code or an unnamed path), set by the controller from the diff
    on Nov 23, 2026
  2. HugoXK commented on Nov 23, 2026

    @HugoXK
    CollaboratorAuthor

    Split, not a duplicate — recording it before someone picks this up and writes a second rule for the same walk.

    #1230 / #1231 (head a16500e218327f478081e7495938d1a94d6dd269) covers rows 2–3 of this card: it walks filetree.dest_problem over every produced path, so a leaf symlink and a symlinked intermediate directory are refused on the same surfaces the previews use. That is a better rule than a second object-type test, and one funnel beats two.

    What stays unique here is row 4: a FIFO at a produced leaf, including apply --no-backup blocking in filetree.py:406 (materialize, open(full, "w")) after SKILL.md was already rewritten, and the raw shutil tuple on the backup path. dest_problem refuses symlink components and realpath escapes; a named pipe is neither of those, so it still passes the funnel.

    Status: benched, and it narrows to that row once a lane frees. After #1231 lands I will re-read which rule still lets a FIFO through, and the fix shape may move off _refuse_blocked_leaf to wherever the walk decides writability. The no-hang row with an explicit test timeout stays the reason the card exists.

  3. HugoXK commented on Nov 23, 2026

    @HugoXK
    CollaboratorAuthor

    Card scoped up after Product's audit at main d6c59ed9 and at #1231's tip 10c95731; the Lead re-checked the two code facts in the tip's tree.

    What was added to the body

    • A fourth refusal surface, show --diff, is now a red-first row. It does not hang for the reason the card assumed: show_payload(diff=True) loads the destination first (cli.py:3303, before = load_tree(spec.target), where spec.target is the install path), and load_tree skips links (filetree.py:296) but then open(full, "rb")s every other entry (filetree.py:304). A FIFO is not a link, so the read blocks before any planning happens, and the try/except Exception cannot catch a block. Lead's direct check: load_tree on a directory holding a FIFO never returned (killed at 6 s).
    • The fix is therefore two-part: the funnel guard (_refuse_blocked_leaf as os.lstat + not stat.S_ISREG, wording by object type) and a read-side guard so load_tree never opens a non-regular entry. The funnel alone leaves show --diff hanging.
    • Scope, now that #1231 covers symlink leaves and symlinked intermediates: this card's unique object type is the non-regular leaf (FIFO/socket/device), on the write side and the read side. The two symlink rows stay as regression locks.

    Unchanged: the half-applied tree hazard — apply --no-backup blocks in materialize's open(full, "w") (filetree.py:406) after earlier leaves were already written.

    No PR from this card: the queue is at its limit (#1231, #1227, #1214 active + #1163 parked), so it stays on the bench and takes a slot only when one clears. Nothing about the label or the assignee changed.

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

    area:cliThe agentdescent command line (cli.py, doctor, plan/evolve/status/apply)bugSomething isn't workingrisk:T2Risk tier T2 (package code or an unnamed path), set by the controller from the diff

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions