Skip to content

placement: reject overflowing card reserve and set-aside sums - #359

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
Burntgogi:fix/card-reserve-overflow
Oct 16, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
Burntgogi:fix/card-reserve-overflow

Conversation

@Burntgogi

@Burntgogi Burntgogi commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Fixes #349. Reserve-list and context/scratch additions could overflow before the checked floor; shared-pool accumulation could also panic in debug or wrap in release. These paths could fabricate available space instead of a named refusal.

This PR merged 5e3f139fdb7cfe2c18cd4453f85475a1c9034347 as 3781737c6df9b721045c11a493ca6505cc2f1ec8 during verification. Later branch 62ea287 is a subsequent rebased validation head, not this PR's merged head. Its #339 caller compatibility repair is submitted separately as #372.

Change

  • Check both existing sum owners: Card::reserve_bytes and set_aside_bytes now return Option<u64>; floor_bytes propagates None.
  • Reject invalid set-asides before the expert budget with PlacementError::CardBytesPastU64.
  • Check the complete load floor and shared-pool additions. Skip the irrelevant combined total for separate device memories. Whole-fit no longer converts an unrepresentable need into a fitting u64::MAX sentinel.
  • Migrate the original callers and retain validated plan invariants and safe display of an invalid public whole-need record. The two newly merged serve: connect dense qwen35 to the existing native Qwen seat #339 dense-refusal/test callers are completed by fix(qwen): consume checked Card reserves after merged context policy #372.

No kernel, allocator geometry, numeric band or placement retry policy changes.

Exercised evidence

  • Exact source 62ea287641c702b2ffd2147b79e8f6bf53254b0f: cargo test -p bloomery-placement: 138 passed.
  • cargo test --release -p bloomery-placement card_sums: 3 passed; scoped cargo clippy -p bloomery-placement --all-targets --no-deps -- -D warnings passes.
  • Separate actual release consumer: independent card memories are accepted without an irrelevant cross-card sum; the overflowing shared pool is refused with CardBytesPastU64 naming the offending card.
  • New regressions cover reserve-list overflow, context+reserve, scratch+reserve, context+scratch, dense/KV/past overflow at the exact boundary, free-reading paths, and actual upload additions after a representable set-aside.
  • FAIL-first retained: the pooled regression exits 101 with an overflow panic in debug and a failed named-refusal assertion in release before the fix; both profiles pass afterward. Reproduce with cargo test -p bloomery-placement pooled_card_sums_are_checked_only_for_shared_memory and its --release form.
  • The permanent regression retains the complete two-card construction and checks stage1 in the error. This named card and error category provide the debugging context; the throwaway public consumer is not a second production tool.
  • Post-merge integration 09bd728, including merged main and fix(gates): supply split prefill referee cache origin #370/fix(qwen): consume checked Card reserves after merged context policy #372, passes workspace/all-targets, all-feature GPU-test metadata and 124 host-library tests (3 ignored). These are not CUDA device execution.

Immutable fail-first output, owner/consumer logs, merged-head attribution and post-merge integration log.

NVIDIA device-consumer acceptance remains unrun; an A6000 maintainer run is still needed. Dependency-inclusive strict clippy remains blocked by four existing gguf diagnostics; no lint level was relaxed. No GPU or performance result is claimed for this PR.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement labels Oct 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: The checked card floors still feed an unchecked pool sum.

Must fix

1. Check the pool accumulation

crates/placement/src/placement.rs:3743 Two distinct stage cards covering 0..1 and 1..2 (head on the second), each with usable_bytes = u64::MAX, a 1 << 63 reserve, zero context/scratch/margin, and no free or budget cap, pass the individual floor checks. With layered(2) and NoKv, their combined total exceeds u64.
Debug builds panic here. Release builds wrap; on a unified pool of u64::MAX, pool_need repeats the wrapping sum and misses PoolOver. The new tests use one card and do not catch this remaining overflow path.
Checking this sum in the current overflow fix avoids another correction to the same totals owner.

Replace the accumulation with:

if machine.unified().is_some() {
    pool_cards = pool_cards
        .checked_add(used - card.context_in_free())
        .and_then(|bytes| bytes.checked_add(card.margin_bytes))
        .ok_or_else(|| card.bytes_past_u64())?;
}

Add this two-card case to the regression: require a named refusal on a unified machine and successful planning on a machine with separate card memories.

Non-blocking

⚠ Complete the fix evidence: crates/placement/src/placement.rs:4533. The body lists green runs but no FAIL-first output. It also describes a separate release consumer that the diff does not retain. Include the failing run and retain the reproducer in existing tools, or explain how the fix supplies the required debugging layer.

Checked

Duplicates: 4 new items checked (three functions and the error variant); no duplicate owner. Dryer reported 0 pairs.
Complexity: WholeNeed::fmt 13→17 adds overflow rendering; totals 15→17 and plan_rule 34→35 add error propagation. These changes do not require a split.
Silent failure: 8 handling sites followed. Overflow reaches a named error or explicit “past u64 bytes” text; the two production expect sites follow checked floors.
Tests, static mutation: wrapping the addition at reserve_bytes breaks the new boundary assertions; restoring the sentinel at whole_need breaks the new refusal assertions.
Migrated tests: drop reserve insertion (2 tests), batch scratch (2), set fixed costs to zero (1), or drop the all-expert refusal (1): assertions turn red.
Gates: no existing pin, tolerance or test removed or relaxed.
Escape catalog: C1–C4 do not match. The changed production path is load-time planning.

Notes

Rust tests were assessed statically, not executed. The pool-overflow arithmetic was checked separately.
Dryer skipped gpu-gates; its changed callers were checked by Grep.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/beside.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Filed outside this PR: #363

@Burntgogi

Copy link
Copy Markdown
Contributor Author

Combined verification record: https://github.com/Burntgogi/bloomery/blob/ce8398216da51ae2d1e0b2c42ddb8dfda76c7460/docs/contrib/evidence/native-roadmap-20261015/refresh-20261016/results.json . Placement strict clippy passes with --no-deps; the dependency-inclusive strict attempt remains red on four existing chunks_exact_to_as_chunks warnings in unchanged gguf/quant.rs:1296,1351. No lint level was relaxed. Integrated metadata, public release consumer and complete recipe check pass; the incidental localized FIFO assertion cleanup is separate #367.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review:

Verdict: CLEAN: The incremental change closes the reported pool overflow and adds assertions for both memory configurations.

Non-blocking

⚠ Complete the fix evidence: crates/placement/src/placement.rs:4596. The body still lists green runs without FAIL-first output, and the separate release consumer is not retained. Include the failing regression run and retain the reproducer in existing tools, or explain how the named error and its context provide the debugging layer. This makes recurrence checks repeatable.

Checked

Duplicates: 1 new item checked, the regression test; no duplicate contract found. Dryer reported 0 pairs.
Complexity: crapper flags totals 15→19; this increment adds a unified-pool guard and checked accumulation. WholeNeed::fmt 13→17 and plan_rule 34→35 predate this increment. No complexity finding.
Silent failure: 1 new error-propagation site followed; either checked addition returns CardBytesPastU64. The subtraction is bounded by the context already included in the checked floor.
Tests, static mutation: wrapping the addition at line 3745 defeats the named-error assertion; removing the unified guard makes the separate-memory success assertion fail. Checked the two-card arithmetic independently.
Gates: no existing pin, threshold or test removed or relaxed.
Escape catalog: C1–C4 do not match. The changed path is load-time planning.

Notes

Rust tests were assessed statically, not executed. The body carries no GPU gate evidence.
Dryer skipped gpu-gates; this increment does not change that crate.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/beside.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4
juliankang4 merged commit 3781737 into midagedev:main Oct 16, 2026
6 checks passed
@juliankang4

Copy link
Copy Markdown
Collaborator

@Burntgogi Thanks for the contribution. The review is done, so I'm merging this.

@Burntgogi

Copy link
Copy Markdown
Contributor Author

Post-merge caller cutover: #359 merged its earlier 5e3f139 head before the later compatibility branch update. Together with #339, current main e195c9e actually fails Qwen CLI/shared-server metadata checking with E0308 at qwen3moe_place.rs:660 (u64 versus Option<u64>).

The minimal repair is #372 at 626be5f: preserve bounded typed shortage fields; report overflowing reserves as the named CardBytesPastU64. Actual fail-first diagnostics, passing exact-head production metadata/138 placement tests, and runtime execution of the real private refusal owner are retained. No default value, panic suppression or context-policy change is used.

Final combined integration c5e2e1e, including #370/#372 and final #254 source 7697492, passes formatting, workspace/all-targets, all-feature GPU-test metadata, 124 default host-library tests (3 ignored), both diagnostic self-tests and recipe derivation. NVIDIA native acceptance is not claimed.

Immutable final evidence and distinct merged-versus-validation source heads:
https://github.com/Burntgogi/bloomery/tree/036c69c9052f7a345d0e44ee812738ed42bf54ff/docs/contrib/evidence/native-roadmap-20261015/refresh-20261016

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

Labels

gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

placement: card set-aside sums overflow before the checked floor

2 participants