Repository navigation
fix(harnesses): docker solver removes a kept work tree with an unlistable directory - #1638
antonwolfy wants to merge 3 commits into
Conversation
…able directory (intel#1511) docker_solver._rmtree was shutil.rmtree(path, ignore_errors=True). A directory the agent left at mode 0o111, 0o555 or 0o000 made the removal fail silently, so the previous run's kept tree under output_dir/work stayed and the shutil.copytree that follows merged the new tree into it. On Linux as a non-root user, a work/sub at 0o111 left ['sub'] after _rmtree(work), for each of the three modes and for a nested directory. The body of AgentWorkspace.cleanup (make each directory searchable and writable through a descriptor opened with O_NOFOLLOW, then remove, never raise, log the path when the tree stays) moves into a module-level remove_tree(path) in agent_sandbox.py. AgentWorkspace.cleanup calls it with self.root and _rmtree calls it too, so there is one copy of the logic. The warning now reads "tree %s was not removed: %s", since both callers use it. Where the repair cannot run, removal is plain and a tree that stays is logged instead of silent. The existing cleanup tests pass unchanged: the one that patches shutil.rmtree patches the shared module attribute, which remove_tree calls. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
The changelog, test comment, and PR description inaccurately describe a prevented merge rather than a stale snapshot blocking replacement and need correction.
1 open issue
What changed in this PR
1 new finding.
This PR addresses #1511 by reusing sandbox cleanup logic so unlistable kept work trees no longer block Docker solver snapshot replacement.
Changes:
- Extracts shared
remove_treecleanup and uses it in the Docker solver. - Adds regression tests for permissions, symlink safety, and failure logging.
- Adds a changelog entry.
| File | Description |
|---|---|
| dokimi/tests/test_docker_solver_rmtree.py | Tests removal and snapshot replacement. |
| dokimi/dokimi/harnesses/docker_solver.py | Delegates removal to the shared helper. |
| dokimi/dokimi/harnesses/agent_sandbox.py | Extracts reusable permission-repair cleanup. |
| dokimi/changelog.d/20261204_100000_docker-solver-rmtree-unlistable.md | Documents the cleanup fix. |
Review effort: Balanced
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 4 selected item(s). CI at Review details
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 4e4d0ad)
- Contract: changed (count signal only, no file:line)
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
No new blocking findings on 4e4d0adc.
An offline probe confirmed that an old snapshot prevented replacement on the base. The head removes it and saves the fresh snapshot. The description and changelog should say the old snapshot was retained. Earlier discussion
CI was still running for Intel CI; ci.
Reviewed the diff, edge cases and prior threads. Focused tests: 11 passed on head. The full local suite was outside coverage.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1638 +/- ##
==========================================
- Coverage 96.46% 96.43% -0.03%
==========================================
Files 561 585 +24
Lines 74345 76601 +2256
Branches 12840 13176 +336
==========================================
+ Hits 71716 73872 +2156
- Misses 1609 1672 +63
- Partials 1020 1057 +37
🚀 New features to boost your workflow:
|
…merge Settles the review point on the changelog fragment and the test docstring: `shutil.copytree` without `dirs_exist_ok` rejects an existing destination with `FileExistsError`, which the solver logs, so the old snapshot was kept without the new files. The fragment and the test docstring now say that instead of a merge. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@napetrov (#1638 (review)): Review body with no change asked beyond its thread: the description and changelog wording about the retained old snapshot is settled in the thread above (cbce4e3). |
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head cbce4e3)
- Contract: changed (count signal only, no file:line)
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
No new actionable findings.
Docker solver cleanup reuses the workspace permission recovery so a kept snapshot can be replaced when its own directories have restrictive modes.
CI on head cbce4e3: 0 failing Actions jobs; merge base 01ff2d6 is behind base tip 5225c2a.
Compared the change and input edges against the merge base and checked existing threads and GitHub Actions. Runtime checks used focused Linux tests and local fixtures. Focused tests on the head: head 11 passed in 0.29s.
vchamarthi
left a comment
There was a problem hiding this comment.
@antonwolfy, could you fix the small thing I've marked fix before merge (in the line comments)? I'll approve once that's done.
Optional, non-blocking (1)
dokimi/changelog.d/20261204_100000_docker-solver-rmtree-unlistable.md:8: The changelog says a tree that stays is logged with its path, but a dangling symlink at the tree's path stays with no warning.
What I checked on cbce4e3: the 11 changed tests pass, and fail on main as expected; the full test suite passes with main merged in (36,229 tests), apart from failures main has too; it merges cleanly onto main; when I changed the code on purpose, the tests still passed for 1 of 10 changes; the line comments say where.
…s a dangling link that stays Settles two review points. The first: deleting os.close(root) in remove_tree left every test passing, so a new test compares the entries of /proc/self/fd before and after removing a tree with unlistable nested directories. The second: a dangling symlink at the tree's path stayed with no warning, because shutil.rmtree raises FileNotFoundError for it and that was read as "gone". remove_tree now treats FileNotFoundError as gone only when the path is not a link, and logs the link otherwise; a test covers it. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@napetrov (#1638 (review)): No findings, no change. The head's tests pass here too; the checks I ran are in the description's Testing section. |
@vchamarthi (#1638 (review)): The blocking point is answered in the reply to the thread on |

Summary
docker_solver._rmtreewasshutil.rmtree(path, ignore_errors=True)._solve_claudecalls it onoutput_dir / "work"to clear a previous run's kept agent tree and again before it copies the new tree in. When the agent left a directory at mode0o111,0o555or0o000, the removal failed silently, the old tree stayed and theshutil.copytreethat followed rejected the existing destination withFileExistsError, which the solver logs ([keep work tree] ...), so the old snapshot was kept without the new files. On Linux as a non-root user, withwork/sub/a.txtandchmod <mode> work/sub:_rmtree(work)onmain0o111workleft,['sub']0o555workleft,['sub']0o000workleft,['sub']The same holds when the unlistable directory is nested one level down.
AgentWorkspace.cleanupalready repairs this (#1385, #1512); the issue's second option is taken here: the body ofcleanupbecomes a module-levelremove_tree(path)inagent_sandbox.py, and bothcleanupand_rmtreecall it, so there is one copy of the logic and no second import path to keep in step.Closes #1511
The same cause in
command.clear_run_dir(harnesses/command.py:226, which raises instead of staying silent) is tracked in #1637.mainalso failstests/test_import_architecture.py::test_package_uses_the_new_modules(dokimi.runs.resolveimportsdokimi.utils), unrelated to this change (not touched here; filed separately).Changes
harnesses/agent_sandbox.py:remove_tree(path)holds whatAgentWorkspace.cleanupdid: make each directory searchable and writable through a descriptor opened withO_NOFOLLOW, thenshutil.rmtree; it never raises and logstree <path> was not removed: <reason>when the tree stays.AgentWorkspace.cleanupcalls it withself.root. The warning no longer says "work tree", since the staged directories use it too. Behaviour ofcleanupis otherwise identical and its tests are unchanged.harnesses/docker_solver.py:_rmtreecallsremove_tree. Where the repair cannot run (noO_NOFOLLOW,O_DIRECTORYor/proc/self/fd), removal is plain as before, but a tree that stays is logged instead of silent.tests/test_docker_solver_rmtree.py: the repro for each mode, flat and nested; the new tree copied after the removal holds only the new files (onmainthe copy fails withFileExistsError); a link out of the tree leaves its target alone; a missing path is no error and no warning; a tree that stays logs its path and the reason; no repair available logs what stayed; the directory descriptorsremove_treeopens are all closed afterwards (the entries of/proc/self/fdare the same before and after); a dangling symlink at the path stays and is logged.harnesses/agent_sandbox.py:remove_treetreatsFileNotFoundErrorfromshutil.rmtreeas "gone" only when the path is not a symlink, so a dangling link is logged instead of silent.Risk
A tree
_rmtreecould not remove used to stay silently; it is now removed, and one that still stays is logged at WARNING._rmtreestill never raises. A path that is a symlink (live or dangling) or otherwise not removable byshutil.rmtreenow logs a warning where it was silent. Directories the repair opens are set to0o700inside the tree being deleted only; links are not followed.Testing
On a Linux review host, at
4a99ec57(onmain01ff2d6):make ci-local: 36 passed, 2 failed, 16 skipped (matrix legs on other Pythons, jobs conditional on a PR, steps needing tools not on the machine). One failure istests/test_import_architecture.py::test_package_uses_the_new_modules(['dokimi.runs.resolve'] import dokimi.utils, dokimi.runs.resolve imports dokimi.utils, which test_package_uses_the_new_modules refuses #1629), which fails identically onmain's tree (not touched here). The other ispip-audit, which reports advisories againstfilelock4.2.4 from the lock (Drop the filelock override once a litellm release allows filelock 4 #383), not touched here. The full suite: 35418 passed, 1 failed, 28 skipped; gitleaks: no leaks found.main's code the new test file gives12 failed, 1 passed(the one that passes is the missing-path test, which holds on both); the first failure isassert not work.exists()for0o111.os.close(root)inremove_treefails the descriptor test (1 failed); making the dangling-link case always silent fails the dangling-link test (1 failed)._unlock_belowfromremove_tree(8 failed),_rmtreeback toignore_errors=True(10 failed), dropping the warning (2 failed), logging a path that is gone (1 failed),_can_unlockalways true (1 failed), the warning without the reason (1 failed).O_NOFOLLOWin_open_searchableandis_dir(follow_symlinks=False)in_unlock_belowremoved; either alone leaves it passing, as the two layers overlap.fix/unlistable-root-readers,fix/unlistable-repo-eval-readers,fix/unlistable-skill-docsonmain4024f25:pytest -n auto35800 passed, 28 skipped,mypyclean,ruff checkclean.Open questions
None.
Revert
A plain revert restores
shutil.rmtree(path, ignore_errors=True)in_rmtreeand the body ofcleanup. Nothing is stored.Checklist
pytestpasses (one failure in the full run,test_import_architecture.py::test_package_uses_the_new_modules, fails the same onmain)ruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)