Repository navigation
fix(skills): a directory that cannot be listed is an error in seven more digests, file lists and checks - #1211
antonwolfy wants to merge 3 commits into
Conversation
…ore digests, file lists and checks (intel#1168) Path.rglob and an os.walk with no onerror skip a subdirectory that cannot be listed (mode 0o111) without an error, so the Harbor export cache key, the files the leak gate indexes, the resources of a loaded skill, the packages of `catalog formats`, the scenarios of a reach fixture, the link check of a repo-run skill arm and the output-overwrite guard of `eval leak` described a smaller tree. Each now lists with digest_entries.listed_entries or an os.walk whose onerror re-raises, so the OSError of the directory is raised: _content_key, read_skill (which documents OSError), load_skill, detect_skill_packages, scenarios_of and _uncopyable raise it, and `catalog formats` and `eval leak` turn it into an input error (exit 2). check_skill wraps it as the ValueError it documents. Entries these sites already left out (.git and an evals directory for the leak gate, vendored directories for the package list, __pycache__ for the resources) are dropped before they are listed, so an unlistable one does not raise. A dot-named or vendored directory that cannot be listed is still left out of a skill's resources, as novelty.bundle leaves it out. The result for a tree that can be listed is unchanged. The catalog scan now reports a skill with another folder that cannot be listed as an error row, where the review ran with a bundle-file-unchecked note: the two tests that pinned the note and the skill_treatment test that pinned a skill loading with such a folder pin the new outcome. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 17 selected item(s). CI at Test notes (1)
Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1211 +/- ##
==========================================
+ Coverage 96.07% 96.13% +0.05%
==========================================
Files 496 498 +2
Lines 65209 66035 +826
Branches 11317 11463 +146
==========================================
+ Hits 62652 63480 +828
+ Misses 1583 1579 -4
- Partials 974 976 +2
🚀 New features to boost your workflow:
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 3983a66)
- Contract: candidate. errors dokimi/dokimi/commands/catalog.py:475; errors dokimi/dokimi/commands/leak.py:63
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
The strict traversal correctly propagates listing failures from included skill content. One CLI path also traverses excluded content for an output collision check even when the command writes no files. The regression is visible in the order of the guard and the input reader. Reviewed the seven call sites and their tests from source. GitHub CI is green.
Settles the review thread on `_refuse_clobber`: with no `--out` and no lock there is no output to protect, yet the strict walk entered an unlistable `evals/` that `read_skill` leaves out and exited 2. The guard now returns before the walk when there are no outputs; with an output the walk stays strict. A test covers the stdout-only run with an unlistable excluded directory. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@napetrov (#1211 (review)): Review body; its one finding is the thread 4699602155, fixed in 45271c1. |
|
Ready for another look at codecov has not reported on this head yet. |
vchamarthi
left a comment
There was a problem hiding this comment.
@antonwolfy, could you fix the problem I found and the small thing I've marked fix before merge (in the line comments) and answer my question below? Then push and I'll take another look.
My question before I approve:
- A
discover_skillscall now fails for the whole catalog when one skill has a folder that cannot be listed:catalog probe --catalogexits 2 and names the folder, whilecatalog scanmakes that skill an error row and goes on. Say which in the PR description.
What I checked on 45271c1:
- When I broke the changed code on purpose, the tests missed 4 of 12 breakages.
- The 364 changed tests pass, and fail on main as expected.
- The full test suite passes with main merged in (36,547 tests), apart from failures main has too.
- It merges cleanly onto main.
…ueError Settles the review points on the arm factory and external-content.md. `create_treatment` now wraps the `PermissionError` of `load_skill` (`skill:`, `skill-agent:`) and of `discover_skills` (`skill-catalog:`) in a `ValueError` that names the arm, as `check_skill` does, so the CLI refuses it instead of printing a traceback and exiting 5. Tests cover the three arm kinds. `external-content.md` no longer says a vendored folder that cannot be listed gives the `bundle-file-unchecked` note: the bundle walks skip vendored folders before they are opened, so only a hidden folder can. The changelog fragment names the arm refusal. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@vchamarthi (#1211 (review)): The two line comments are done in 2229e53. On the question: yes, a |
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 2229e53)
- Contract: candidate. errors dokimi/dokimi/commands/catalog.py:475; errors dokimi/dokimi/commands/leak.py:70
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
The earlier permission-denied fix is in place for all three skill arm kinds. I checked another listing failure against the merge base and found a raw filesystem error still escapes the treatment factory. The subjects run planning path translates ValueError into a CLI input error. CI passed.
| skill = load_skill(part.arg) | ||
| try: | ||
| skill = load_skill(part.arg) | ||
| except PermissionError as exc: |
There was a problem hiding this comment.
blocking: Could both factory branches translate directory listing failures consistently? I simulated an I/O error (EIO) only while listing a skill’s references directory. Both skill: and skill-catalog: leaked raw OSError on this commit; on the merge base both arms constructed. The new strict listing is intended, but subjects run only translates ValueError in _run_plan, so this case escapes as a traceback. Please translate the listing error into an arm-specific validation error while preserving the existing behavior for a missing SKILL.md, and cover a non-permission listing failure.
vchamarthi
left a comment
There was a problem hiding this comment.
@antonwolfy, could you fix the new problem I found (in the line comments) and fix what napetrov's thread on dokimi/dokimi/treatments/factory.py:60 still points out? Then push and I'll take another look.
What I checked on 2229e53:
- When I changed the code on purpose, the tests still passed for 4 of 12 changes, and no test pins these down yet (non-blocking):
dokimi/dokimi/skills/loader.py:160(it returns None),dokimi/dokimi/skills/loader.py:163(it returns None) anddokimi/dokimi/skills/loader.py:164(the handled error is raised again). - The 367 changed tests pass, and fail on main as expected.
- The full test suite passes with main merged in (37,076 tests), apart from failures main has too.
- It merges cleanly onto main.
| if not outputs: | ||
| return # nothing is written, so the walk below would only list what read_skill leaves out | ||
| skill_root = Path(args.skill) | ||
| if skill_root.is_file(): |
There was a problem hiding this comment.
Must fix (blocking): With a skill folder as --skill, an existing --out file in a sibling folder is refused as an input, and no test catches that.
Input: --skill is a skill folder, and --out is an existing file, other/leak.json, in a sibling folder.
Got: The guard accepts it now, which is what I'd expect, since it is not an input of the run.
Suggestion: Add that case to tests/test_unlistable_sites.py beside test_leak_output_guard_refuses_when_it_cannot_list_the_skill.
I tested this patch: it fixes the problem, and the tests still pass.
Patch
--- a/dokimi/tests/test_unlistable_sites.py
+++ b/dokimi/tests/test_unlistable_sites.py
@@ -189,3 +189,9 @@
_refuse_clobber(_clobber_args(skill, skill / "references" / "a.md"), None)
with unlistable(skill / "references"), pytest.raises(InputError, match="references"):
_refuse_clobber(_clobber_args(skill, elsewhere), None)
+
+
+def test_leak_output_guard_accepts_an_existing_output_beside_a_skill_folder(tmp_path: Path):
+ skill = _skill(tmp_path)
+ other = _write(tmp_path / "other", {"leak.json": "{}"})
+ _refuse_clobber(_clobber_args(skill, other / "leak.json"), None)Details
If I change if skill_root.is_file(): to if not (skill_root.is_file()):, the guard lists the parent folder, refuses other/leak.json as an input, and every test in the changed files still passes. The assert that would catch it: with other/leak.json present, _refuse_clobber(_clobber_args(skill, other / "leak.json"), None) must not raise.
Summary
Path.rgloband anos.walkwith noonerrorskip a subdirectory that cannot be listed (mode0o111, as a non-root user) without an error, so a digest, file list or check of a skill or task described a smaller tree and nothing said so (#1168, the same cause as #1103 to #1106, fixed for four sites in #1169). Onmain, with a skill directory holdingSKILL.mdand areferences/directory of two files, andchmod 111 references:references/(or the task'senvironment/) unlistable, onmainharbor_export._content_key(cache key of an exported task)0ff7dfe6ee3e21e2bd2288aa5ad8b92f, no errorleakgate.read_skill(files the leak gate indexes)['SKILL.md', 'references/a.md']['SKILL.md'], so a leak in the dropped file is not foundloader.load_skillresources['references/a.md'][]formats.detect_skill_packages(catalog formats)conformance.scenarios_ofcwd=.,cwd=sub,read=subcwd=.onlyarms._uncopyable(link check of a skill arm)links outside itfor a link in the directoryNone, the link is not checkedleak._refuse_clobber(eval leakoutput-overwrite guard)--outthat is a file of the skillThe fix taken is the first option the issue gives, applied per site: list with
digest_entries.listed_entries(or anos.walkwhoseonerrorre-raises), so theOSErrorof the directory is raised where each site already raisesOSErroror returns a digest, a key or a list, never a smaller value and never a warning. Entries a site already left out (.gitand a top-levelevalsfor the leak gate, vendored directories for the package list,__pycache__for the resources) are dropped before they are listed, so an unlistable one does not raise.The same search over every
rglobandos.walkunderdokimi/dokimi/found more places with the cause that the issue does not name, and they are not changed here: the two doc sources of the issue (a question about their contract) in #1207, the skill discovery walks in #1208, the static check walks in #1209 and other readers of a user's tree in #1210.Closes #1168
Changes
harnesses/harbor_export.py_content_key,skills/loader.pyload_skill,skills/formats.pydetect_skill_packagesandrepos/conformance.pyscenarios_oflist withlisted_entries;eval/leakgate.pyread_skilldoes too (its docstring already says it raisesOSError), withdropfor the entries it left out;repos/arms.py_uncopyablewalks with anonerrorthat re-raises.leak._refuse_clobberreturns before it lists the skill when no file is written (no--outand no lock), so a stdout-onlyeval leakis not stopped by an unlistableevals/thatread_skillleaves out; with an--outor a lock the listing stays strict.load_skillstill leaves out__pycache__, and a dot-named or vendored directory (.git,venv,node_modules) that cannot be listed, asnovelty.bundledoes since fix: a directory that cannot be listed is an error in four digests and file lists, not a smaller tree #1169; any other directory that cannot be listed raises. A listable tree gives the same resources as before.skill_treatment.check_skillwraps theOSErrorofload_skillin theValueErrorit documents (it caught onlyFileNotFoundError);catalog formatsandeval leak(_refuse_clobber) turn it into anInputError, exit 2, naming the directory. A catalog scan row for a skill with such a folder is an error row, as for any skill that does not load;repo runalready catchesOSErroraround the arm check.test_catalog_command_checks.py::test_an_unreadable_subdirectory_does_not_abort_the_scanandtest_catalog_bundle_unreferenced.py::test_an_unreadable_folder_withholds_the_claimasserted a review with abundle-file-uncheckednote for a skill with a folder that cannot be listed; the skill is now an error row and the scan goes on.test_skill_treatment.py::test_an_unreadable_subdirectory_is_not_a_loop_errorassertedcheck_skillreturned the name; it now asserts acannot load skillValueErrorthat is not a loop error. The hidden-folder note (.cache) and the vendored cases are unchanged.treatments.factory._buildwraps thePermissionErrorofload_skill(skill:,skill-agent:) and ofdiscover_skills(skill-catalog:) in aValueErrorthat names the arm, ascheck_skilldoes, so an arm spec that names such a skill is refused instead of ending in a traceback.discover_skillscall fails for the whole catalog when one skill has a folder that cannot be listed:catalog trigger-probe --catalogexits 2 and names the folder, and askill-catalog:arm is aValueError;catalog scaninstead makes that skill an error row and goes on (run on a catalog of one skill with an unlistablereferences/:trigger-probeexit 2--catalog: [Errno 13] Permission denied: .../references,catalog check --per-skillone skill in stateerror).external-content.md(thebundle-file-uncheckednote is for a hidden folder; another folder that cannot be listed makes the skill an error row) andevaluating-treatments.md(the leak gate).Risk
A skill, task or fixture tree with a directory the process cannot list is now refused where it used to be read as a smaller tree:
eval leakandcatalog formatsexit 2 with the directory named, a catalog scan reports the skill as an error row (before, a review with abundle-file-uncheckednote),repo runrefuses a skill arm, a Harbor export raisesPermissionError, andcheck_skillfails the cell before the image build. A directory with no read permission as root, or on a file system with no modes, lists as before. The output for a tree that can be listed is unchanged, including the Harbor cache key, so no cached export is invalidated. The two surviving mutants of the changed-lines job areFalsebecomingNonein the_not_listed_as_resourcepredicate, which both are falsy: equivalent.Open PRs that change the same files (#1190, #1193, #1197, #1171, #1158, #1039) change other lines: #1190 rewrites the
InputErrorandparse_frontmatterimport lines ofcommands/leak.py,commands/catalog.pyandharnesses/skill_treatment.py, which this change leaves alone (it adds its own import line inleak.pywith the unchangedexit_codesimport between the two), and the others change other hunks ofcatalog.py,external-content.mdandevaluating-treatments.md, so a merge with any of them meets no conflicting hunk.Testing
On a Linux review host, at
2229e530(onmain602de14):make ci-local: 38 passed, 0 failed, 15 skipped (docker and network steps, other Python versions, semgrep, matrix jobs of other workflows). 28404 tests passed, 23 skipped; changed-line coverage 100% (50 lines).test_a_skill_arm_with_a_folder_that_cannot_be_listed_is_refused_as_a_value_error(skill:andskill-agent:) andtest_a_skill_catalog_arm_with_a_folder_that_cannot_be_listed_is_refused_as_a_value_error: with theexcept PermissionErrorof both wraps changed toFileNotFoundError,3 failed, 19 passed, each failing on thePermissionErrorfromload_skillordiscover_skills.test_leak_output_guard_does_not_list_the_skill_when_no_file_is_written: with the early return replaced byif False, it fails (the guard raisesInputErroron the unlistableevals/with no output).tests/test_unlistable_sites.py(19 tests): onmain's code9 failed, 9 passed; the nine that fail are the unlistable-directory tests of the seven sites, ofcatalog formatsand ofcheck_skill, first onDID NOT RAISE PermissionError; the nine that pass pin a listable tree's result (the same key, files, resources, packages, scenarios) on both. The three changed existing tests give3 failed, 342 passedonmain's code.rglobor droppingonerrorat each of the seven sites, dropping eachdropclause, the dot-named and vendored carve-out, theInputErrorwraps, thecheck_skillcatch, the\0of the key) each fail the test that pins them.make ci-local.Open questions
What a doc source (
local:andokf:) should do with a directory it cannot list: the code raisesMCPConnectionErrorfor a missing path, skips an unreadable file at debug level and warns on no files, anddocs/adding-doc-source.mdsays nothing of it, so neither settles it. Left to #1207.Revert
A plain revert restores the old behaviour: a directory that cannot be listed is left out of the listing again. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to [the twoInputErrorwraps and thecheck_skillcatch carry the cause in a comment or the message of theOSError; the tests cite More rglob/os.walk sites list or digest a directory tree and skip a subdirectory they cannot list #1168, the raises do not name an issue].github/.licenserc.yaml)