fix(nwsync): declare Frame_Content_Size, and verify what is published (#86, #85)

These two land together on purpose. Fixing the encoder alone changes nothing
for the blobs already in the zone, because emit skips whatever is already
present.

#86 — klauspost/compress omits the zstd Frame_Content_Size field for inputs
under 256 bytes, which the format permits. Reference libzstd never does, so the
NWN client — which sizes its output buffer from ZSTD_getFrameContentSize and has
therefore never met a frame without one — rejected roughly 6% of our blobs
outright. Any single one stops a sync dead, so no client could complete a sync
of the live manifest.

No encoder option changes this, so emit re-headers the affected frames into the
shape libzstd itself emits: Single_Segment_flag set, Window_Descriptor dropped,
and the freed byte spent on a one-byte Frame_Content_Size. Same length in, same
length out. Verified against the zstd CLI end to end: a real emitted 230-byte
blob now reports its decompressed size where it previously reported none.
emitter_version goes to 2, so assemble refuses to merge an index written by the
encoder that omitted the field.

#85 — a published blob was verified by exactly one thing, a player's client, at
download time. `nwsync verify <manifest-sha1>` now reads a manifest and its
blobs back through the public pull zone with no credential, decompresses and
hashes every one, and reports missing / malformed framing / size mismatch / hash
mismatch per blob. `--sample N` makes a routine check cheap against a manifest
that is ~69,000 blobs and 15 GB. `emit --verify` applies the same check where
emit would otherwise trust presence, and replaces a stored blob that is not what
its name claims — which is what makes the #86 blobs repairable.

Both new checks assert the frame property, not just a round trip. Round-tripping
cannot see this class of fault: both the zstd CLI and Go's decoder stream such a
frame happily, being more capable decoders than the client's, which is how the
defect reached production and survived an audit.

Refs #54, #55, #59, #75, sow-platform#79.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-01 00:20:15 +02:00
co-authored by Claude Opus 5
parent 682f920114
commit 56d4054118
11 changed files with 752 additions and 19 deletions
+28
View File
@@ -501,3 +501,31 @@ func TestRunUsageErrors(t *testing.T) {
}
}
}
// TestEveryBlobDeclaresItsFrameContentSize guards the fault that stopped every
// client sync (#86): klauspost/compress omits Frame_Content_Size for inputs
// under 256 bytes, and the game client cannot decode a frame without it. This
// asserts a frame property, not a round trip — the zstd CLI and Go's decoder
// both stream such a frame happily, so round-tripping cannot see the defect.
func TestEveryBlobDeclaresItsFrameContentSize(t *testing.T) {
// 230 and 175 are real sizes from the manifest that failed to sync; 255/256
// straddle the encoder's threshold.
for _, size := range []int{1, 32, 175, 230, 255, 256, 257, 1024, 5000} {
payload := make([]byte, size)
for i := range payload {
payload[i] = byte('a' + i%26)
}
blob := compressBlob(payload)
if !frameDeclaresContentSize(blob[blobHeaderBytes:]) {
t.Errorf("blob of %d bytes declares no frame content size (descriptor %#x)",
size, blob[blobHeaderBytes+4])
}
got, err := decompressBlob(blob)
if err != nil {
t.Fatalf("decompress %d-byte blob: %v", size, err)
}
if !bytes.Equal(got, payload) {
t.Errorf("%d-byte blob did not round trip", size)
}
}
}