Skip to content

fix(cli): show --diff previews the write apply refuses (#1188) - #1200

Open
HugoXK wants to merge 1 commit into
mainfrom
agent/1188-show-diff-write-dirs
Open

HugoXK wants to merge 1 commit into
mainfrom
agent/1188-show-diff-write-dirs

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1188. Partial: #1082. Partial: #963.

Base: 8d75685
Tip SHA: b9b6202

What changed

show --diff previewed a write that the same apply refuses. Its only guard
was _refuse_plan_outside_write_dirs, which checked the destination; apply
additionally checks every file the plan names and the backup slot
(_check_apply_paths). A directory artifact backs up under
$AGENTDESCENT_HOME/backups/..., so with AGENTDESCENT_SURFACE_WRITE_DIRS
set to the destination's tree the preview listed the files as written while
apply exited 2 on the backup path.

show now runs apply's own check set:

  • text artifact: slot = _backup_slot(dest) if backup and not plan["noop"] and os.path.exists(dest) else None, then _check_apply_paths(dest, plan["written"], slot, _operator_write_guard()) — the expression and call
    apply makes at cli.py:3561;
  • materialised tree: result._write_to(dest, backup=..., dry_run=True, check_write=_operator_write_guard()) — apply's call at cli.py:3604 with
    only dry_run different, and _write_to runs _check_apply_paths before
    its dry_run return (evolution.py:2102-2105).

_refuse_plan_outside_write_dirs(payload, target, written=(), backup=None)
carries the extra paths instead of guarding the destination alone; the
tree branch's call to it was dropped because _write_to now performs that
same set. An unset AGENTDESCENT_SURFACE_WRITE_DIRS still means
allow-anywhere.

One asymmetry is deliberate: the preview assumes the default apply, so it
checks the backup slot. apply --no-backup takes no such slot and refuses
nothing extra; the preview is therefore stricter than that one flag
combination, not wrong about it.

Red first, at this PR's base (8d75685a) in a clean worktree with only the new
test file present:

PYTHONPATH=. python -m pytest -o addopts="" tests/test_write_dirs_apply_show.py -q
1 failed, 2 passed in 2.92s
FAILED tests/test_write_dirs_apply_show.py::test_show_refuses_a_plan_whose_directory_backup_is_outside_the_allowlist

show returned apply_plan {"written": ["alpha/SKILL.md", "alpha/references/rules.md", "beta/SKILL.md"], ..., "noop": false} with no
error, while the same call through apply exited 2 with error: backup '<tmp>/ad-home/backups/seed-lib-e25afdcf43d6/bak-0' is outside the operator's write allowlist (AGENTDESCENT_SURFACE_WRITE_DIRS); allowed roots: '<tmp>/seed-lib', dest unchanged and home never created.

Ran at b9b62024

  • PYTHONPATH=. python -m pytest -o addopts="" tests/test_write_dirs_apply_show.py -q
    — 3 passed;
  • full suite, eight shards over tests/test_*.py (516 files), each
    PYTHONPATH=. python -m pytest -o addopts="" -q <chunk> — 7935 passed, 22 failed, 10 errors, 51 skipped;
  • the 32 red/error ids are identical to a clean 8d75685a worktree run of the
    same ten files (22 failed, 442 passed, 15 skipped, 10 errors, 137.81s):
    comm between the two sorted id lists is empty. All 32 are environment rows
    — OSError: [Errno 30] Read-only file system: '/home/xuke/.agentdescent-tests' — plus the Docker sandbox rows in
    test_sandbox_container.py;
  • python -m tools.gen_api_docs --check — docs/api.md is up to date;
  • python -m tools.changelog_fragments check — 9 changelog fragment(s) OK.

Not run

  • mkdocs build --strict in its exact form: this host is offline and the
    social plugin fetches fonts.google.com, so the build dies at
    ERROR - Error building page 'index.md': ... ConnectTimeout. Verified
    instead with mkdocs build --strict -f mkdocs.local.yml, whose only
    difference is social: {cards: false} — pass, Documentation built in 12.91 seconds. The CI build online is not claimed here.

@HugoXK HugoXK added enhancement New feature or request area:plugins Host plugins and installers: Claude Code, Codex, DSH, OpenCode, MCP server area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) agent-pr Pull request opened by an agent labels Nov 20, 2026
@github-actions github-actions Bot added the risk:T2 Risk tier T2 (package code or an unnamed path), set by the controller from the diff label Nov 20, 2026
`show --diff` guarded only the destination. A directory artifact backs up
under `$AGENTDESCENT_HOME/backups/...`, not beside the target, so a
destination inside `AGENTDESCENT_SURFACE_WRITE_DIRS` whose home is outside
it was reported as `written` while the same `apply` exited 2 on the backup
slot -- a preview for a call that cannot run.

`show` now runs apply's own check set: the destination, every path in the
plan's write set and the backup slot. A single-file artifact checks through
`_check_apply_paths`, as `apply` does; a tree through
`_write_to(check_write=...)`, the call `apply` makes, with `dry_run` the
only difference. An unset allowlist still means allow-anywhere.

Partial: #1082
Partial: #963
@HugoXK

HugoXK commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Advisory QA read — #1200 at b9b6202411c9b4f4d9535389527a6dfef8c6af64

Read live at that head (draft: false, mergeable_state: clean, 0 comments before this one); base 8d75685aecdecb9a93056d8abee661b827a83c28, main 4b46761a6bb69985d86a9495b4eb8e397b3f2a92 — the one commit above the base is #1198 (AGENTS.md + a test docstring). Body Tip SHA: equals the head. 4 files +135/−11 = 146 changed lines → T2 by path (agentdescent/cli.py), under the 250-line / 12-file cap; labels enhancement + area:plugins + area:cli + risk:T2 match.

Ran (fresh clone, fetched refs/pull/1200/head):

  • Full offline suite at the tip, one command, -n 8 -o addopts="": 21 failed / 7924 passed / 63 skipped / 10 errors, 308.92s. The same command at base 8d75685a: 21 failed / 7921 passed / 63 skipped / 10 errors, 285.54s. The 31 red ids are the same set id for id (junit both ways, comm empty): 0 new, 0 vanished.
  • Red at base, only this branch's new test file present in a clean 8d75685a worktree: 1 failed, 2 passed in 1.26s — exactly the body's row and the same id (test_show_refuses_a_plan_whose_directory_backup_is_outside_the_allowlist; the failure shows apply_plan with written: [alpha/SKILL.md, …] and no error).
  • tests/test_write_dirs_apply_show.py at the tip: 3 passed in 1.32s.
  • Focused set at the tip (test_write_dirs_apply_show, test_mcp, test_mcp_algorithm_spec_allowlist, test_mcp_algorithm_spec_target_dir, test_apply_noop): 57 passed, 5 failed — and all five ids (test_crlf_files_compare_verbatim, test_a_script_with_only_user_exec_is_not_what_apply_leaves, …) are in the base suite's 31-id red set, unchanged.
  • python -m tools.gen_api_docs --check → docs/api.md is up to date; python -m tools.changelog_fragments check → 9 fragments OK; mkdocs build --strict with the offline social plugin stripped (untracked mkdocs-offline.yml, the same workaround the body records) → rc 0, 12.16s.

Probes at the tip, independent of the new test's assertions:

  • With AGENTDESCENT_HOME outside AGENTDESCENT_SURFACE_WRITE_DIRS, show --diff --json returns apply_plan with error: backup '…/ad-home/backups/seed-lib-…/bak-0' is outside the operator's write allowlist (AGENTDESCENT_SURFACE_WRITE_DIRS); allowed roots: '…/seed-lib', and no written key — the preview no longer advertises the write apply exits 2 on for the same run (rc 2, destination unchanged, home never created).
  • The declared asymmetry holds as written: apply --no-backup (no slot) returns rc 0 on that same run where the preview refuses, so the preview is stricter than that one flag combination, not wrong about it.
  • With the allowlist unset, the same run's preview is green again (error: None), so allow-anywhere is unchanged.

Not run: docker sandboxes (no daemon — the same 10 errors at both ends), wheel smoke (no packaging path), real-model path (offline; the diff is path checking), risk_gate.py (no gh; tier computed from .github/agent/risk-rules.json).

Findings: none blocking. Recorded, not a defect: the preview assumes a default apply, so show --diff refuses a backup slot that apply --no-backup would never take — the body declares that asymmetry and it is what the probe above shows.

No UI surface: CLI show --diff output and one docs paragraph; nothing is rendered.

No merge action from QA: this report is advisory, the merge gate is the repo's review decision on the head sha, and the merge itself is executed by the repo's merge process.

This branch has not been deployed

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

Labels

agent-pr Pull request opened by an agent area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) area:plugins Host plugins and installers: Claude Code, Codex, DSH, OpenCode, MCP server enhancement New feature or request risk:T2 Risk tier T2 (package code or an unnamed path), set by the controller from the diff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): show --diff checks only the destination, so it advertises a write apply refuses on the backup path

1 participant