Skip to content

fix(cli): show and --dry-run advertise a write whose parent is a file, and the real write fails with File exists #1208

Open

Description

@HugoXK

Implementation: AgentDescent (ours) — draft PR #1215 opened in this session; do not pick up.

Problem

#1204 closed the gap where show --diff advertised writes apply refuses. This is the next case past it, and it is not a #1204 regression: here apply does not refuse the destination, it fails while creating the parent.

Measured at 1aa816e0 (allowlist unset, blocker a regular file):

  • text artifact, --to <tmp>/blocker/rule.md: show --diff --json exits 0 with apply_plan carrying would_write/written and no error; apply --dry-run says the same; the real apply exits 2 with cannot write <dest>: File exists. Nothing is written, and the message names the destination — but the file it collides with is the parent, not the destination.
  • tree artifact rooted at <tmp>/blocker/lib: show prints written: [alpha/SKILL.md, beta/SKILL.md]; apply exits 2 with cannot write <root>: Not a directory.
  • apply --from <file> --to <blocked>: exit 2, the same File exists.
  • control, missing parent with no blocker (<tmp>/newdir/rule.md): show 0, apply 0, the file is written — #1125 is intact.

Mechanism

  • The parent is only materialised after the planning path returns: text write cli.py:3616-3621, --from :3727-3732, the tree inside _write_to → materialize (wrapped at :3641). Every plan, including --dry-run, therefore never touches it.
  • _cannot_write (cli.py:125) renders <dest>: <strerror>, so File exists is the parent's errno printed against a destination that never existed.

Fix shape

One refusal, placed where every surface already passes through:

  • _refuse_blocked_parent(dest): walk up to the nearest existing ancestor; when it is not a directory, raise the ordinary run-store error with cannot write <dest>: '<ancestor>' is a file, not a directory — the actionable half File exists does not give.
  • Call it at the top of _check_apply_paths (evolution.py:1582), before the check_write is not None guard, so it runs with the operator allowlist unset. That funnel is the one call site used by show text (cli.py:3117), apply text (:3593), --from (:3714), --install-to (:3812) and the tree path (evolution.py:2107) — so show, --dry-run and the real write agree by construction instead of by three parallel checks.
  • Order: after the destination refusals (_refuse_text_dest, _refuse_dest_link), whose messages must not change. Blocked-parent is the last destination check.

Acceptance

  • All three shapes above: show --diff / --json and apply --dry-run carry an error equal to the real apply's message (not a hard-coded copy).
  • The message names the blocking ancestor, not only the destination.
  • Control: a missing parent with no blocker still writes (#1125 behaviour unchanged), and the blocker file is untouched.
  • This intentionally changes apply's message for this case (File exists → the named ancestor); #1204's "message bytes unchanged" rule does not apply here, and the test must assert the new text.
  • Red-first at 1aa816e0: three new rows fail before the change.
  • changelog.d/ Fixed fragment; focused apply/show tests, tools.gen_api_docs --check, tools.changelog_fragments check green.

Scope

agentdescent/evolution.py (_refuse_blocked_parent + one call at the top of _check_apply_paths), one test file, one changelog fragment. No cli.py change expected; no behaviour change for an existing destination or a creatable parent. T2.

Lineage: #1124 (missing parent dies at open) → #1125 (a fresh --to creates its parent) → this (a parent that is a file must be refused before anything is planned).

Activity

  1. added
    bugSomething isn't working
    area:cliThe agentdescent command line (cli.py, doctor, plan/evolve/status/apply)
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Nov 21, 2026
  2. self-assigned this
    on Nov 21, 2026
  3. HugoXK commented on Nov 21, 2026

    @HugoXK
    CollaboratorAuthor

    Branch agent/1208-blocked-parent at 9911610a32bd10259c8a6eb8f8bca327d4666687, based on 1aa816e0e155c2f59db1686e404a7ebae739d94b.

    One _refuse_blocked_parent at the top of _check_apply_paths, two commits (test, then fix + Fixed fragment). Red at base: 4 failed, 1 passed; green at tip: 5 passed. PR follows.

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

Metadata

Metadata

Assignees

Labels

agent-workingAn agent has claimed this issue (the claim comment names the branch)area:cliThe agentdescent command line (cli.py, doctor, plan/evolve/status/apply)bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions