Skip to content

bcpack: name the reason a BCPack request fails - #1804

Closed
tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-frontier-bcpack-inspect
Closed

tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-frontier-bcpack-inspect

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Refs #1198 (the bcpack failed class). This changes no request outcome and no counter.

What it adds

  • decode_lanes takes an optional LaneReport* (default nullptr). With no report the code path answers as before. With one it records why the decode stopped (the failure kind), the bytes handed to lanes, and the fewest and most symbols any lane had produced.
  • src/startup_stubs/bcpack_inspect.h: inspect_bcpack(input, size, format, output_size) returns a class plus bytes_read, min_symbols_per_lane, max_symbols_per_lane and the requested count. Classes: ok, bad_arguments, unsupported_format, destination_misaligned, header_invalid, fragment_not_home, end_state_invalid, trailing_input, request_shorter_than_stream, request_longer_than_stream, truncated_in_fragment, cycle_limit, control_code_unmapped. Layouts exist for BC1 and BC7 only, the formats decode_bcpack decodes today.
  • tests/bcpack_inspect_check.cpp, registered next to the other BCPack checks, with a --mutate collapse control that reports every failure as one class and must fail.

Why
Today a BCPack failure is one false. A request for fewer blocks than the stream holds, a request for more, and a cut stream all end in the same no-progress line of decode_lanes, so a count or a log cannot tell them apart. The lane state can. On the synthetic 64-block BC1 stream: asking for 16 blocks leaves every lane at 16 symbols with 196 of 515 bytes read; asking for 65 or 1000 ends with every lane at 64 symbols and all 515 bytes read; cutting the input at 300 bytes stops lanes at 31 or 32 symbols mid-fragment.

What it does not do

  • No change to decode_bcpack, execute_request or xcrdapi.cpp; it is not called from the request path yet. It is meant to be called on the failure path once the request code settles.
  • It does not decode a request for the first part of a longer stream, and it does not say what a title expects for such a request.
  • A stream cut exactly at a fragment boundary in every lane reads as request_longer_than_stream: that is a shorter stream.
  • control_code_unmapped is the one class without a stream case. No synthetic stream in the repository reaches it, and about 3 million random one-to-three byte changes of the two BC7 streams did not find one. header_invalid cannot come from the BC1 or BC7 layouts (their alphabets are at least 3 bits wide), so it is checked through decode_lanes with a 2-bit alphabet.

Streams used
The synthetic streams already in the repository: tools/_bcpack_rans/vectors/synthetic_11.json (64 BC1 blocks), tests/bcpack_mode6_vector.py (one BC7 mode 6 block) and tests/bc7_mode6_multiblock_check.py (two blocks). Each case changes only the destination size, the input length or one input byte. Every case also checks that inspect_bcpack says ok exactly when decode_bcpack returns true.

Overlap
git merge-tree of this branch against origin/main (330df7f) reports no conflict. Against #1390, #1429 and #1616 the conflicts are the same ones each of those has with origin/main alone (tests/startup_stub_consumer.cpp, xcrdapi.cpp, CMakeLists.txt and docs/experiments.md), none in a file this branch touches differently. No conflict with #1787, #1788 or #1789. The merge of this branch with #1390's decoder compiles and the new check passes on it. The decoder edit is confined to decode_lanes plus the report types placed just before it.

Commands run locally on Linux (g++ 14.2, with a local one-function <intrin.h> shim for _BitScanReverse, kept outside the repository; the decoder header includes <intrin.h> as it does on main)

  • g++ -std=c++17 -O2 -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=undefined -I <shim> -I src tests/bcpack_inspect_check.cpp: 160 cases, 0 failed, no warnings.
  • Same binary with --mutate collapse: 30 failed, exit 1.
  • Five local mutations, each reverted: swapping request_longer/truncated (12 cases fail), reporting request_shorter only when input is left (2 fail), reporting trailing input as an end-state error (2 fail), adding one to bytes_read (25 fail), checking destination alignment with a smaller modulus (survived at first; two cases added, then 2 fail).
  • python3 -B tests/docs_links_check.py and python3 -B tests/bidi_controls_check.py: pass. git diff --check origin/main...HEAD: clean.
  • Not run: a Windows build (the CMakeLists.txt registration is inside the existing INTAKE_PYTHON block next to the other BCPack checks).

AI-assisted; commands listed were executed locally.

decode_lanes can fill an optional LaneReport saying why it stopped and how far the lanes got; without
one it behaves as before. bcpack_inspect.h turns that into a class for a request (destination size
not a whole number of blocks, request shorter or longer than the stream, a cut stream, trailing input,
and so on) with the bytes read and the symbols per lane. decode_bcpack and the request path are
unchanged. The check runs the repository's synthetic BC1 and BC7 streams; its collapse control
reports every failure as one class and must fail.
@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant