fix(validator): refuse to overwrite corrupt PATS_FILE in save_pat / remove_pat#829
Open
ebios-star wants to merge 1 commit intoentrius:testfrom
Open
fix(validator): refuse to overwrite corrupt PATS_FILE in save_pat / remove_pat#829ebios-star wants to merge 1 commit intoentrius:testfrom
ebios-star wants to merge 1 commit intoentrius:testfrom
Conversation
…emove_pat Previously `_read_file` swallowed `(json.JSONDecodeError, OSError)` and returned `[]` on any failure, so a partial-write or on-disk corruption of `data/miner_pats.json` produced this sequence: 1. `_read_file()` silently returns `[]`. 2. `save_pat()` appends one fresh entry to the empty list and writes it. 3. The atomic `os.replace` overwrites the corrupt file with a single-entry list — every previously stored PAT is gone forever. The read path keeps its graceful-degradation contract (load_all_pats / get_pat_by_uid still return empty/None on corrupt files so the validator scoring round can continue), but the write path now refuses to overwrite an unreadable file: - `_read_file(*, raise_on_corrupt=False)` is the new signature. - Read callers keep the default and additionally log a warning so the corruption is at least visible in operator logs. - `save_pat` and `remove_pat` pass `raise_on_corrupt=True`; the json.JSONDecodeError / OSError now propagates up to the bittensor axon handler, which surfaces it to the broadcasting miner as a retriable error rather than acknowledging a silent data-loss write. Adds `TestCorruptFileRefusesToOverwrite` covering the two write paths and the on-disk preservation invariant. The existing `test_load_handles_corrupt_file` is unchanged and still passes. Closes entrius#781.
Contributor
Author
|
@anderdc @LandynDev — friendly ping for review when you have a moment. Closes #781. Read paths ( Happy to rebase if needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #781.
`_read_file` in gittensor/validator/pat_storage.py was swallowing `(json.JSONDecodeError, OSError)` and returning `[]` on every failure, so a partial-write or on-disk corruption of `data/miner_pats.json` produced this sequence:
The read path keeps its graceful-degradation contract (`load_all_pats` and `get_pat_by_uid` still return empty/None on corrupt files so the validator scoring round can continue), but the write path now refuses to overwrite an unreadable file:
Related Issues
Closes #781.
Type of Change
Testing
Checklist