Repository navigation
Conversation
write() opened the destination before the new JSON existed, so a write that stopped partway truncated the previous judged.json and left every later reader with nothing. Stage the JSON beside the destination and rename it over the original, the way runmark.py and schedule.py already publish their files.
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
harness2.core.judge.write()publishedjudged.jsonby callingPath.write_text()on the destination itself, which truncates the previous file before any of the new JSON exists. A write that stops partway — a full disk, an interrupted run — therefore destroyed the last valid grades, and every later reader of that file found nothing.The JSON is now staged in a temporary file beside the destination and renamed over it with
os.replace, so a failed publish leaves the previousjudged.jsonexactly as it was. The destination path and the on-disk format (indent=2,default=str,frac/gradedmerged into each row) are unchanged.Where the shape comes from
This is not a new pattern in the tree — it is the one the project already uses in two other places, so the change copies that wiring rather than inventing a third:
harness2/core/runmark.py:118-121stagesf"{MARK}.{os.getpid()}.tmp"and finishes withos.replace.harness2/core/schedule.py:354-356does the same with.json.tmpbeside the summary.I followed those two rather than adding a helper module, because a shared atomic-write helper would be a change to a layer four call sites already own, and the issue is about this one call site.
Related Issue
Closes #245
What a failed write leaves behind
The destination is untouched. The staging file (
judged.json.<pid>.tmp) remains after a failed write, which is whatrunmark.pyandschedule.pyalready do; nothing globs the run namespace for*.json, so it cannot be mistaken for a result file. The new test asserts the destination and the directory contents, so if that ever changes the test says so.Tests
Measured on this branch's base,
6868817(the currentmain), withpython3 -m unittest discover -s tests -p 'test_*.py'from the repository root:6868817, unmodifiedRan 70 tests—FAILED (errors=4, skipped=6)Ran 73 tests—FAILED (errors=4, skipped=6)The four failing names are identical on both trees, and they are environmental rather than project defects:
RolloutIsolationTests.test_fence_blocks_other_rollouts_but_keeps_own_dirs_and_tmp,test_installed_commands_stay_on_path,test_later_rollout_cannot_see_earlier_installs_or_temp_files,test_retry_starts_from_a_clean_sandboxall fail withFileNotFoundError: [Errno 2] No such file or directory: 'timeout'— this machine is macOS, which has notimeout(1). So the delta is+3 tests, +3 passing, the same 4 names failing.tests/test_judge_write_atomic.pyis the regression test, and it was run against the code as it was before this change:6868817:test_failed_publish_keeps_the_previous_result_fileFAILS — the destination is left holding half a JSON document, which is the reported behaviour, not a missing symbol or a broken fixture. The other two cases pass on both trees.The failing case writes a valid
judged.json, makes the publish stop partway (OSError(28, ...)after partial bytes), and then asserts on the file that survives — it still parses, and still holds the previous row — rather than on whatwrite()returned.Not in this change
harness2/cli/judge.py:152publishesbase_judged.jsonwith the same directwrite_text(), so it has the same weakness. It is a different function and a different file from the one this issue names, so it is reported here rather than changed here — say the word and it is a one-line follow-up.