Skip to content

fix(glob): refuse a directory a user's pattern cannot list instead of running on a smaller set - #1505

Merged
antonwolfy merged 3 commits into
intel:mainfrom
antonwolfy:fix/unlistable-pattern-globs
Dec 1, 2026
Merged

antonwolfy merged 3 commits into
intel:mainfrom
antonwolfy:fix/unlistable-pattern-globs

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#1384: trace consistency --arm LABEL=GLOB, the session paths of trace prefilter and skill novelty ground --header / --shared-lib expand a path pattern with glob.glob(pattern, recursive=True). glob skips a directory it cannot list (mode 0o111, non-root user) without an error, so a trace, a session or a header under it is not in the arm, the session list or the symbol input, and the command runs on the smaller set. With docs/top.md and docs/sub/a.md, the pattern <root>/docs/**/*.md and then chmod 111 docs/sub:

Site Listable docs/sub unlistable, on main
--arm x=<root>/docs/**/*.md (_trace_arms) ['a.md', 'top.md'] ['top.md']
session paths (_session_paths) ['a.md', 'top.md'] ['top.md']
--header / --shared-lib (symbols._files) ['a.md', 'top.md'] ['top.md']

Fix taken: the issue's first option. One helper, dokimi.pattern_glob.expand, gives what glob.glob(pattern, recursive=True) gives (sorted, a wildcard skips dot names, ** matches zero or more directories and follows links, a literal segment is statted and not listed) but raises the OSError of a directory the pattern has to list. Each caller turns it into its existing usage error (InputError, exit 2): Error: --arm '<root>/docs/**/*.jsonl': cannot list the directory <root>/docs/sub: Permission denied. The second option (document it and warn) is not taken: it keeps the smaller input set, and the sibling fixes (#1361 and its PR, digest_entries.listed_entries) refuse.

Refuted design: walking only the pattern's literal prefix with os.walk(onerror=...) would raise for a directory glob never lists. A pattern docs/*/a.md with docs/sub at mode 0o111 finds docs/sub/a.md (the next segment is literal, so glob stats it), and a ** skips a hidden directory, so a walk that lists every directory under the prefix refuses inputs glob answers correctly. The helper instead follows glob's own segment-by-segment plan and lists only what it lists.

Closes #1384

Changes

  • dokimi/dokimi/pattern_glob.py (new, foundation layer in tests/test_import_architecture.py): expand(pattern) and has_magic. A directory that is not there (ENOENT, ENOTDIR, a link loop) lists nothing, as for glob; any other OSError of a listing is raised with filename naming the directory. A link into a directory the user cannot search is no longer taken for a non-directory (os.path.isdir and DirEntry.is_dir swallowed the PermissionError): the walk below ** and the directory-only listing raise it. A leading **/ also matches the working directory itself (**/*.jsonl finds top.jsonl, as glob does).
  • commands/context.py: _trace_arms (--arm, still falling back to the pattern itself when nothing matches) and _session_paths (~ expanded and a literal file kept before any glob, as before) expand through _expand_pattern, which refuses with the directory named. The --arm help says so.
  • novelty/symbols.py: _files expands through expand and raises InputError naming the directory; a path that exists is still read as it is (inc[1]/). The --header help says so.
  • Docs: a line in architecture.md (shared building blocks), run-consistency.md (--arm) and grading-tiers.md (--header).
  • tests/test_pattern_glob.py: the helper against glob.glob on a listable tree (26 patterns, relative and absolute, hidden names, a link, ** in the middle, a magic early segment, inc[[]1]), the unlistable counterexamples, and one test per site that makes docs/sub mode 0o111 (skipped as root) and asserts the error and the directory in its message.
  • Changelog fragment (Fixed).

Risk

An --arm glob, a session path glob or a --header / --shared-lib glob that has to list a directory it cannot list used to give a smaller set and now exits 2 naming the directory. A listable tree gives the same matches in the same order. A directory a literal segment only passes through, or that a ** skips as hidden, is not listed and does not refuse. The branch adds one row to LAYERS in tests/test_import_architecture.py and a line to architecture.md: open PRs #1190, #1416 and #1249 change that test file and conflict with it on merge (a one-line rebase for whichever merges second); #1190 and #1416 also change the dokimi.utils import line of commands/context.py, which this PR leaves alone. glob on 3.11 to 3.14 could differ from the port in an edge not in the parity table; the table is the pinned set.

The refusal message for --shared-lib names --library: that is the existing _files wording (the flag argument is library), kept here and tracked in #1504.

Testing

On a Linux review host, at b8a9f5e7 (on main 9e41f5e8):

  • make ci-local: 38 passed, 0 failed, 16 skipped (steps that need another runner, micromamba, semgrep, or a job condition false on a PR). 32140 tests passed, 27 skipped; pattern_glob.py 100% line and branch coverage under tests/test_pattern_glob.py.
  • Repro: the new tests run against main's code (the helper replaced by a glob.glob stand-in) give 6 failed, 32 passed, the first on Failed: DID NOT RAISE PermissionError for docs/**/*.md over a mode 0o111 docs/sub. The CLI at this head exits 2 on all three sites with the message above.
  • Mutants: each of 12 breaks of the helper and the three callers (the listing error swallowed, a literal segment listed instead of statted, hidden names entered, dot names matched, ENOENT raised, a link not followed, [ not a wildcard, the --arm fallback dropped, each caller's catch removed, the label, the sort) fails a test of the new file.
  • Review round: with top.md and docs/top.md, expand('**/*.md') gave only docs/top.md before and gives both now, as glob.glob does; with runs/link pointing into private/sub and private at mode 0o000, expand('<root>/runs/**/*.jsonl'), runs/** and runs/*/a.jsonl raise PermissionError (they returned runs/top.jsonl or nothing). The new tests fail on the previous head (5 failed): dropping the empty prefix fails 4 parity tests, and going back to os.path.isdir / is_dir returning False fails test_a_link_into_a_directory_the_user_cannot_search_raises_not_skips.
  • Second review round: with runs/open/a.jsonl, a link runs/.hidden and a link runs/other into private/sub at mode 0o000, runs/**/*.jsonl and runs/open*/*.jsonl raised PermissionError on the link the pattern leaves out and now return runs/open/a.jsonl; runs/o*/*.jsonl, which matches the link, still raises. With runs/private at mode 0o000, runs/*/sub/*.jsonl gave only runs/open/sub/a.jsonl and now raises PermissionError; at mode 0o111 it returns both files. The two new tests fail against the previous head's pattern_glob.py (2 failed, 49 passed); deleting the os.lstat of the new literal-segment check fails the parity case a/*/d.txt. The root-level **/*.md match raised in that round was already fixed at 60374d22 and is in the parity table (top.md, **/*.md).
  • Mutation of changed lines (the ci-local step), at this head: 80 of 100 mutants run (cap 80), 65 killed, 15 survived, in the exc.strerror or exc fallbacks, the False returns for an absent path (a listing of one gives nothing either way) and the dirs/dironly plumbing of pattern_glob.py; none is waived.
  • Merged together with fix/unlistable-root-globs, fix/sandbox-cleanup-unlistable, fix/novelty-out-dir-unlistable on main bcb1f9f: pytest -n auto 32223 passed, 27 skipped, mypy clean, ruff check clean.
  • Not run: Python 3.11, 3.12 and 3.14 (this run is 3.13), Windows, and a run as root (the unlistable-directory tests skip there).

Open questions

None.

Revert

A plain revert restores glob.glob at the three sites. Nothing is stored.

Checklist

`trace consistency --arm LABEL=GLOB`, the session paths of `trace prefilter` and `skill novelty ground --header` / `--shared-lib` expanded their pattern with `glob.glob(pattern, recursive=True)`, which skips a directory it cannot list (mode 0o111, non-root) without an error. A trace, session or header under it was missing and the command ran on the smaller set: with `docs/top.md` and `docs/sub/a.md`, `<root>/docs/**/*.md` gave `['top.md']` once `docs/sub` was `chmod 111`.

The three sites now expand with `dokimi.pattern_glob.expand`, which gives what `glob.glob(pattern, recursive=True)` gives, sorted (a wildcard skips dot names, `**` matches zero or more directories and follows links, a literal segment is statted and not listed), but raises the `OSError` of a directory the pattern has to list. Each caller turns it into its usage error (`InputError`, exit 2) naming the pattern and the directory. A directory only a literal segment passes through, or one a hidden-skipping `**` does not enter, is not listed and does not raise. The `--arm` fallback to the pattern itself when nothing matches, `~` expansion, the literal-file-first rule and the `[1]` literal path of `--header` are unchanged.

The module is added to the foundation layer of the import architecture, with a line in the architecture doc, the run-consistency and grading-tiers docs, the `--arm` and `--header` help, and a changelog fragment.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner December 1, 2026 15:47
@antonwolfy antonwolfy self-assigned this Dec 1, 2026
Copilot AI balanced review requested due to automatic review settings December 1, 2026 15:47
@exai-bot

exai-bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

CI at b8a9f5e: 21 passing, 4 skipped.

Review details
  • Commit reviewed: b8a9f5e against merge base 60374d2
  • Coverage: 3 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 107k tokens (72k from cache), 22s
  • Tool calls: 13 (8 file_read, 2 code_search, 1 ci_status, 1 local_check_results, 1 pr_threads)
  • small change set: 3 files

Comment thread dokimi/dokimi/pattern_glob.py Resolved
Comment thread dokimi/dokimi/pattern_glob.py Resolved
@codecov-commenter

codecov-commenter commented Dec 1, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.33%. Comparing base (9e41f5e) to head (b8a9f5e).
⚠️ Report is 13 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1505      +/-   ##
==========================================
+ Coverage   96.31%   96.33%   +0.02%     
==========================================
  Files         515      519       +4     
  Lines       68928    69407     +479     
  Branches    11933    12028      +95     
==========================================
+ Hits        66389    66866     +477     
- Misses       1563     1566       +3     
+ Partials      976      975       -1     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/context.py 95.81% <100.00%> (+0.06%) ⬆️
dokimi/dokimi/commands/skill.py 100.00% <ø> (ø)
dokimi/dokimi/novelty/symbols.py 98.59% <100.00%> (+0.03%) ⬆️
dokimi/dokimi/pattern_glob.py 100.00% <100.00%> (ø)

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Leading ** patterns fail to match root-level files, silently omitting inputs from relative arm, session, and header/library expansion.

1 open issue
What changed in this PR

1 new must-fix finding.

This PR addresses #1384 by introducing shared glob expansion that rejects required directory listings that fail, rather than letting commands process incomplete input sets.

Changes:

  • Route trace arms, session paths, and header/shared-library patterns through the shared helper.
  • Convert listing failures into usage errors naming the affected directory.
  • Add parity and permission-error tests, CLI help, and documentation.
File Description
dokimi/​tests/​test_pattern_glob.py Adds glob parity and directory-permission tests.
dokimi/​tests/​test_import_architecture.py Registers the helper in the foundation layer.
dokimi/​dokimi/​pattern_glob.py Adds shared expansion with explicit listing errors.
dokimi/​dokimi/​novelty/​symbols.py Uses the helper for header and library patterns.
dokimi/​dokimi/​commands/​skill.py Documents header-pattern listing failures in help.
dokimi/​dokimi/​commands/​context.py Integrates expansion for trace arms and session paths.
dokimi/​docs/​run-consistency.md Documents arm-pattern fallback and refusal behavior.
dokimi/​docs/​grading-tiers.md Documents header-pattern listing errors.
dokimi/​docs/​architecture.md Describes the shared helper and error handling.
dokimi/​changelog.d/​20261201_140000_pattern-glob-unlistable.md Records the glob permission-handling fix.

Review effort: Balanced

Comment thread dokimi/dokimi/pattern_glob.py Resolved
… unsearchable directory raises

A leading `**/` in a user's pattern matched only the directories below the working directory, so `**/*.jsonl` left out `top.jsonl` that `glob.glob` finds. The directory-only expansion of `**` now also yields the empty prefix.

The walk below `**` and the directory-only listing took a link whose target the user cannot search for a non-directory (`os.path.isdir` and `DirEntry.is_dir` caught the PermissionError), so the subtree was skipped without the promised error. They now treat only a path that is not there or a link that loops as no directory, and raise any other OSError.

`_expand` is split so the literal case is its own function, and the parity fixture gains a root-level `.md` file and the patterns that reach the changed lines.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 15 of 80 small breaks of the lines this PR changes, and not every break was tried

At b8a9f5e: 65 caught · 15 missed

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/novelty/symbols.py:184 drop-clause exc.strerror or exc → (exc) 1
dokimi/dokimi/pattern_glob.py:44 flip-bool False → True 1
dokimi/dokimi/pattern_glob.py:55 flip-bool False → True 1
dokimi/dokimi/pattern_glob.py:67 delete-statement raise → pass 1
dokimi/dokimi/pattern_glob.py:102 drop-clause dirname != pattern and has_magic(dirname) → (dirname != pattern) 72
dokimi/dokimi/commands/context.py:113 drop-clause exc.strerror or exc → (exc) 2
dokimi/dokimi/novelty/symbols.py:184 drop-clause exc.strerror or exc → (exc.strerror) 1
dokimi/dokimi/pattern_glob.py:32 drop-clause keep(entry.name) and (not dironly or _is_dir(entry)) → (keep(entry.name)) 68
dokimi/dokimi/pattern_glob.py:44 return-none False → None 1
dokimi/dokimi/pattern_glob.py:55 return-none False → None 1
dokimi/dokimi/pattern_glob.py:66 return-none False → None 4
dokimi/dokimi/pattern_glob.py:75 take-branch os.path.join(directory, name) if directory else name → (os.path.join(directory, name)) 22
dokimi/dokimi/pattern_glob.py:102 drop-clause dirname != pattern and has_magic(dirname) → (has_magic(dirname)) 72
dokimi/dokimi/commands/context.py:113 drop-clause exc.strerror or exc → (exc.strerror) 2
dokimi/dokimi/novelty/symbols.py:184 swap-boolop exc.strerror or exc → exc.strerror and exc 1

Not checked:

  • 20 more breaks of covered changed lines were over the limit and not tried
  • 4 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

Comment thread dokimi/dokimi/pattern_glob.py Resolved
Comment thread dokimi/dokimi/pattern_glob.py Resolved
…ow an unsearchable directory raises

Review points on intel#1505: directory-only expansion classified every entry before the hidden-name and wildcard filters, so a link to an unsearchable directory that the pattern skips (`runs/.hidden` under `runs/**`, a non-matching link under `runs/open*/`) raised EACCES. `_names` now takes a filter that runs before the directory check.

A literal segment below a wildcard (`runs/*/sub/*.jsonl`) was checked with `os.path.lexists`, which hides EACCES, so a directory that could not be searched dropped its files without a word. It is now an lstat that raises everything but the absent-path errors.

The leading `**/` zero-directory match raised in the same review is already handled at the head (60374d2) and the parity fixture holds `top.md` with `**/*.md`.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: CONTRACT (head b8a9f5e)

  • Contract: changed. errors dokimi/dokimi/novelty/symbols.py:183; dispatch dokimi/dokimi/pattern_glob.py:91
  • Responsibility: candidate. policy dokimi/docs/architecture.md; policy dokimi/tests/test_import_architecture.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

Checked recursive, literal and hidden-name handling in the three CLI consumers. The leading / and permission propagation cases from the previous round are fixed. All 52 focused glob tests passed locally on Linux. A multi- glob now suppresses its own duplicate-path warning; the old callers already counted each file once. The Windows smoke job was still queued at review time.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

(approved) ### Change class: CONTRACT (head b8a9f5e)

@napetrov (#1505 (review)): This approval asks for no change. No commit was added this round, and the head stays at b8a9f5e. The change-class summary and the recap of the leading **/, permission-propagation and multi-** cases need nothing from this PR.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

Review points answered at b8a9f5e; 1 checks still pending (Windows smoke test (py3.13)); every other check passed.

@antonwolfy
antonwolfy merged commit 0eeaaf9 into intel:main Dec 1, 2026
25 checks passed
@antonwolfy
antonwolfy deleted the fix/unlistable-pattern-globs branch December 1, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

glob.glob of a user's pattern skips a directory it cannot list: trace --arm, session paths, --header and --library

5 participants