Skip to content

fix(subjects): a descriptor path past the file-name limit is reported as a missing descriptor - #1078

Merged
xaleryb merged 3 commits into
intel:mainfrom
antonwolfy:fix/subject-descriptor-long-name
Nov 22, 2026
Merged

xaleryb merged 3 commits into
intel:mainfrom
antonwolfy:fix/subject-descriptor-long-name

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

subjects show, subjects run and subjects list --subjects-root end in an OSError traceback when the path they are given has a component over the file-name limit (255 bytes on Linux). On main, _load_mapping(Path("x" * 5000 + ".json")) raises OSError: [Errno 36] File name too long from path.is_file() in dokimi/dokimi/subjects/loader.py; cmd_subjects_show and cmd_subjects_run catch only ValueError and FileNotFoundError, so a missing descriptor gets Error: cannot load subject: <path> (exit 2) and this one gets the traceback. cmd_subjects_list has the same cause for its root: Path.is_dir() on --subjects-root with a 300-character component raises OSError: [Errno 36].

Of the fix options the issue lists (read the OSError as a missing file in _load_mapping, or catch it at the call sites), this takes the first: one place, and a later caller of load_subject is covered. Only a name-too-long error is read as missing (ENAMETOOLONG, or on Windows winerror 123, 206 or 1921); a permission or I/O error on an existing path still propagates, since calling it "missing" would give a wrong message.

Closes #1022

The scorecard digests have the same cause on another input and are handled by #1023 (refs #911); they are not touched here.

Changes

  • dokimi/dokimi/subjects/loader.py: _load_mapping treats an OSError from the is_file() probe as a missing file, raising FileNotFoundError(path), when name_too_long holds. The probe still comes before the suffix check, so a long name with an unsupported suffix is reported as missing, as before.
  • dokimi/dokimi/commands/subjects.py: cmd_subjects_list applies the same check to --subjects-root and refuses it with --subjects-root is not a directory: <path> (exit 2).
  • dokimi/tests/test_subjects_long_name.py (new; tests/test_subjects.py is at its growth-ratchet size): the load, command and list cases above, a 300-character component under PATH_MAX, the unsupported-suffix order, the Windows codes, a PermissionError that must still propagate from both probes, and a subjects list root whose is_dir() raises ENAMETOOLONG (on a Python where Path.is_dir() returns False for a long name, the 5000-character root never reaches the handler, so this case makes it run on every version).
  • Changelog fragment (Fixed).

Risk

Only inputs that raised OSError change: a descriptor path or --subjects-root with a component over the file-name limit now exits 2 with cannot load subject: ... or --subjects-root is not a directory: ... instead of a traceback. Paths of normal length, missing descriptors, the suffix error and other OSErrors behave as before.

Open PRs #956 and #954 also change commands/subjects.py (an error message in cmd_subjects_run, the --max-tokens option in register) and #956 one message in loader.py (_member_specs); none touches the lines changed here, so a merge with either is clean.

Testing

On a Linux review host, at 0a929158 (on main 36075a0):

  • make ci-local: 36 passed, 0 failed, 14 skipped (steps that need another runner, Docker, micromamba, semgrep or a PR event). 24494 tests passed, 19 skipped; changed-line coverage 100%; mutation of changed lines: 17 of 17 killed.
  • On main's code, tests/test_subjects_long_name.py gives 8 failed, 2 passed, first on OSError: [Errno 36] File name too long from Path.is_file(); the two that pass are the PermissionError tests, which pin what must not change. Here: 11 passed.
  • Mutant for the added subjects list test: re-raising every OSError from the root probe in cmd_subjects_list fails it (and the 5000-character root test, on this Python 3.13).
  • Mutants, each failing the tests named: dropping the errno check in _load_mapping fails 7 tests (the load, command, 300-character and Windows cases); widening it to any OSError fails the PermissionError test; emptying the Windows codes fails the three Windows cases; moving the suffix check before the probe fails the unsupported-suffix test; dropping or widening the check in cmd_subjects_list fails the list test and the list PermissionError test respectively.
  • Not run: the matrix legs on Python 3.11, 3.12 and 3.14, and Windows (the Windows codes are pinned with a faked winerror).

Open questions

None.

Revert

A plain revert restores the traceback. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • 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)

… as a missing descriptor (intel#1022)

`load_subject` probed the descriptor with `Path.is_file()`, which on Linux raises `OSError: [Errno 36] File name too long` for a component over the limit. `subjects show` and `subjects run` catch only `ValueError` and `FileNotFoundError`, so the user got a traceback where a missing descriptor gets `cannot load subject: <path>`. `subjects list --subjects-root` had the same traceback from `Path.is_dir()`.

`_load_mapping` now reads an `OSError` from that probe as a missing file and raises `FileNotFoundError(path)` when its errno is ENAMETOOLONG or its winerror is 123, 206 or 1921. `subjects list` applies the same check to the root and refuses it as not a directory. Any other `OSError`, a permission or I/O error on an existing path, still propagates. The suffix check still comes after the probe, so a long name with an unsupported suffix is reported as missing, as before.

The tests are in a new file because `tests/test_subjects.py` is at its growth-ratchet size.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 21, 2026 13:41
@antonwolfy antonwolfy self-assigned this Nov 21, 2026
@exai-bot

exai-bot commented Nov 21, 2026 •

Copy link
Copy Markdown

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

CI at dea8d90: 21 passing, 3 skipped.

Review details
  • Commit reviewed: dea8d90 against merge base 0a92915
  • Coverage: 1 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 20k tokens (9k from cache), 5s
  • Tool calls: 1 (1 file_read)
  • dokimi/changelog.d/20261121_130000_subject-descriptor-long-name.md: 1 file

@codecov-commenter

codecov-commenter commented Nov 21, 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 95.93%. Comparing base (36075a0) to head (dea8d90).
⚠️ Report is 7 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    #1078   +/-   ##
=======================================
  Coverage   95.92%   95.93%           
=======================================
  Files         450      451    +1     
  Lines       59527    59622   +95     
  Branches    10265    10273    +8     
=======================================
+ Hits        57101    57197   +96     
+ Misses       1507     1505    -2     
- Partials      919      920    +1     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/subjects.py 94.71% <100.00%> (+0.14%) ⬆️
dokimi/dokimi/subjects/loader.py 77.98% <100.00%> (+1.32%) ⬆️

... and 21 files with indirect coverage changes

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

…be as not a directory

Codecov names the ENAMETOOLONG handler in cmd_subjects_list as not covered: newer Pythons make Path.is_dir return False for a long name, so the 5000-character root never reaches the handler there. The new test makes is_dir raise ENAMETOOLONG, so the handler runs on every Python version.

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

Copy link
Copy Markdown
Contributor Author

Review points answered at 0a92915; 6 checks still pending (Fidelity golden (claude-code 2.1.318), Mutation of changed lines, Package install smoke test (py3.11), Test Linux Python 3.14, Test Linux Wheels Python 3.14, Tests (py3.14)); every other check passed.

@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: LOCAL (head 0a92915)

  • Contract: none
  • Responsibility: none
  • Dependency: none
  • Review depth: skim: local change, check diff + tests
  • Coverage gaps: none

One documentation nit. I checked the loader and both CLI path probes, including an actual inaccessible descriptor on Python 3.14.

Focused tests on 0a9291588: 11 passed in 0.22s. CI on head 0a92915: 0 failing Actions jobs; merge base 36075a0 is the base tip.

intel#1022)

Path.is_file() turns the permission error into False on 3.14, so a descriptor below an unsearchable directory raises FileNotFoundError there, on the base as well. The changelog said a permission or I/O error on an existing path always propagates.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>

@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 dea8d90. Ran the earlier head 0a92915 merged with main: tests/test_subjects_long_name.py has 9 failures and 2 passes on main's code (the two passes pin PermissionError) and 11 passes on the head; widening the handler to any OSError turns the PermissionError test red; the full suite, ruff, mypy, bandit and the growth, comment-block and docs gates are clean. dea8d90 only qualifies the changelog sentence for Python 3.14 (napetrov's note); the code is unchanged. CI is green on this head.

@xaleryb
xaleryb merged commit c322a90 into intel:main Nov 22, 2026
24 checks passed
@antonwolfy
antonwolfy deleted the fix/subject-descriptor-long-name branch November 22, 2026 10:15
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.

subjects plan/run/evidence: a descriptor path longer than the file-name limit ends in an OSError traceback

5 participants