fix(bgcode): DEFLATE is zlib-wrapped, not raw — real-file confirmed (#188) - #236
Merged
Merged
Conversation
…rmed (#188) Phase-1 assumed raw DEFLATE ('deflate-raw'). Validating the decoder against a real Prusa XL ColorMix .bgcode (21 MB, 856 blocks) showed its DEFLATE metadata blocks (Slicer/Print) decode ONLY as zlib-wrapped — raw fails ("invalid stored block lengths"). It went unnoticed because GCode blocks use heatshrink, not DEFLATE, so the DEFLATE path was never exercised until real metadata. Switch the decoder + the test assembler to DecompressionStream('deflate') (zlib), and add a flavor-lock test asserting a raw-DEFLATE block is rejected (E_BGCODE_INFLATE) so the flavor can't silently regress. Real-file validation (local): all 856 CRC32 verified; 848 heatshrink-12 + MeatPack-comments GCode blocks → 51.4 MB of valid Prusa G-code (1,892,006 G1 moves, comments + ;WIPE_START preserved, MeatPack no-spaces mode exercised) in ~3 s — so the phase-2/3 decoders are correct on real data. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sobechestnut-dev
enabled auto-merge (squash)
July 27, 2026 21:17
This was referenced Jul 28, 2026
Merged
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.
The first fruit of validating the decoder against a real Prusa XL ColorMix
.bgcode(thanks for the file!). Part of #188 phase 4.The bug the real file caught
Phase 1 assumed raw DEFLATE (
'deflate-raw'). Prusa actually uses zlib-wrapped DEFLATE — the real file's Slicer/Print metadata blocks decode only with the zlib header (zlib.decompress(data)); raw fails withinvalid stored block lengths. It was invisible until now because GCode blocks use heatshrink, not DEFLATE — so the DEFLATE path was never exercised on real data until a real file's metadata.Fix:
DecompressionStream('deflate')(+ the test assembler), and a flavor-lock test asserting a raw-DEFLATE block is now rejected, so this can't silently regress.Real-file validation (local, conclusive)
Decoding the 21 MB / 856-block file end-to-end:
G1moves, comments +;WIPE_STARTpreserved, and the file uses MeatPack no-spaces mode (G1X177.233Y194.747E.02659) — so the phase-2 no-spaces handling and the phase-3 heatshrink are correct on real data.So the phase-2/3 codec ports are validated against real Prusa output; this PR fixes the one thing that was wrong (the DEFLATE flavor).
Verification
typeCheck✓,lint✓ (0 errors), CI-liketest:packages✓ (31 bgcode tests),pack:check✓ (no snapshot change).🤖 Generated with Claude Code