Skip to content

fix(cli): refuse a non-regular entry in the --from source tree - #1255

Merged
Birfy merged 4 commits into
mainfrom
agent/1246-apply-from-non-regular
Nov 24, 2026
Merged

Birfy merged 4 commits into
mainfrom
agent/1246-apply-from-non-regular

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1246

What changed

apply --from no longer plans a non-regular entry in the source tree.

Before: _files filtered the --from walk with os.path.islink only, so a FIFO where the artifact expects a file came back as a planned file and _same opened it — blocking until a peer appeared, forever when none did; a socket or a device failed unread. The blocked-leaf funnel (_check_apply_paths) runs later and on the --to side, so it could not catch this one.

After: with refuse_symlinks the walk also refuses any non-regular entry, decided by one lstat and no read, naming the kind through filetree._entry_kind:

--from <root> contains a non-regular entry ('references/rules.md' is a named pipe);
refuse to apply (a pipe blocks in open until a peer appears and a device or socket
cannot be read). Remove it or replace it with a real file, matching apply <run_id>
which materialises regular files only.

Exit code 2, ok: false, nothing written and no backup slot taken. The copy loop re-checks the mode as well, so a tree that changes under us cannot open one either. The --to side is unchanged: a stray entry there is left alone, exactly as a stray link already was.

No UI surface.

Verification at the tip

Tip SHA: 9dda901

Ran:

  • pytest -q -o addopts="" tests/test_apply_from_non_regular.py → 4 passed, 1 skipped (the device row skips itself where mknod is not permitted).
  • Red first at base 22ea7528 with only this test file added → 3 failed, 1 passed, 1 skipped; the blocking row: apply --from with a FIFO source blocked: `timeout 20` killed the child (rc=124)., child stack ending agentdescent/cli.py", line 3874 in _same.
  • pytest -q -o addopts="" over the 14 apply-related files (test_apply*, test_cli_apply*, test_skill_library_apply_install.py) → 90 passed, 1 skipped.
  • python3 -m tools.changelog_fragments --root . check → 33 changelog fragment(s) OK.

Not run:

  • Full pytest -q: this box has no markdown package, so tests/test_docs_links.py fails at collection (environment, not the diff). Every apply-related file was run as listed above.
  • mkdocs build --strict: no docs/ or mkdocs.yml change.

Correction

The socket row's fixture now builds its trees under a short /tmp root when sun_path would overflow, and the red block above was retaken with that fixture in place: 3 failed, 1 passed, 1 skipped on the product assertions (the socket row fails as assert 0 == 2, planned as written), not on OSError: AF_UNIX path too long.
The refusal rows now run under timeout 60 with the stack dump at 45 s, so a cold start cannot turn a refusal into a false rc=124; the red block was retaken under those bounds at base 22ea7528 (3 failed, 1 passed, 1 skipped, FIFO rows killed at 60 s, socket row assert 0 == 2).

Reviewed head (appended; nothing above changes): 90605bf7d4c2dbc7503363e588cccd1de12960df, a base-only merge of 28ded70d onto 9dda901e; review request 7129680903 named that head. The Tip SHA: line above stays as the sha the gates actually ran at.

`_files` classified the `--from` tree with `os.path.islink` alone, so a FIFO
where the artifact expects a file was returned as a planned file and
`_same` opened it -- blocking until a peer appeared, forever when none did.
A socket or a device failed unread. The funnel that names a blocked leaf runs
later and on the `--to` side, so it could not catch this.

With `refuse_symlinks` the walk now also refuses any non-regular entry,
naming the kind through `filetree._entry_kind` from one `lstat` and no read;
the copy loop re-checks so a tree that changes under us cannot open one
either. The `--to` side keeps its behaviour: a stray entry there is left
alone, as a stray link already was.

Fixes #1246
@HugoXK HugoXK added bug Something isn't working area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) labels Nov 24, 2026
@HugoXK

HugoXK commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-report for one body edit and one commit on this draft.

The socket row's fixture now builds its trees under a short /tmp root when the bind path would exceed sun_path, so the red block at base 22ea7528 is retaken with that fixture in place and fails on the product assertions, not on OSError. The push that follows moves Tip SHA: to the new head and appends one correction line under a new ## Correction section; the fix description is unchanged.

The new socket row bound src/references/rules.md, so a long TMPDIR pushed the bind past
sun_path's 108 bytes and the row failed with AF_UNIX path too long instead of exercising
the refusal. Build that row's trees under a short /tmp root when the fixture path is long,
allow that root for the run, and remove it in finally (#1246).
@HugoXK

HugoXK commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-report for one body edit and one commit on this draft, after CI at 6b68f86e settled green (10 checks, none pending, none failed).

The change is only the file's own bounds and the comments that state them: CEILING 20 -> 60 (timeout on every capped child) and DUMP_AFTER 12 -> 45 (the faulthandler dump, still inside the ceiling), plus the docstring/comment lines that name the old numbers. _assert_returned's two guards and every assertion stay byte-identical. Tip SHA: moves to the new head and one line is appended under ## Correction; the fix description is unchanged.

CEILING=20 and the 12 s faulthandler dump sat inside a single cold import plus fixture
build, so a refusal row could die as a false rc=124 on a loaded box. Raise the kill to
60 s and the dump to 45 s, keeping the dump inside the ceiling so a real hang still
yields a stack before the kill. Bounds and their comments only; assertions unchanged.
@HugoXK

HugoXK commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

State change in this turn: draft true → false on this PR (GraphQL markPullRequestReadyForReview). Reason: the gate set is complete at the live head and the ready queue is empty after two merges.

Live head 90605bf7d4c2dbc7503363e588cccd1de12960df, base 28ded70d8cf7063f0abf2b07e20921316d28430e.

90605bf7 is a merge commit (9dda901e + 28ded70d), so the diff is exactly what was reviewed at 9dda901e90f5d3d073358b05ffd510096e1046d5 plus main's own changes — nothing new for a reader to judge. All ten checks on it are complete and none is failing.

The body's Tip SHA: line is superseded by this comment; the body stays as written.

@HugoXK
HugoXK marked this pull request as ready for review November 24, 2026 11:06
@HugoXK

HugoXK commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Review request at head 90605bf7d4c2dbc7503363e588cccd1de12960df, base 28ded70d8cf7063f0abf2b07e20921316d28430e.

What to review: 90605bf7 is a merge of main into 9dda901e90f5d3d073358b05ffd510096e1046d5, so the change under test is that tip's. It replaces the two bounds in tests/test_apply_from_non_regular.py with CEILING = 60 and DUMP_AFTER = 45 (the dump stays inside the ceiling), and updates the three comment/docstring passages that stated the old numbers; every assertion line is byte-identical to the reviewed tip, and agentdescent/cli.py is untouched.

Evidence at the base with only that test file added: 3 failed, 1 passed, 1 skipped — the two FIFO rows fail at rc=124 against the old bound and the socket row fails on the product assertion (assert 0 == 2 on the plan), not on a fixture error. At this head: 4 passed, 1 skipped under both a short and a 126-byte TMPDIR, the socket row executing in both; the only skip is the device row, which needs root.

All ten checks on 90605bf7 are complete and none is failing.

@github-actions github-actions Bot added risk:T3 Risk tier T3 (core loop, release, process; needs Danyang's click), set by the controller agent-pr Pull request opened by an agent labels Nov 24, 2026
@HugoXK

HugoXK commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Body edit, no push: the Tip SHA: line above names 9dda901e90f5d3d073358b05ffd510096e1046d5, which is the content tip the gates ran at; the reviewed head is 90605bf7d4c2dbc7503363e588cccd1de12960df, a base-only merge of 28ded70d onto 9dda901e, named by review request 7129680903. Appending one line so a reader cannot take 9dda901e for the reviewed head; nothing else changes and no commit goes with this.

@Birfy

Birfy commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Review (Birfy)

Tip SHA: 90605bf
Ran:

  • .github/scripts/risk_gate.py --repo ThinkFlowLab/agentdescent --pr 1255 → T3 (size 256 lines / 3 files > 250 / 12 allowed for T2)
  • pytest -q -o addopts='' tests/test_apply_from_non_regular.py at this tip → 4 passed, 1 skipped
  • python -m tools.changelog_fragments check → 37 changelog fragment(s) OK
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
  • Required CI at this tip (build, test 3.9–3.13) → SUCCESS
    Not run:
  • Full offline suite locally — the CI test matrix is the line
  • The device-node row skipped on this box (mknod not permitted); CI covers the platforms that can create one
    Findings:
  • No actionable defects. apply --from now refuses a non-regular source entry (FIFO, socket, or device) by lstat before any open, and the copy loop re-checks the mode so a tree that changes under us cannot block either. The --to walk is unchanged.
    Verdict: PASS

@Birfy
Birfy merged commit 414839e into main Nov 24, 2026
12 checks passed
@Birfy
Birfy deleted the agent/1246-apply-from-non-regular branch November 24, 2026 16:31
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) bug Something isn't working risk:T3 Risk tier T3 (core loop, release, process; needs Danyang's click), set by the controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: apply --from blocks on a non-regular entry in the source tree instead of refusing it

2 participants