From 0bc2833aa06c1ce71199bdee7e04347eac704d1f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 16 May 2026 04:21:47 +0000 Subject: [PATCH] =?UTF-8?q?fix(sprint-12/wave-F):=20codex=20P2=20=E2=80=94?= =?UTF-8?q?=20AttentionMaskBackend=20impl=20for=20AttentionMaskSoA=20+=20c?= =?UTF-8?q?anonical=20MailboxId=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex P2 review on PR #388 flagged that `AttentionMaskActor` is public but `AttentionMaskSoA` (the only production backend in the crate) doesn't implement `AttentionMaskBackend`. Downstream consumers can't add the impl themselves because they own neither the trait nor the SoA (Rust orphan rules), so `AttentionMaskActor::new(AttentionMaskSoA::new(...))` would force them to wrap in a local newtype. Fix #1 — production-backend impl in attention_mask_actor.rs Added `impl AttentionMaskBackend for crate::attention_mask::AttentionMaskSoA` with the four trait methods delegating to the existing inherent methods on AttentionMaskSoA. Now downstream consumers can wire the two directly: `AttentionMaskActor::new(AttentionMaskSoA::new(4))` works out of the box. Fix #2 — collapses CSI-10 from the W-Meta-Opus honest review The W-F2 worker had defined a local `pub type MailboxId = u32` in attention_mask.rs (Opus CSI-10 entry: "W-F2 used local MailboxId shadow alias"). Switched to `pub use lance_graph_contract::collapse_gate::MailboxId;` — same underlying u32 so all method signatures stay compatible, but now both attention_mask.rs and attention_mask_actor.rs reference the SAME canonical type and the trait impl in fix #1 can be added without type-mismatch concerns. Test status: 14/14 attention_mask + attention_mask_actor tests pass. Clean compile (modulo 2 pre-existing unused_mut warnings unrelated to this change). Branch rebased on main (post PR #385 merge) to pick up the ndarray hpc-extras feature flag that W-C1 added; this resolves the blake3 unresolved-crate compile failure that hit cognitive-shader-driver prior to rebase. https://claude.ai/code/session_01UwJuKqP828qyX1VkLgGJFS --- .../src/attention_mask.rs | 11 +++++------ .../src/attention_mask_actor.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/cognitive-shader-driver/src/attention_mask.rs b/crates/cognitive-shader-driver/src/attention_mask.rs index 58f4c6d4..03373875 100644 --- a/crates/cognitive-shader-driver/src/attention_mask.rs +++ b/crates/cognitive-shader-driver/src/attention_mask.rs @@ -8,13 +8,12 @@ //! `AttentionMaskSoA` is `!Send` by design (non-atomic interior mutation). //! Callers that need cross-thread access must wrap in `tokio::sync::Mutex`. //! -//! # Registration -//! This file is intentionally NOT registered in `lib.rs`. The main thread -//! adds `pub mod attention_mask;` after the sprint-12 fleet completes. +//! # MailboxId +//! Imports the canonical `MailboxId` alias from +//! `lance_graph_contract::collapse_gate` (also re-exported here for ergonomic +//! `use cognitive_shader_driver::attention_mask::MailboxId` access). -/// Re-export the canonical `MailboxId` alias so this module compiles -/// standalone without an explicit `--extern` flag. -pub type MailboxId = u32; +pub use lance_graph_contract::collapse_gate::MailboxId; // ── SoA row ────────────────────────────────────────────────────────────────── diff --git a/crates/cognitive-shader-driver/src/attention_mask_actor.rs b/crates/cognitive-shader-driver/src/attention_mask_actor.rs index 14a540ff..8e2a7a8e 100644 --- a/crates/cognitive-shader-driver/src/attention_mask_actor.rs +++ b/crates/cognitive-shader-driver/src/attention_mask_actor.rs @@ -33,6 +33,25 @@ pub trait AttentionMaskBackend { fn is_active(&self, mailbox_id: MailboxId) -> bool; } +/// Production-backend impl: wires the sibling `attention_mask::AttentionMaskSoA` +/// into the actor without forcing downstream consumers to write a newtype +/// (Rust orphan rules would block them — neither the trait nor the SoA is +/// theirs). Per codex P2 review on PR #388. +impl AttentionMaskBackend for crate::attention_mask::AttentionMaskSoA { + fn touch(&mut self, mailbox_id: MailboxId, w_slot: u8) -> bool { + crate::attention_mask::AttentionMaskSoA::touch(self, mailbox_id, w_slot) + } + fn evict_lru(&mut self) -> Option { + crate::attention_mask::AttentionMaskSoA::evict_lru(self) + } + fn tick(&mut self) { + crate::attention_mask::AttentionMaskSoA::tick(self) + } + fn is_active(&self, mailbox_id: MailboxId) -> bool { + crate::attention_mask::AttentionMaskSoA::is_active(self, mailbox_id) + } +} + pub struct AttentionMaskActor { inner: B, pending_evictions: Vec,