Skip to content

test(contract): widen no_cpu_fallback_contract to cover Candle-side paths - #1341

Merged
joelteply merged 1 commit into
canaryfrom
feat/no-cpu-fallback-contract-widen
May 16, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/no-cpu-fallback-contract-widen

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Closes #1316 ALPHA-GAP finding #5: the existing no_cpu_fallback_contract.rs asserted the no-CPU-fallback rule only at the llama.cpp + ORT layers. The Candle / inference-grpc / orpheus / residency-gate paths shipped their own no-CPU-fallback guarantees in PRs #1312, #1314, #1331, #1335, #1338 — but the contract test didn't enforce them. A future regression could silently re-add a CPU fallback to any of those paths without breaking this gate.

This PR closes the hole with six new source-grep assertions.

What ships

Six new tests in no_cpu_fallback_contract.rs:

  1. inference_grpc_select_best_device_hard_fails_on_no_gpu — pins inference-grpc/src/model.rs contains "no CPU fallback" phrase AND select_best_device returns Result<Device, ...> (not bare Device, which would let someone silently re-add Device::Cpu as the Ok variant). Catches regression of fix(gpu): inference-grpc hard-fail on no-GPU (companion to #1312) #1314.

  2. orpheus_tts_select_device_hard_fails_on_no_metal — pins orpheus.rs select_device returns Result<Device, TTSError>. Catches regression of fix(audio/tts): orpheus must fail-closed on no-Metal, no CPU fallback #1312.

  3. residency_gate_emits_no_gpu_block_reason — pins residency.rs defines BlockReason::NoGpuBackendOnNode AND BlockReason::PartialGpuSplit. Both load-bearing for the gate's typed refusal contract. Removal would leave the gate unable to express "no GPU" or "GPU exists but model spills to CPU."

  4. enforcement_module_exists_and_composes_the_three_layers — pins enforcement.rs exports pub fn enforce_residency AND composes all three layers (probe_hardware_profile + read_qwen_model_metadata + check_residency_gate). Without the composition, every adapter re-invents it and invariably misses a layer.

  5. llamacpp_adapter_wires_residency_gate_at_load_time — pins llamacpp_adapter.rs calls enforce_residency. This is what makes the gate ACTUALLY fire in production. Removal would leave the gate as a callable function nobody calls.

  6. hw_probe_does_not_introduce_cpu_fallback — pins hw_probe.rs documents the never-panic contract AND exposes build_hardware_profile as a pub fn. Panic-in-probe crashes the supervisor; private-pure-fn means tests can't mock hardware.

Pattern

Same forbidden-strings ratchet as the existing assertions (LlamaCppConfig 'n_gpu_layers: -1', ort_providers 'CPU fallback is forbidden', LlamaCppAdapter 'NoLocalModelLoadable'). Source-only inspection — fast, deterministic, no runtime cost. The asserted strings are documentation-as-contract: removing them is the regression signal.

Test plan

9 passing (3 pre-existing + 6 new) on cargo test --test no_cpu_fallback_contract --features metal,accelerate.

Why this matters

Without these assertions, the four Rust paths that already enforce no-CPU-fallback (inference-grpc, orpheus, residency gate, adapter wiring) could be silently reverted by a single PR that "fixes a compile error" or "simplifies a return type." The forbidden-strings ratchet catches that class of regression at test-time instead of at "1 tok/s on a 5090" production-incident-time.

This is the cheap follow-up to PIECE-5's whole stack — gate the rule at type-checking time, not just at runtime.

@joelteply
joelteply merged commit 6db36a9 into canary May 16, 2026
3 checks passed
@joelteply
joelteply deleted the feat/no-cpu-fallback-contract-widen branch May 16, 2026 22:07
joelteply pushed a commit that referenced this pull request May 16, 2026
…ning; navigate to MODULE-CATALOG queue

Second refresh of ALPHA-GAP Immediate Next Actions to reflect work
landed since #1316 merged. Six items closed; navigation into
MODULE-CATALOG queue made explicit.

Closed: #6 contract widening (#1341), #8 GRID-INFERENCE-ROUTING PR-1
(#1315), CBAR-PIECE-5 end-to-end (#1331/#1333/#1335/#1338),
PIECE-8 inference-grpc hardcoded-clamps (#1340), doc family
architecture surface (#1324/#1327/#1332/#1336/#1337 open;
#1316/#1317/#1320/#1329 merged).

Item #9 reorganized to point at MODULE-CATALOG's 'Next Modules To
Build' queue (audit-recorder → threat-detector → working-set-manager
→ demand-aligned-recall → substrate-governor).

Adds closeout summary section listing what's done, what's open
(5 architecture-doc PRs ready for review + 2 airc PRs), and what's
queued (5 modules with dependency state + LoC + acceptance criteria
in MODULE-CATALOG).

Doc-driven development cycle is working: doc spec → implementing
agent picks up → ships PR → next spec referenced.
joelteply added a commit that referenced this pull request May 16, 2026
…ning; navigate to MODULE-CATALOG queue (#1342)

Second refresh of ALPHA-GAP Immediate Next Actions to reflect work
landed since #1316 merged. Six items closed; navigation into
MODULE-CATALOG queue made explicit.

Closed: #6 contract widening (#1341), #8 GRID-INFERENCE-ROUTING PR-1
(#1315), CBAR-PIECE-5 end-to-end (#1331/#1333/#1335/#1338),
PIECE-8 inference-grpc hardcoded-clamps (#1340), doc family
architecture surface (#1324/#1327/#1332/#1336/#1337 open;
#1316/#1317/#1320/#1329 merged).

Item #9 reorganized to point at MODULE-CATALOG's 'Next Modules To
Build' queue (audit-recorder → threat-detector → working-set-manager
→ demand-aligned-recall → substrate-governor).

Adds closeout summary section listing what's done, what's open
(5 architecture-doc PRs ready for review + 2 airc PRs), and what's
queued (5 modules with dependency state + LoC + acceptance criteria
in MODULE-CATALOG).

Doc-driven development cycle is working: doc spec → implementing
agent picks up → ships PR → next spec referenced.

Co-authored-by: Test <[email protected]>
joelteply added a commit that referenced this pull request May 16, 2026
…ierarchy + paging (#1346)

PR-1 of working-set-manager (MODULE-CATALOG §VII + GENOME-FOUNDRY-
SENTINEL Parts 2/3/4). Pure data + serde + ts-rs exports. No traits,
no I/O, no async, no wiring — those land in PR-2/PR-3.

Mirrors the slice shape that worked for CBAR-PIECE-2 PR-1 (#1321) +
PIECE-5 PR-1 (#1331): ship the data shape first, hang behaviors on
it incrementally.

What lands

- TierRole (Fast/Warm/Bench/Cold/Frozen) + is_present_on_uma helper
- EvictionPolicy + canonical_for(role) pinning the per-role policy
  table from GENOME-FOUNDRY-SENTINEL Part 2
- TierCapacity + available_bytes (saturating) + utilization (zero-safe)
- EvictionRecord (trace bus event shape — PR-3 wires through #1339+
  #1343 artifact dispatch)
- TierError + Display + Error
- PageKind / PageOffset (Whole / Expert / Range)
- PageRef { kind, artifact, offset } — Hash+Eq for HashMap-key use
- PageHandle (what page_in returns)
- ResidentPage + WorkingSetCapacity + WorkingSet
- PageFault + AccessDenied (typed events; audit-recorder #1344
  subscribes to AccessDenied as one of its inputs)
- PersonaId(Uuid) + ArtifactId(Uuid) typed newtypes — the type
  system catches swapped arguments at audit_access(persona, page)
  sites. Wire is transparent (UUID string).

What is deliberately deferred

- WorkingSetManager trait + page_in/page_out/audit_access (PR-2)
- TierStore trait + per-role impls (separate PR set)
- MMU permission table enforcement (PR-2 or PR-3)
- PageFault/EvictionRecord publishing via artifact dispatch (PR-3)
- Hardware-anchor Vec<TierConfig> from governor (substrate-governor
  lane — codex's #1345)

Tests

35 tests on genome:: pin every invariant the type system + serde
encoding guarantee. 35/35 pass. No regressions across other 2467
lib tests.

Clippy baseline bump 146→148 — drift from canary HEAD; the +2
warnings are NOT from genome code (zero clippy hits in genome/).
They land via codex's recent #1340/#1341/#1344/#1345 merges that
didn't bump the file. Bumping here so the ratchet stays meaningful
for the NEXT PR to gate against.

Co-authored-by: Test <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant