Repository navigation
fix(novelty): a too-deeply nested routing file is no partial result - #793
Conversation
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>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
vchamarthi
left a comment
There was a problem hiding this comment.
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.pyandheadroom.pyalready catchRecursionError; 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) |
@vchamarthi (#793 (review)): No code change. The description now names the catch line for each reader instead of the file list: |
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
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 isschema_compatonnovelty.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.loadsraisesRecursionErroron"[" * 20000, and the oldexcept (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
Fixedfragment says what a user sees.
Summary
Follow-up to the review of #764, where
_is_partial_filecaughtOSErrorandValueErrorbut notRecursionError, so a file of about 20000[madesave_resultraise 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_fileon a file holding"[" * 20000raisesRecursionError: maximum recursion depth exceeded while decoding a JSON array from a unicode string.save_resultcalls it when the output path already exists and the result is partial, so a cappednovelty routingrun died while saving, after the model calls were paid for. Other readers already catchRecursionErrorin theexceptat: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 catchesRecursionError, so a file too deep to parse is treated like a file this cannot read: not a partial result.save_resultthen keeps it and writes the partial result to the first sidecar beside it;_takes_partialskips it.dokimi/tests/test_novelty_routing_spend_cap_partial.py: a test that a 20000-deep file givesFalsefrom_is_partial_file, and thatsave_resultover it does not raise, leaves the file as it was and writes the partial result to a sidecar.Risk
None for files that parse: the result is unchanged. A file nested too deep to parse used to raise
RecursionErrorout ofsave_resultand_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(onmainf4c52f7):make ci-local: 33 passed, 0 failed, 14 skipped (other Python versions' matrix legs,--with-dockerjobs, 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.main,_is_partial_fileon a file of"[" * 20000raisesRecursionError; at this head it returnsFalse.RecursionErrorwhenRecursionErroris removed from theexceptclause, and fails the same way againstmain's code.test/retention-lexical-score,test/audit-ratchet-nitsonmainb84b143:pytest -n auto21664 passed, 19 skipped,mypyclean,ruff checkclean.Open questions
None.
Revert
A plain revert restores the old behaviour: a too-deeply nested routing file makes
save_resultraiseRecursionError. Nothing is stored.Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)