Skip to content

fix(novelty): a too-deeply nested routing file is no partial result - #793

Merged
antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:fix/partial-guard-recursion
Nov 16, 2026
Merged

antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:fix/partial-guard-recursion

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the review of #764, where _is_partial_file caught OSError and ValueError but not RecursionError, so a file of about 20000 [ made save_result raise after a paid, capped run (review). The review noted it as pre-existing; there is no reply and no open issue.

On main, _is_partial_file on a file holding "[" * 20000 raises RecursionError: maximum recursion depth exceeded while decoding a JSON array from a unicode string. save_result calls it when the output path already exists and the result is partial, so a capped novelty routing run died while saving, after the model calls were paid for. Other readers already catch RecursionError in the except at: read_json_input (dokimi/dokimi/utils.py:789), the cells file (dokimi/dokimi/eval/cells.py:157), arm and plugin setup (dokimi/dokimi/commands/arms.py:75), the leak command's inputs (dokimi/dokimi/commands/leak.py:117), catalog skill discovery (dokimi/dokimi/commands/catalog.py:251) and the headroom arms files (dokimi/dokimi/commands/headroom.py:245). I read each line and the call it wraps; I did not run a deep file through each.

Changes

  • dokimi/dokimi/commands/novelty_routing_report.py _is_partial_file: also catches RecursionError, so a file too deep to parse is treated like a file this cannot read: not a partial result. save_result then keeps it and writes the partial result to the first sidecar beside it; _takes_partial skips it.
  • dokimi/tests/test_novelty_routing_spend_cap_partial.py: a test that a 20000-deep file gives False from _is_partial_file, and that save_result over it does not raise, leaves the file as it was and writes the partial result to a sidecar.
  • Changelog fragment (Fixed).

Risk

None for files that parse: the result is unchanged. A file nested too deep to parse used to raise RecursionError out of save_result and _takes_partial; it is now kept and the partial result goes to a sidecar, as for any other unreadable file.

Testing

On a Linux review host, at bfff737 (on main f4c52f7):

  • make ci-local: 33 passed, 0 failed, 14 skipped (other Python versions' matrix legs, --with-docker jobs, jobs that only run on a PR or need tools it lacks: conda-forge, semgrep, Claude Code install, fuzz). 21544 tests passed, 19 skipped; changed-line coverage 100% (1 line measured). The first run hit a scratch-space failure unrelated to the change; the rerun was clean.
  • Repro: on main, _is_partial_file on a file of "[" * 20000 raises RecursionError; at this head it returns False.
  • Mutants: the new test fails with RecursionError when RecursionError is removed from the except clause, and fails the same way against main's code.
  • Merged together with test/retention-lexical-score, test/audit-ratchet-nits on main b84b143: pytest -n auto 21664 passed, 19 skipped, mypy clean, ruff check clean.
  • Not run: the other Python versions (3.11, 3.12, 3.14) and Windows; the test uses a depth of 20000, well past the interpreter's recursion limit on each.

Open questions

None.

Revert

A plain revert restores the old behaviour: a too-deeply nested routing file makes save_result raise RecursionError. 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)

Settles the review point of intel#764 that `_is_partial_file` caught OSError and ValueError but not RecursionError: a routing file holding about 20000 `[` made `save_result` raise after a paid, capped run.

`_is_partial_file` now also catches RecursionError, so such a file is treated like one this cannot read: not a partial result, and the capped run writes its partial result to the sidecar beside it. A test pins both the guard and `save_result` over a 20000-deep file. Changelog fragment (Fixed).

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

exai-bot commented Nov 15, 2026 •

Copy link
Copy Markdown

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

CI at bfff737: 25 passing, 3 skipped.

Review details
  • Commit reviewed: bfff737 against merge base f4c52f7
  • Coverage: 3 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 54k tokens (33k from cache), 8s
  • Tool calls: 4 (3 file_read, 1 code_search)
  • small change set: 3 files

@codecov-commenter

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.75%. Comparing base (f4c52f7) to head (bfff737).
⚠️ Report is 6 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     #793   +/-   ##
=======================================
  Coverage   95.75%   95.75%           
=======================================
  Files         415      415           
  Lines       55411    55510   +99     
  Branches     9520     9536   +16     
=======================================
+ Hits        53060    53155   +95     
- Misses       1451     1454    +3     
- Partials      900      901    +1     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/novelty_routing_report.py 99.09% <100.00%> (ø)

... and 16 files with indirect coverage changes

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

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

Reviewed bfff737: Not approved yet: waiting on @antonwolfy to back 1 unverified claim (below). Nothing to fix in the code.

Blocking

  • Not verified: The description says eval/cells.py, arms.py, leak.py, catalog.py and headroom.py already catch RecursionError; only the name's presence in those files was checked, not each catch. Name the catch line for each in the description, or drop the list. For @antonwolfy.
Verified on bfff737: 7 checks pass
Area What holds How
Changed tests The changed test file passes on the head: 52 passed, including the new test that pins the deep-file guard and save_result tests on the head
New test on main The new test test_a_file_nested_too_deep_to_parse_is_not_a_partial_result_and_save_result_keeps_it fails on main with RecursionError from json.loads same tests on main
Guard pinned Removing RecursionError from the except in _is_partial_file fails the new test with RecursionError broke the code, tests caught it
Merge The PR merges onto current main with no conflict merge onto main
Path inputs _is_partial_file returns False for a missing file, a directory, an empty file and a dangling symlink; _takes_partial returns False for the dangling symlink; a path with spaces and non-ASCII characters is read; a relative path is read from another working directory ran it, edge input (paths)
Structured inputs _is_partial_file returns False for {}, [], null, ["partial"], a status that is a list, truncated JSON and 20000 [, and True for {"partial": ...} with an extra key and for {"status": "partial"} ran it, edge input (structured)
Deep nesting A file of 20000 [ gives False from _is_partial_file and _takes_partial; save_result writes the partial result to routing.partial.json and leaves the deep file as it was; a 500-deep file under a status of partial is read as partial ran it, edge input (nesting)

@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) Reviewed bfff737: **Not approved yet: waiting on @antonwolfy to back 1 unverified claim (belo

@vchamarthi (#793 (review)): No code change. The description now names the catch line for each reader instead of the file list: dokimi/dokimi/utils.py:789 (read_json_input), eval/cells.py:157, commands/arms.py:75, commands/leak.py:117, commands/catalog.py:251 and commands/headroom.py:245. I read each except and the call it wraps: all list RecursionError. It also says these were read, not run with a deep file. catalog.py:251 wraps skill discovery (frontmatter), not a JSON read, so it is a nesting guard of the same kind rather than the same parser.

@vlad-perevezentsev vlad-perevezentsev 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.

LGTM

I checked bfff737. The fix is right: _is_partial_file now treats a file too deeply nested for json as unreadable, so save_result keeps it and writes the partial result to a sidecar, the same as for any other unreadable file.

Merge: safe now: it merges cleanly into current main, 14 commits behind, and no other open PR touches its files.

What I ran, at bfff737:

  • make ci-local --offline: 21 passed, 1 failed, 20 skipped. The failure is schema_compat on novelty.v1.json (/partial/reason), and it does not come from this PR, which touches no schema.

Checked, no issues

  • The test: on the base, json.loads raises RecursionError on "[" * 20000, and the old except (OSError, ValueError) does not catch it, so the new test fails there. It checks that the deep file stays as it was and that the sidecar holds the partial result.
  • Changelog: the Fixed fragment says what a user sees.

@antonwolfy
antonwolfy merged commit 41c2ba9 into intel:main Nov 16, 2026
28 checks passed
@antonwolfy
antonwolfy deleted the fix/partial-guard-recursion branch November 16, 2026 11:49
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