From 7b251064ade817ade05a1bfe40d160558ac62604 Mon Sep 17 00:00:00 2001 From: kawaii-shakal Date: Wed, 25 Nov 2026 14:20:30 +0500 Subject: dstorage: rebuild a BC6H/BC7 request with a few lost blocks instead of failing it (BCPACK-LOST-BLOCK-LIMIT) A fitted BPTC request whose predictor chains reach a history entry the local profile does not know was refused once more than max(2, blocks/1024) blocks were affected, leaving the whole destination untouched. On the 1.0.2.1 package two BC7 requests fail this way at every boot, with one unknown endpoint entry each (5 of 1,536 and 15 of 768 blocks). bcpack::decode gets a separate limit for these lost blocks (lost_divisor, 1024 by default, as before) and an optional Report with the block and lost counts. DirectStorage passes 32 (LEONIDA_DSTORAGE_LOST_DIVISOR) and logs each approximated request. Inconsistent blocks keep the 1-in-1,024 limit; strict mode refuses any lost block. Co-Authored-By: Claude Opus 5.5 --- runtime/src/bcpack.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'runtime/src/bcpack.cpp') diff --git a/runtime/src/bcpack.cpp b/runtime/src/bcpack.cpp index bb4646787..8a6049d73 100644 --- a/runtime/src/bcpack.cpp +++ b/runtime/src/bcpack.cpp @@ -263,7 +263,7 @@ bool bc7(const Symbols &a, const Symbols &b, const BptcState &ep, // earlier uses of the slot. struct Coverage { array missing_ep{}, missing_ix{}; - size_t lost{}, inconsistent{}, limit{}; + size_t lost{}, inconsistent{}, limit{}, lost_limit{}; bool lost_endpoints{}, lost_indices{}; void note_missing(const BptcState &block) { const bool ep = block.ep_root >= 0 && missing_ep[block.ep_root]; @@ -382,7 +382,7 @@ bool rebuild_bptc(unsigned codec, size_t i, size_t blocks, const Symbols &a, } else if (i >= 256) coverage.note_missing(next); if (!valid) return false; - if (coverage.lost > coverage.limit) { + if (coverage.lost > coverage.lost_limit) { reason = coverage.lost_endpoints && coverage.lost_indices ? "missing-endpoint-and-index" : coverage.lost_endpoints ? "missing-endpoint" : "missing-index"; return false; @@ -394,7 +394,8 @@ bool rebuild_bptc(unsigned codec, size_t i, size_t blocks, const Symbols &a, Quality decode(unsigned codec, std::span source, std::span output, bool allow_fitted, - const Calibration *history, const char** failure, bool fast_entropy) { + const Calibration *history, const char** failure, bool fast_entropy, size_t lost_divisor, + Report *report) { const char* reason = "bcpack-stream"; if (failure) *failure = reason; Quality quality = Quality::confirmed; @@ -410,12 +411,17 @@ Quality decode(unsigned codec, std::span source, coverage.limit = allow_fitted && history ? max(2, output.size() / block_size / 1024) : 0; + coverage.lost_limit = allow_fitted && history + ? max(2, output.size() / block_size / max(1, lost_divisor)) + : 0; + if (report) *report = {output.size() / block_size, 0}; const bool valid = visit_blocks(codec, source, output.size(), [&](size_t i, const Symbols &first, const Symbols &tuple) { auto *dst = output.data() + i * block_size; if (codec >= 6) return rebuild_bptc(codec, i, output.size() / block_size, first, tuple, bptc, dst, history, allow_fitted, quality, coverage, reason); return rebuild_classic(codec, i, first, tuple, classic, dst, allow_fitted, quality); }, fast_entropy); + if (report) report->lost = coverage.lost; if (valid && (!coverage.inconsistent || quality == Quality::fitted)) return quality; if (failure) *failure = coverage.inconsistent && valid ? "anchor-or-pbit" : reason; return Quality::failed; -- cgit v1.2.3