Skip to content

fix(mcp): local: and okf: refuse a doc tree with a directory they cannot list (#1207) - #1369

Merged
xaleryb merged 4 commits into
intel:mainfrom
antonwolfy:fix/doc-source-unlistable-dir
Nov 29, 2026
Merged

xaleryb merged 4 commits into
intel:mainfrom
antonwolfy:fix/doc-source-unlistable-dir

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#1207: local: and okf: listed the doc tree with rglob("*"), which skips a directory it cannot list without an error. On main, a source holding a.md and sub/b.md with sub at mode 0o111 (as a non-root user):

Call On main
LocalMarkdownClient(d)._collect_files() and OKFClient(d)._collect_files() ['a.md']
get_library_docs("x", "parallel_for") files ['a.md']
check_connection() True
require_local_doc_source("local:<d>") and ("okf:<d>") accepted, so eval questions generate goes on with the smaller set (or default seed topics, since RagasSeedExtractor swallows a retrieval error)

A root directory at 0o111 holding a.md gave [] and a "no doc files found" warning from both clients, though the source is not empty (the preflight already refused that root with "permission denied", and still does).

Of the issue's three options this takes (a): a directory that cannot be listed is an error, raised as MCPConnectionError like a missing path. The repo settles this bug class the same way at its other sites (scorecard digests, catalog scan, arms, reach, novelty bundle: "a directory that cannot be listed is an error, not a smaller tree" in docs/reach-matrix.md), and (b) or (c) would leave the measured docs smaller than the user's with at most a log line, the defect the issue reports.

answers generate, evaluate and a local:/okf: treatment arm do not run this preflight (the #1086 check, which only eval questions generate and benchmark preflight call): a missing path is not refused before their run, and a treatment arm records retrieval_failed for each question. That is tracked in #1368.

Closes #1207

Changes

  • mcp/utils.py: list_doc_tree lists a directory with digest_entries.listed_entries and turns an OSError into MCPConnectionError("<client>: cannot list <directory>: <error>"), naming the directory the error names.
  • mcp/local_markdown.py, mcp/okf_client.py: _collect_files and _iter_candidate_files list through it instead of rglob("*"). get_library_docs raises the MCPConnectionError; check_connection returns False and logs a warning that names the directory. The filters, the size limit, the single-file source, the empty-directory warning and the skip of an unreadable file are unchanged.
  • mcp/factory.py: require_local_doc_source lists the tree of a directory source that passed its other checks and raises InputError("doc source <source>: cannot list <directory>: <error>") (exit 2), so eval questions generate and benchmark preflight refuse it before any seed extraction. The existing refusals and their messages are unchanged. listed_entries is imported inside the helper, so the module's import block is as on main.
  • docs/adding-doc-source.md: what local: and okf: do with a missing path, an unlistable directory, an empty directory and an unreadable file.
  • tests/test_doc_source_unlistable.py: both clients and the preflight, parametrized. The questions generate test patches RagasSeedExtractor on the dokimi.questions package, the name the command reads, so it fails when the extractor is reached.
  • Changelog fragment (Fixed): it says eval questions generate and benchmark preflight exit 2 with cannot list <directory> for a directory below the root, and with the existing cannot read <root>: permission denied for a root the user cannot read or search.

Risk

A local: or okf: source with a directory the user cannot list is refused now (MCPConnectionError from retrieval, exit 2 from eval questions generate and benchmark preflight); it was read as a smaller tree before. A tree that can be listed gives the same files and docs. The order of the files _collect_files returns is no longer rglob's: OKFClient sorts them as before, and LocalMarkdownClient's scored list is sorted by (-score, path), so the results are in the same order. No existing test pinned the silent skip.

A tree is refused for any directory the user cannot list, even one that holds no docs (a root-owned lost+found under a mount point used as the doc root, for one); the message names that directory.

Open PRs on mcp/factory.py, each checked with git merge-tree against this branch:

Testing

On a Linux review host, at b714c1f3 (on main 26e3083):

  • make ci-local: 1 failed, 37 passed, 16 skipped; its pytest step 30819 passed, 27 skipped, 2 failed and 1 error, all three Timeout (>60.0s) from pytest-timeout under host load (test_unclosed_openers.py::test_cli_trace_heredoc_scans_many_openers_on_one_line_of_a_closed_heredoc_in_linear_time, test_eval_tasks_generate_history.py::test_usage_errors[extra4-is not a regular expression], test_import_architecture.py::test_every_module_is_in_a_layer); run alone, those three files pass (383 and 54 passed). The commit on top of 77f9455a changes only the changelog fragment. At 77f9455a the mutation step had 29 mutants of the changed lines, 29 killed, 0 survived (python scripts/mutate_changed.py --base origin/main). The comment-block and duplicate checks pass.
  • tests/test_doc_source_unlistable.py on main's code: 15 failed, 6 passed (the first failure is DID NOT RAISE MCPConnectionError from get_library_docs with sub at 0o111; the tests that patch listed_entries in dokimi.mcp.utils fail there with AttributeError, the name this PR adds; the unreadable-root preflight test passes, since that message is unchanged); here 21 passed.
  • Mutants, each failing the tests named: rglob("*") back in LocalMarkdownClient or in OKFClient (the subdirectory and the root test of that client); the OSError conversion dropped (a raw PermissionError, 4 tests); check_connection returning True on the error (the subdirectory test, for each client); the warning not naming the directory (the subdirectory test); the preflight listing dropped (the two preflight tests, and the questions generate test, which fails with reached the extractor or generator raised from the RagasSeedExtractor(...) call). The eight mutants of the changed lines that survived an earlier run (not unreadable and dropped in mcp/factory.py; the exc.filename or ... and exc.strerror or ... fallbacks in mcp/factory.py and mcp/utils.py) are killed by the unreadable-root preflight test, the subdirectory tests that match cannot list <root>/sub: (and Permission denied$ for the preflight), and the tests that raise an OSError with no filename or no strerror from the listing.
  • Not run: Python 3.11, 3.12 and 3.14; the tests that need a user that cannot list a mode 0o111 directory skip as root.

Open questions

None.

Revert

A plain revert restores the silent skip of a directory that cannot be listed. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes [the full run had 3 pytest-timeout failures under host load; each passes alone]
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…not list (intel#1207)

Both clients listed the tree with rglob("*"), which skips a directory it cannot list without an error: a source holding a.md and sub/b.md with sub at mode 0o111 returned a.md alone, check_connection() said True, and the preflight accepted it. A root at 0o111 gave no docs and a "no doc files found" warning.

The clients now list with digest_entries.listed_entries; a directory that cannot be listed raises MCPConnectionError naming it from get_library_docs, as a missing path does. check_connection() returns False with a warning that names the directory. require_local_doc_source lists the tree of a root that passed its other checks and raises InputError "cannot list <directory>", so eval questions generate exits 2 instead of falling back to default seed topics. A listable tree gives the same files, a directory with no doc files still warns and gives no docs, and an unreadable file is still skipped. docs/adding-doc-source.md says what each case does.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…entries lazily (intel#1207)

The questions-generate test patched RagasSeedExtractor on dokimi.questions.ragas_seed, but cmd_questions_generate reads it from the dokimi.questions package, so the real extractor ran when the preflight listing was missing. The test now patches the package attribute and fails on the extractor mock.

factory.py imports listed_entries inside _require_listable, so the module's import block is as on main and does not conflict with a change to the InputError import line. The unused root parameter of the test helper _files is dropped.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…llbacks of the doc-source listing (intel#1207)

Eight mutants of this PR's lines survived the mutation step: the `not unreadable and` guard of the preflight, and the `exc.filename or ...` and `exc.strerror or ...` fallbacks of the client and preflight messages.

An unreadable root now has a preflight test that expects `cannot read <root>: permission denied` and no `cannot list`. The subdirectory tests of the clients and the preflight match the directory the message names, and the preflight message ends with the bare strerror. An `OSError` without a filename, and one without a strerror, is raised from the listing and the exact messages are asserted.

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

exai-bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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

CI at `b714c1f`: 1 failing, 20 passing, 4 skipped

Not fully read: job Tests (py3.14): HTTP 404: The specified blob does not exist.

At b714c1f, Tests (py3.14) is failing; the other 24 checks pass or are skipped. Local lint and type checks pass, but the failed job's unavailable log prevents determining its cause or proposing a justified fix. Retrieve the job output or rerun the check to resolve attribution.

Check Status Assessment
Tests (py3.14) failing Cause unclear. The check reports failure, but its job log could not be retrieved (HTTP 404), and log search returned no failure details. Reading the diff and implementation does not establish which test or step failed, so attribution to this change is not supported.
Review details
  • Commit reviewed: b714c1f against merge base 26e3083
  • Coverage: 7 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 190k tokens (125k from cache), 47s
  • Tool calls: 19 (13 file_read, 3 code_search, 1 ci_status, 1 local_check_results, 1 pr_comments)
  • Handle unlistable documentation source directories, with tests and documentation: 7 files

@codecov-commenter

codecov-commenter commented Nov 28, 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.22%. Comparing base (26e3083) to head (b714c1f).
⚠️ Report is 1 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    #1369      +/-   ##
==========================================
- Coverage   96.23%   96.22%   -0.01%     
==========================================
  Files         509      509              
  Lines       67757    67785      +28     
  Branches    11765    11767       +2     
==========================================
+ Hits        65204    65225      +21     
- Misses       1571     1574       +3     
- Partials      982      986       +4     
Files with missing lines Coverage Δ
dokimi/dokimi/mcp/factory.py 97.00% <100.00%> (+0.26%) ⬆️
dokimi/dokimi/mcp/local_markdown.py 90.16% <100.00%> (+5.95%) ⬆️
dokimi/dokimi/mcp/okf_client.py 88.54% <100.00%> (+3.75%) ⬆️
dokimi/dokimi/mcp/utils.py 96.82% <100.00%> (+0.39%) ⬆️

... and 7 files with indirect coverage changes

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

…1207)

Settles the review point on the changelog fragment: `require_local_doc_source` keeps `cannot read <root>: permission denied` for a root the user cannot read or search, and `cannot list <directory>` is the message for a directory below the root.

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

xaleryb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor
  • Ran: the head merged with current main on Python 3.13, using real chmod 0o000 and 0o111 subdirectories as a non-root user for both local: and okf:. Also ran the full suite, ruff, mypy, bandit -ll, check_growth, check_comment_blocks, and 10 mutants of the changed lines. All 10 mutants were killed.
  • On a readable tree (including a symlinked subdirectory), file collection, get_library_docs output and check_connection are the same as on main.
  • If a subdirectory cannot be listed, eval questions generate --doc-source local:|okf:<dir> now exits 2 with doc source ...: cannot list <dir>/sub: Permission denied before any model call. Main exits 0 and skips the subdirectory without saying so. This matches the cannot list convention of fix(readers): refuse a directory that cannot be listed in six readers of a user's tree (#1210) #1366 and fix(readers): dashboard generate and hits judge refuse a directory they cannot list, eval inspect reports it #1390, and the PR reuses digest_entries.listed_entries instead of adding a new helper.
  • An earlier point (the changelog's message for an unreadable root) is fixed in b714c1f; the output is now cannot read <root>: permission denied.
  • No open findings. Nothing is left for the author.

@xaleryb xaleryb 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.

Approved on b714c1f. local: and okf: doc sources exit 2 with cannot list

before any model call when a subdirectory cannot be listed, reusing listed_entries; a readable tree gives the same files and output as main. All 10 mutants of the changed lines are killed. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.

@xaleryb
xaleryb merged commit 757f61a into intel:main Nov 29, 2026
33 of 34 checks passed
@antonwolfy
antonwolfy deleted the fix/doc-source-unlistable-dir branch November 29, 2026 10:27
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.

doc sources: local: and okf: list the files of a tree without a directory they cannot list; what should they do?

4 participants