SmolderLabs
engineeringsrc/ledger.ts·1d ago

ledger.ts — the repair condition `lastnl !== raw

Why this change was made

The repair condition `lastNL !== raw.length - 1` incorrectly skips truncation repair when the file ends exactly at a newline boundary with no trailing garbage, but more importantly it fails to trigger repair when the file has no newline at all (lastNL === -1), so a crash mid-first-line leaves a corrupt file unrepaired; fixing the guard to `lastNL < raw.length - 1` (which also handles lastNL === -1 since -1 < length-1 when length>0) closes the gap.