Skip to content

fix: refuse a deeply nested user file instead of a RecursionError traceback - #1645

Open
napetrov wants to merge 3 commits into
intel:mainfrom
napetrov:arch/r13-2
Open

napetrov wants to merge 3 commits into
intel:mainfrom
napetrov:arch/r13-2

Conversation

@napetrov

@napetrov napetrov commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Refuse a deeply nested user file instead of a RecursionError traceback

Problem

json.loads and yaml.safe_load raise RecursionError (not ValueError) past the interpreter's nesting limit. Readers of user files that catch only ValueError let it escape as a traceback: repo compare --ledger on a deeply nested ledger, and the other user-file readers listed below.

Change

  • repos/ledger.py load_ledger reads through the shared dokimi.files.read_json_input (already refuses deep nesting), wrapping InputError as LedgerError naming the file.
  • Other user-file readers add RecursionError to the handler they already have: repos/compare.py batch_stamp (read as no stamp), repos/conformance.py load_expectations, report/eval_io.py load_eval and answers_by_id, commands/repair_receipt.py, commands/opportunities.py, commands/catalog_scan.py _parse_row, novelty/sweep.py read_rows, task_formats/source.py _parse_jsonl, external/upstream.py load_manifest, skills/formats.py (manifest and marketplace), mcp/factory.py, skill_coverage.py and eval_coverage.py (evals.json).
  • Not changed, from the 66 try blocks in the scan (rec.txt): they read tool or provider output (harness and agent streams, llm_cli, container and probe output, egress proxy, typecheck and l0 tool output, git output), caches, run directories and their reports, split locks, sweep state, or a node run's JSON (promptfoo config); and some read workspace or dataset fields (uptake MCP configs, trigger-set fields, dataset test lists, the mutation and replay run files). Each is a candidate for a follow-up if a user file turns out to reach it.
  • Not changed, found by review outside rec.txt, same gap on user files: read_log (native_logs, an Inspect or promptfoo log), subjects/loader _load_mapping (a subject descriptor), datasets cells, openai_evals ideals. Each escapes as a RecursionError traceback today; a follow-up PR can route them through the same catch.

Evidence

  • tests/test_deep_user_inputs.py: 16 cases, all fail on the base with RecursionError (14 JSON, 2 evals.json), all pass here.
  • Existing ledger, compare, deep-input, eval-coverage, skill-coverage and report suites pass; ruff and mypy clean on the changed modules.

Behaviour

  • A deeply nested ledger, expectations, manifest, runtime config or evals.json is refused with the loader's own error, naming the file, as a malformed one is. A deeply nested eval file reads <path> is nested too deeply to read as JSON.
  • A missing or unreadable ledger now reads cannot read the ledger: cannot read <path>: ... (the wrapper sits on the shared reader's message). An empty --ledger "" reads cannot read the ledger: cannot read .: Is a directory (base: Is a directory; the empty path is .). A non-UTF-8 ledger reads cannot read the ledger: <path> is not UTF-8 text (base: the raw codec error). Exit code and stdout are unchanged. A device path is refused by refuse_device.
  • Optional inputs use the existing malformed-file fallback. report eval still generates the report and omits answers from an unreadable optional answers file. repo compare treats an unreadable _eval/batch.json as missing and warns has no stamp when comparing multiple batches.

🤖 Generated with Claude Code

@napetrov
napetrov requested a review from a team as a code owner December 5, 2026 05:25
Copilot AI balanced review requested due to automatic review settings December 5, 2026 05:25

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.

🟢 Approval recommended

There are no active review issues requiring changes.

No open issues 🎉

What changed in this PR

0 new findings; nothing to fix.

This PR prevents deeply nested user files from producing uncaught RecursionError tracebacks in dokimi’s affected readers.

Changes:

  • Handles excessive nesting through existing malformed-input behavior.
  • Reuses shared readers for ledgers and skill-creator evaluation files.
  • Adds regression tests and documents behavior and remaining exclusions.
File Description
dokimi/​tests/​test_deep_user_inputs.py Adds 16 deep-input regression cases.
dokimi/​scripts/​duplicates_baseline.json Removes the extracted reader’s duplication baseline.
dokimi/​dokimi/​task_formats/​source.py Records deeply nested JSONL lines as invalid.
dokimi/​dokimi/​skills/​formats.py Handles deeply nested manifests and marketplaces.
dokimi/​dokimi/​skill_coverage.py Uses the shared evaluation-file reader.
dokimi/​dokimi/​repos/​ledger.py Loads ledgers through the shared JSON reader.
dokimi/​dokimi/​repos/​conformance.py Converts excessive YAML nesting into a loader error.
dokimi/​dokimi/​repos/​compare.py Treats deeply nested batch stamps as absent.
dokimi/​dokimi/​report/​eval_io.py Handles deeply nested evaluation and answers files.
dokimi/​dokimi/​novelty/​sweep.py Handles excessive nesting in resume rows.
dokimi/​dokimi/​mcp/​factory.py Reports excessive runtime-config nesting as an input error.
dokimi/​dokimi/​external/​upstream.py Refuses deeply nested upstream manifests.
dokimi/​dokimi/​eval_coverage.py Extracts a shared nesting-aware evaluation reader.
dokimi/​dokimi/​commands/​repair_receipt.py Refuses deeply nested report input.
dokimi/​dokimi/​commands/​opportunities.py Handles excessive nesting during input parsing.
dokimi/​dokimi/​commands/​catalog_scan.py Handles deeply nested resume rows.
dokimi/​changelog.d/​20261204_100000_napetrov_deep-user-input-refusal.md Documents fixes and remaining exclusions.

Review effort: Balanced

@codecov-commenter

codecov-commenter commented Dec 5, 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.43%. Comparing base (19e5222) to head (abc5217).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1645      +/-   ##
==========================================
- Coverage   96.44%   96.43%   -0.01%     
==========================================
  Files         585      585              
  Lines       76600    76600              
  Branches    13175    13174       -1     
==========================================
- Hits        73876    73870       -6     
  Misses       1671     1671              
- Partials     1053     1059       +6     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/catalog_scan.py 97.34% <100.00%> (ø)
dokimi/dokimi/commands/opportunities.py 86.58% <100.00%> (ø)
dokimi/dokimi/commands/repair_receipt.py 100.00% <100.00%> (ø)
dokimi/dokimi/eval_coverage.py 99.22% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/external/upstream.py 91.77% <100.00%> (ø)
dokimi/dokimi/mcp/factory.py 97.52% <100.00%> (ø)
dokimi/dokimi/novelty/sweep.py 94.83% <100.00%> (ø)
dokimi/dokimi/report/eval_io.py 100.00% <100.00%> (ø)
dokimi/dokimi/repos/compare.py 99.53% <100.00%> (ø)
dokimi/dokimi/repos/conformance.py 99.21% <100.00%> (ø)
... and 4 more

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

…ceback

json.loads and yaml.safe_load raise RecursionError, not ValueError, past the
interpreter's nesting limit. The user-file readers that caught only ValueError
(repo compare --ledger, the batch stamp, eval and answers files, repair
receipts, --resume and --jsonl rows, task source lines, skill, eval-coverage
and upstream manifests, the runtime config) let it escape as a traceback. The
ledger now goes through the shared reader in dokimi.files, which already
refuses deep nesting; the others catch RecursionError with the handler they
already have.

Tests: tests/test_deep_user_inputs.py (16 cases, red on the base, green here).
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@exai-bot

exai-bot commented Dec 5, 2026 •

Copy link
Copy Markdown

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

CI at abc5217: 26 passing, 4 skipped.

Review details
  • Commit reviewed: abc5217 against merge base 19e5222
  • Coverage: 17 files in 2 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 296k tokens (193k from cache), 35s
  • Tool calls: 37 (26 file_read, 5 code_search, 2 local_check_results, 2 pr_threads, 1 ci_status, 1 file_read_diff)
  • Deep user-input validation, format handling, and regression coverage: 8 files
  • Adopt input validation across commands and integration consumers: 9 files

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

@napetrov, could you fix the small thing I've marked fix before merge (in the line comments) and answer my question below? I'll approve once that's done.
I'll approve once that's done.

My question before I approve:

  • A deeply nested answers file, or a deeply nested batch stamp, is read as no answers or no stamp (dokimi/dokimi/report/eval_io.py:34, dokimi/dokimi/repos/compare.py:191), while a deeply nested ledger or evals.json is refused. State the choice in the PR description, as it asks, or refuse deep answers and stamp files the way the ledger is refused, so the user is told the file was not read.

What I checked on e7c2b1d:

  • When I changed the code on purpose, the tests still passed for 5 of 9 changes, and no test pins these down yet (non-blocking): dokimi/dokimi/commands/opportunities.py:55 (the handled error is raised again), dokimi/dokimi/report/eval_io.py:34 (the handled error is raised again), dokimi/dokimi/repos/compare.py:191 (the handled error is raised again) and 2 more.
  • The 16 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (36,378 tests), apart from failures main has too.
  • It merges cleanly onto main.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AO2JI
Thread: PRR_kwDOVBg7g88AAAABcgRV-g
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vchamarthi

State the choice in the PR description
Clarified the description and changelog in abc5217.

@napetrov

napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

abc5217 corrects the eval coverage changelog entry. The description now explains the existing fallback for unreadable optional answers and batch stamps.

For the three named mutation notes, I changed each handler to re-raise. The existing deep-input test for opportunities, answers, or stamps failed in each run.

This branch has not been deployed

No deployments
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.

5 participants