Repository navigation
Conversation
`_text_plan` only asks whether `dest` already holds the evolved text, so a missing parent was invisible to the dry run: it printed `written` with exit 0 and the real run died at `open` with `error: cannot write ...: No such file or directory`, writing nothing. The tree branch materialises its parents and so does the `--from` branch; the run-store text branch now does the same before `open`, and an `OSError` from `makedirs` still takes the existing `_cannot_write` single-line path. The reverse row pins the #990 contract (exit 2, one `error: cannot write ...` line); `tests/test_cli_write_error.py` is unchanged. Not in scope: the tree branch, `--from`, `_text_plan`'s noop rules.
HugoXK
left a comment
There was a problem hiding this comment.
Review tip: 9e0c669
Verdict: PASS
Internal AD Security review of this tip, from a fresh clone. It is not the PASS .github/agent/review-policy.json counts (that file lists only login Birfy) and it is not the merge gate; the owner's PASS at the tip and merge click still decide.
Security surface: no finding. 3 files (agentdescent/cli.py +11, changelog.d/1124-text-apply-missing-parent.md, tests/test_cli_apply_text_missing_parent.py), no .github/**, dependency or lockfile, integrations/**, ARK_API_KEY/FORWARDED_ENV, network or model call. The one new filesystem effect is directory creation, and it sits behind the two gates the branch already had — the link refusal and the operator write guard.
1. The fix is the tree's existing shape, byte for byte. diff -u between the new block (agentdescent/cli.py:3426-3431) and the --from text branch (:3525-3530) is empty. It is the same parent = os.path.dirname(dest) / if parent: os.makedirs(parent, exist_ok=True) / except OSError: raise _cannot_write(dest, e) the tree writer (agentdescent/filetree.py:393,403) and --from already use — not a second rule. The duplication is real; see the non-blocking note, no change requested.
2. The dry run still writes nothing, parents included. if dry_run: returns at :3404-3405, before the new makedirs at :3426. Measured from a fresh cwd with a relative --to sub/rule.md --dry-run: exit 0, written: ["sub/rule.md"], sub/ absent; the real run then exits 0, creates sub/, writes the text, content matches. The positive row pins the dry-run half at tests/test_cli_apply_text_missing_parent.py:26-30.
3. A refused parent is still one line and exit 2. Parent path occupied by a regular file (linkfile -> real.txt, --to linkfile/rule.md): makedirs raises FileExistsError, the new except OSError turns it into error: cannot write …/linkfile/rule.md: File exists, exit 2, one line, no traceback. Base reached the same handler from open (NotADirectoryError), so the contract is unchanged. tests/test_cli_write_error.py is byte-identical to base (git diff length 0); the reverse row is a pin, as the body states.
4. Security — makedirs is behind the link check and the write guard, checked at the lines. Order in the text branch: _refuse_dest_link(os.path.dirname(os.path.abspath(dest)) or os.sep, dest) at :3399 → _text_plan (read only, :3400) → _check_apply_paths(dest, plan["written"], slot, check_write) at :3403 → dry-run return :3404 → optional .bak-N copy :3408-3416 (only when dest exists, so its parent exists and the makedirs is a no-op) → new makedirs :3426-3431 → open :3433. No write precedes the check.
- The check is
filetree.dest_problem(parent, dest)(filetree.py:344-364): it walks every component from the parent down to the leaf and refuses a symlink, then requiresos.path.realpath(dest)to stay underos.path.realpath(parent). Measured: a symlinked leaf → exit 2, one line, victim file unchanged; a parent that is a symlink to a file → exit 2, one line. - A symlinked directory above the file stays legal —
filetree.py:367-380(leaf_problemdocstring) says so and I measured it:--to <linkdir>/rule.mdexits 0 and the file lands in the linked directory. That is the pre-existing rule for--fromand the tree writer, not widened by this PR. - The operator guard runs before creation: with
AGENTDESCENT_SURFACE_WRITE_DIRS=<allowed>and a dest outside it → exit 2 and the outside directory is not created (empty allowlist behaves the same); with the dest inside, the missing subdirectory is created and written. - Non-blocking, for accuracy: this is a single pre-write check, and nothing re-checks between
makedirsandopen.--fromhas the identical ordering (:3508check,:3528makedirs), so the race window is the shape this branch is copying, not a new one, and the delta adds no capability beyond creating the parent of a destination the guard already accepts.
Evidence. Red reproduced at base 5048349a with only the new test file: 1 failed, 1 passed — assert 2 == 0, stderr error: cannot write …/newdir/rule.md: No such file or directory; the reverse row is green at base. At this tip: new file + tests/test_cli_write_error.py → 19 passed; the two apply/CLI selections → 67 passed and 57 passed; tests/test_repo_hygiene.py tests/test_site_navigation.py → 4 passed; tools.gen_api_docs --check → up to date; tools.changelog_fragments check → 50 OK; py_compile clean; no docs/** change, so mkdocs is CI's line. Checks at this head: build, otel-wire, risk tier (report only), reviewed tip (report only) and test (3.9)–(3.13) success, deploy skipped. One environment note: 7 rows of the apply selection fail in this review sandbox only because $HOME/.agentdescent is read-only here; with AGENTDESCENT_HOME pointed at a writable directory all 67 pass — not the PR.
Non-blocking, not findings.
- The 11-line block is byte-identical to the
--fromcopy; a small_ensure_parent(dest)would leave one copy, but the shape is the point of this PR and I do not ask for a new head. --to newdir/(trailing slash, missing): exit 2 and one line (Is a directory), but the emptynewdir/is now created before the failure, and the dry run still reportswritten. The prediction gap is the pre-existing#1124class for a directory-shaped path; the leftover directory is new and benign.- A NUL byte in
--toraisesValueError: embedded null byteout of_text_planat base and at this head alike — pre-existing, not introduced. - The PR currently carries
bug/area:cliand norisk:T*yet; the controller sets it, and the report-onlyrisk tiercheck already ran green. Not mine to set.
One review object was written; no label/assignee/draft change, no push, no merge.
Fixes #1124
What changed
A text-kind
apply <run> --to <fresh>/rule.mdnow creates the missing parent directory before writing. Before: the dry run printed"written": ["…/newdir/rule.md"],"noop": falseand exited 0, then the real run exited 2 witherror: cannot write …/newdir/rule.md: No such file or directory, writing nothing. After: the real run exits 0, the file lands at that path, and the parent is created — the same shape a tree artifact already had, and the same thingapply --fromalready does before itsopen.Scope is the run-store text branch only (
agentdescent/cli.py, the block beforeopeninapply_payload):os.makedirs(parent, exist_ok=True)after the backup step and beforeopen, with anOSErrorfrommakedirsstill going through the existing_cannot_writesingle-line path. The dry run is unchanged and still writes nothing, parents included. Not touched: the tree branch (filetree.materialize),--from, and_text_plan's noop rules.Tests, two rows in
tests/test_cli_apply_text_missing_parent.py:--tounder a regular file still exits 2 with exactly oneerror: cannot write …line and no traceback.tests/test_cli_write_error.pyis byte-identical to base.Red at base
5048349aaceb1ad4c93318581f9a2b49481a5a99, clean worktree with only the new test file added,pytest -q tests/test_cli_apply_text_missing_parent.py:The dry run is already green at that base, which is the bug: the plan is not a prediction.
Verification at the tip
Tip SHA: 9e0c669
Ran:
test_sandbox_containerwith no reachable Docker daemon, 6test_era_srbench, 2test_genesis_example), none in a file this PR touchesNot run:
buildjob is the line.Known non-blocking
None of these is fixed here, and none asks for a new head.
--fromtext branch (the review'sdiff -uis empty). A small_ensure_parent(dest)would leave one copy; that consolidation is left for a later change.--to newdir/(trailing slash, parent missing) now creates the emptynewdir/and then fails with oneerror: cannot write …: Is a directoryline, exit 2. Base created nothing and died atopen, so the leftover directory is a side effect introduced by this PR. It is benign — the command still refuses with the same one line — and it is deliberately not fixed here; the dry run's prediction gap for a directory-shaped--tois a separate, pre-existing gap, not bug(cli): textapply --tointo a missing parent: dry run green, real run exit 2 #1124.--toraisesValueError: embedded null byteout of_text_planat base and at this head alike — pre-existing, not introduced by this PR.