upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/bcpack.cpp
diff options
context:
space:
mode:
authorkawaii-shakal <deusex1998@gmail.com>2026-11-25 14:20:30 +0500
committerkawaii-shakal <deusex1998@gmail.com>2026-11-25 14:20:30 +0500
commit7b251064ade817ade05a1bfe40d160558ac62604 (patch)
treed284eed752168f80d851747cff2a2c0f74d9e860 /runtime/src/bcpack.cpp
parent626d1281af490b0a888443d6b0b7cb5433b94abe (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/bcpack.cpp')
-rw-r--r--runtime/src/bcpack.cpp12
1 files changed, 9 insertions, 3 deletions
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,
263// earlier uses of the slot. 263// earlier uses of the slot.
264struct Coverage { 264struct Coverage {
265 array<bool, 256> missing_ep{}, missing_ix{}; 265 array<bool, 256> missing_ep{}, missing_ix{};
266 size_t lost{}, inconsistent{}, limit{}; 266 size_t lost{}, inconsistent{}, limit{}, lost_limit{};
267 bool lost_endpoints{}, lost_indices{}; 267 bool lost_endpoints{}, lost_indices{};
268 void note_missing(const BptcState &block) { 268 void note_missing(const BptcState &block) {
269 const bool ep = block.ep_root >= 0 && missing_ep[block.ep_root]; 269 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,
382 } else if (i >= 256) 382 } else if (i >= 256)
383 coverage.note_missing(next); 383 coverage.note_missing(next);
384 if (!valid) return false; 384 if (!valid) return false;
385 if (coverage.lost > coverage.limit) { 385 if (coverage.lost > coverage.lost_limit) {
386 reason = coverage.lost_endpoints && coverage.lost_indices ? "missing-endpoint-and-index" : 386 reason = coverage.lost_endpoints && coverage.lost_indices ? "missing-endpoint-and-index" :
387 coverage.lost_endpoints ? "missing-endpoint" : "missing-index"; 387 coverage.lost_endpoints ? "missing-endpoint" : "missing-index";
388 return false; 388 return false;
@@ -394,7 +394,8 @@ bool rebuild_bptc(unsigned codec, size_t i, size_t blocks, const Symbols &a,
394 394
395Quality decode(unsigned codec, std::span<const uint8_t> source, 395Quality decode(unsigned codec, std::span<const uint8_t> source,
396 std::span<uint8_t> output, bool allow_fitted, 396 std::span<uint8_t> output, bool allow_fitted,
397 const Calibration *history, const char** failure, bool fast_entropy) { 397 const Calibration *history, const char** failure, bool fast_entropy, size_t lost_divisor,
398 Report *report) {
398 const char* reason = "bcpack-stream"; 399 const char* reason = "bcpack-stream";
399 if (failure) *failure = reason; 400 if (failure) *failure = reason;
400 Quality quality = Quality::confirmed; 401 Quality quality = Quality::confirmed;
@@ -410,12 +411,17 @@ Quality decode(unsigned codec, std::span<const uint8_t> source,
410 coverage.limit = allow_fitted && history 411 coverage.limit = allow_fitted && history
411 ? max<size_t>(2, output.size() / block_size / 1024) 412 ? max<size_t>(2, output.size() / block_size / 1024)
412 : 0; 413 : 0;
414 coverage.lost_limit = allow_fitted && history
415 ? max<size_t>(2, output.size() / block_size / max<size_t>(1, lost_divisor))
416 : 0;
417 if (report) *report = {output.size() / block_size, 0};
413 const bool valid = visit_blocks(codec, source, output.size(), [&](size_t i, const Symbols &first, const Symbols &tuple) { 418 const bool valid = visit_blocks(codec, source, output.size(), [&](size_t i, const Symbols &first, const Symbols &tuple) {
414 auto *dst = output.data() + i * block_size; 419 auto *dst = output.data() + i * block_size;
415 if (codec >= 6) 420 if (codec >= 6)
416 return rebuild_bptc(codec, i, output.size() / block_size, first, tuple, bptc, dst, history, allow_fitted, quality, coverage, reason); 421 return rebuild_bptc(codec, i, output.size() / block_size, first, tuple, bptc, dst, history, allow_fitted, quality, coverage, reason);
417 return rebuild_classic(codec, i, first, tuple, classic, dst, allow_fitted, quality); 422 return rebuild_classic(codec, i, first, tuple, classic, dst, allow_fitted, quality);
418 }, fast_entropy); 423 }, fast_entropy);
424 if (report) report->lost = coverage.lost;
419 if (valid && (!coverage.inconsistent || quality == Quality::fitted)) return quality; 425 if (valid && (!coverage.inconsistent || quality == Quality::fitted)) return quality;
420 if (failure) *failure = coverage.inconsistent && valid ? "anchor-or-pbit" : reason; 426 if (failure) *failure = coverage.inconsistent && valid ? "anchor-or-pbit" : reason;
421 return Quality::failed; 427 return Quality::failed;