Resume only a matching plan
Bind completed endpoint records to the exact plan bytes before resuming work.
A checkpoint belongs to one plan
Skipping work because an endpoint ID appears in a previous file is unsafe if that ID now refers to a different address or port. Bind the checkpoint to a digest of the complete plan. This lesson uses SHA-256 over the original file bytes, including the header and line endings.
A byte digest is deliberately strict: reordering an otherwise equivalent plan changes it. That avoids ambiguous assumptions about which definition produced the saved state. It is an integrity binding, not a signature or proof that the author is trustworthy. An attacker who can replace both files can calculate a new digest.
Validate before resuming
A checkpoint can contain only known, unique endpoint IDs with final recorded states open or refused. Timeout and error remain retryable evidence and are not accepted as completed work here. Reject malformed or stale checkpoint records before replacing resume.tsv; a partial resume plan could otherwise skip required endpoints.
The reference selects sha256sum in the browser and shasum -a 256 on macOS, reading bytes from standard input so filenames do not affect parsing. This is a small portability adapter around one operation. The resumed plan retains original ordering and excludes only validated completed IDs. No VM memory or running process is persisted: checkpoints are ordinary files whose meaning the tool can inspect and validate.
if command -v sha256sum >/dev/null 2>&1;then sha256sum < plan.tsv;else shasum -a 256 < plan.tsv;fi
Put it into practice.
plan.tsv has unique validated endpoint<TAB>address<TAB>port rows. checkpoint.tsv first line must be plan_sha256<TAB>the lowercase SHA-256 of the exact plan.tsv bytes; later rows are endpoint<TAB>state, where state is open/refused. Reject wrong digest/first-line shape, unknown IDs, duplicate IDs, invalid states or wrong field count with exit 2 and “Invalid checkpoint”, preserving old resume.tsv. Otherwise replace resume.tsv with the plan header and only endpoints absent from the checkpoint, retaining plan order. Use sha256sum or macOS shasum -a 256; do not hash a reconstructed table.
See an explained solution
if command -v sha256sum >/dev/null 2>&1;then digest=$(sha256sum < plan.tsv);else digest=$(shasum -a 256 < plan.tsv);fi
digest=${digest%% *}
work=$(mktemp -d .resume.XXXXXX) || exit 2
trap 'rm -rf "$work"' EXIT
if ! awk -F '\t' -v digest="$digest" '
FILENAME==ARGV[1]{if(FNR>1){order[++n]=$1;row[$1]=$0}next}
FNR==1 {header_seen=1;if(NF!=2 || $1!="plan_sha256" || $2!=digest)bad=1;next}
{
if(NF!=2 || !($1 in row) || $1 in done || ($2!="open" && $2!="refused")){bad=1;next}
done[$1]=1
}
END{
if(bad || !header_seen)exit 2
print "endpoint\taddress\tport"
for(i=1;i<=n;i++)if(!(order[i] in done))print row[order[i]]
}' plan.tsv checkpoint.tsv > "$work/resume";then printf 'Invalid checkpoint\n' >&2;exit 2;fi
mv "$work/resume" resume.tsv
The digest prevents a checkpoint from silently applying to changed plan bytes. Row validation and staging ensure that only known completed endpoints are skipped, while stale or malformed state cannot replace a previous usable resume plan.