Observe target and pending bytes
The old checkpoint was valid. Opening its filename for writing made it empty before the first new byte arrived. In this local Python example, stopping after a 13-byte prefix left an incomplete target. Writing that same prefix to a separate file kept the old target readable.[5][6]
We compared two policies using invented records: an old step-7 record with sum 28 and a new step-8 record with sum 36. Each serialized envelope was 184 bytes and included a body digest. Overwrite opened the target in binary write mode. Stage + replace wrote a pending file in the same directory, closed it, then called os.replace. Each case began with its own copy of the old record.[5][6]
Keep each stop boundary and revision
Four boundaries were declared before the run: after opening, after the first 13 bytes, after the complete payload, and normal completion. The first three raise an authored exception. The file handle closes during exception cleanup before we read either path. These are deliberate sequential stops, not process kills, power failures or overlapping readers.[5][6]
After opening and after the prefix, the overwritten target contained zero and 13 bytes respectively; both failed the selected record validator. The staged policy still exposed the complete old target. Its pending file contained zero or 13 bytes, and those incomplete bytes remain in the saved result rather than being treated as a completed update.[6][5]
After the full write, the policies expose different revisions. Direct overwrite already contains the complete new record. Staging still exposes old and holds new in the pending file because replacement has not occurred. Old is valid but not current. A validator that checks only readability or a digest cannot decide which revision was intended to be published.[6][5]
On normal completion, both targets contain the new record. The staged policy has no pending file after replacement. This positive control matters: the demonstration does not say that every overwrite is incomplete, or that preserving an old record completes the new update. The full output retains all eight target and pending-file outcomes.[6][5]
- Valid is not necessarily current: Before replacement, the staged target remains the old valid record even when the new pending file is complete.
All eight authored local cases; observations occur after writer-handle cleanup. Old and new complete envelopes each contain 184 bytes.
| Policy | Observed boundary | Target bytes | Target revision | Validation | Pending bytes |
|---|---|---|---|---|---|
| Overwrite | After open, before data | 0 | incomplete | invalid | absent |
| Overwrite | After 13-byte prefix | 13 | incomplete | invalid | absent |
| Overwrite | After full write, before completion | 184 | new | valid | absent |
| Overwrite | Normal completion | 184 | new | valid | absent |
| Stage + replace | After open, before data | 184 | old | valid | 0 |
| Stage + replace | After 13-byte prefix | 184 | old | valid | 13 |
| Stage + replace | After full write, before replacement | 184 | old | valid | 184 |
| Stage + replace | Normal completion | 184 | new | valid | absent |
- The pending file belongs only to the staged policy. Absent is different from an empty file.
- The three stop boundaries are authored exceptions; normal completion has no injected stop. No percentages or failure-rate estimates are derived.
Use the documented file semantics
The documented Python semantics explain the boundary. Binary write mode truncates an existing file. os.replace changes the destination name to the source and documents atomic replacement on successful POSIX rename; different filesystems can cause failure. We place both names in one directory. That API statement is background for the example, not a measurement of concurrent-reader behavior.[1][2][3]
The one CPython 3.9.6 run on Darwin passed eight expected-byte case checks and eight separate selected validator controls. Controls include complete records, the empty and partial records, a changed body with a stale digest, a boolean step, an unknown field and non-object JSON. The digest is bookkeeping under this teaching contract, not authenticity or proof that a real training checkpoint contains every required state variable.[5][6]
- Visibility is not durability: This sequential readback does not test power-loss persistence, concurrent readers or a production checkpoint service.
Keep visibility separate from durability
File visibility and durability remain separate. This program makes no explicit fsync call, kills no process and reboots no machine. Reads may come from the operating system cache. We did not test persistence after power loss, remote filesystems, multiple-file transactions or concurrent writers. These eight designed cases do not estimate a recovery rate or establish a production storage guarantee.[4][5]
For a checkpoint benchmark, state which revision should be visible, where interruption is injected, when the reader runs and what qualifies the recovered bytes. Retain incomplete and old-but-valid records as distinct outcomes. The MIT download includes exact source, fixture, protocol, every byte snapshot and the saved result; no model, GPU, timing or economic result is claimed.[5][7]
- Report target revision, byte validity and persistence evidence separately when evaluating checkpoint recovery.
Sources
- Python os.replace docs.python.org
- Python open docs.python.org
- Python tempfile.TemporaryDirectory docs.python.org
- Python os.fsync docs.python.org
- MIT runnable proof and full saved output data.nodus-compute.ai
- Full saved result JSON data.nodus-compute.ai
- Source and saved-result provenance data.nodus-compute.ai
- Vector figure data.nodus-compute.ai
