hunt Claude Sonnet 5 commited on
Commit
d0c3803
Β·
1 Parent(s): 6933ec1

WO-1 tasks.md: embed Q&A clarifications + MIRI + latency benchmark

Browse files

Top section now answers all four pre-build questions inline so Kiro never
needs to ask again:
- Hermes: not integrated, not running β€” Kiro is the agent
- Pipeline 1: node labels are role labels; AWS services fill them; bus is agnostic
- Build target: x86-64 local first, ARM64 t4g.small second with re-benchmark
- Session model: multi-session, real CAT switches, handoff blocks as written

T4: added MIRI step (cargo +nightly miri test) after ring buffer compiles β€”
catches UB that cargo test on x86 TSO cannot detect.

T5: added latency benchmark test with assert!(elapsed_us <= 50) β€” real ΞΌs
measurement with false-sharing diagnosis note and #[repr(align(64))] fix.

T7: added ARM64 verification step post-commit (SSH to t4g.small, cargo test
natively, re-run latency benchmark).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

.kiro/specs/wo1-workspace-ipc-backbone/tasks.md CHANGED
@@ -1,8 +1,74 @@
1
  # WO-1: Tasks
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ## Before you start β€” mandatory
4
 
5
- 1. **Read `requirements.md` and `design.md` in this directory first.** They contain the full context, the pre-flight skill references, and the struct designs you will implement. Do not skip them.
6
 
7
  2. **Run the CAT-5 scanner now:**
8
  ```
@@ -10,15 +76,15 @@
10
  ```
11
  from the repo root. Confirm this Work Order's tasks appear in the output. Paste the output as a reply before beginning.
12
 
13
- 3. **Check your current model against the first task's CAT tag.** This Work Order starts on CAT 1 (Qwen3 Coder Next). If you are running on a different model, switch before proceeding. See `.kiro/steering/model-routing-protocol.md` for the exact switch notice wording.
14
 
15
- 4. **Every task below requires real command output as evidence.** A description of what the output "should" say is not evidence. Paste the actual terminal output.
16
 
17
  ---
18
 
19
- ## The CAT-5 routing summary for this Work Order
20
 
21
- | Tasks | CAT tier | Model |
22
  |---|---|---|
23
  | T1, T2, T7 | CAT 1 | Qwen3 Coder Next |
24
  | T6 | CAT 2 | GLM-5 |
@@ -42,6 +108,8 @@
42
 
43
  *If you get a "linker not found" or "error[E0]: can't find crate" error: check that the Rust toolchain is installed (`rustup show`) and that all six crate directories exist under the repo root (`ls -d miranda-*/`).*
44
 
 
 
45
  ---
46
 
47
  - [ ] [CAT 1] **T2 β€” Add dependencies to `miranda-ipc/Cargo.toml`**
@@ -54,23 +122,19 @@
54
  ```
55
 
56
  Notes:
57
- - `memmap2` is the maintained fork of the original `memmap` crate. It provides `MmapMut` for the shared-memory region. Do not use the original `memmap` crate β€” it is unmaintained.
58
- - `bytemuck` with the `derive` feature enables `#[derive(Pod, Zeroable)]` on the payload structs. These derives are compile-time proofs that a struct has no padding, no uninit bytes, and can be safely cast to/from `&[u8]`.
59
- - You do not need `crossbeam` or any external atomic crate β€” `std::sync::atomic::AtomicUsize` with explicit orderings is sufficient for this ring buffer.
60
 
61
- After editing the file, run `cargo build` again to confirm the new deps resolve and compile:
62
- ```
63
- cargo build
64
- ```
65
- Paste the output. If `memmap2` or `bytemuck` fail to download (offline or registry issue), diagnose β€” do not skip.
66
 
67
  ---
68
 
69
  - [ ] [CAT 3] **T3 β€” Define the three payload structs in `miranda-core`**
70
 
71
- Open `miranda-core/src/lib.rs`. Add the following, exactly as specified in `design.md`. Do not invent different field names or sizes β€” these are fixed by the pipeline science.
72
 
73
- **Constants (add at the top of the file):**
74
  ```rust
75
  pub const AUDIO_SAMPLE_RATE_HZ: u32 = 16_000;
76
  pub const AUDIO_CHUNK_FRAMES: usize = 160; // 10 ms at 16 kHz
@@ -78,12 +142,12 @@
78
  pub const SH_COEFF_COUNT: usize = 9; // L2 spherical harmonic coefficients
79
  ```
80
 
81
- **Why these specific numbers:**
82
- - `AUDIO_CHUNK_FRAMES = 160`: 10 ms of audio at 16 kHz. This is the standard VAD/ASR chunk size for streaming speech recognition (Parakeet, Whisper, all use 10 ms frames).
83
- - `BLENDSHAPE_COUNT = 52`: the ARKit face blendshape standard (Eyes, brows, mouth, jaw, cheek β€” full facial animation rig). WO-3 will implement the SIMD kinematic solver that produces these 52 values.
84
- - `SH_COEFF_COUNT = 9`: L2 spherical harmonics β€” 9 coefficients per color channel encoding low-frequency ambient light. Used by the WebGPU Gaussian-splat renderer (WO-5) to relight EVE dynamically.
85
 
86
- **Structs (add after the constants):**
87
  ```rust
88
  #[repr(C)]
89
  #[derive(Debug, Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
@@ -109,169 +173,194 @@
109
  }
110
  ```
111
 
112
- After adding, run:
 
 
113
  ```
114
  cargo build -p miranda-core
115
  ```
116
- The `bytemuck::Pod` and `bytemuck::Zeroable` derives will fail to compile if the struct has any padding, non-Copy fields, or uninit bytes β€” that is the compile-time safety proof working as intended. If you get a compile error from the derives, it means the struct layout is not C-ABI safe and you must fix it before proceeding.
117
-
118
  Paste the real build output.
119
 
120
- *Size check (informational β€” cargo does not assert this automatically):*
121
- - `AudioChunk`: 8 + 4 + 4 + (160 Γ— 4) = 656 bytes
122
- - `BlendshapeFrame`: 8 + (52 Γ— 4) = 216 bytes
123
- - `SphericalHarmonics`: 8 + (9 Γ— 4) = 44 bytes
124
-
125
- You can verify with `std::mem::size_of::<AudioChunk>()` in a test if you want compile-time confirmation.
126
-
127
  ---
128
 
129
  - [ ] [CAT 5] **T4 β€” Implement the ring buffer in `miranda-ipc` β€” Claude Opus 5 ONLY**
130
 
131
  ⚠️ **MANDATORY MODEL SWITCH BEFORE THIS TASK**
132
 
133
- If you are not currently running as Claude Opus 5, STOP. Do not attempt this task on any other model. Emit the following and wait for the model to be switched:
134
-
135
  ```
136
  CAT 5 MODEL SWITCH REQUIRED β€” T4 (ring buffer implementation) requires Claude Opus 5.
137
  Switch the chat model dropdown to Claude Opus 5, then re-issue this task alone.
138
  ```
139
 
140
- **Handoff block to paste into the Opus 5 session:**
141
  ```
142
  === CAT 5 HANDOFF β€” switching to Claude Opus 5 ===
143
  Task: T4 β€” Implement the lock-free ring buffer in miranda-ipc
144
- Status: Ready to implement β€” all prerequisites complete (T1 build verified, T2 deps added, T3 structs defined)
145
- State: miranda-core now exports AudioChunk (656B), BlendshapeFrame (216B), SphericalHarmonics (44B) β€” all #[repr(C)] with bytemuck::Pod. miranda-ipc has memmap2 and bytemuck as deps.
 
146
  Incoming needs to know:
147
  - Three separate ring buffers (not one polymorphic), one per struct type
148
  - POSIX shared memory at /dev/shm/miranda_bus (tmpfs, RAM-backed β€” required for ≀50 ΞΌs target)
149
  - AtomicUsize head/tail, AcqRel/Acquire/Release ordering β€” NO mutex, NO SeqCst
150
  - Power-of-2 slot counts: audio=64, blendshape=128, sh=128
151
- - AtomicUsize cannot be trivially placed in mmap β€” requires raw pointer cast with SAFETY comment
152
  - Every unsafe block requires a // SAFETY: comment explaining the invariant
153
- - bytemuck::bytes_of and bytemuck::from_bytes are the safe cast path for writing/reading slots
 
 
154
  === END HANDOFF ===
155
  ```
156
 
157
  **What Opus 5 must implement in `miranda-ipc/src/lib.rs`:**
158
 
159
- 1. A `MirandaBus` struct that opens or creates `/dev/shm/miranda_bus` using `memmap2::MmapMut`, with the three ring buffers laid out at fixed byte offsets within the mapping.
160
-
161
- 2. Push methods for each payload type: `push_audio`, `push_blendshape`, `push_sh` β€” each returning `Result<(), BackpressureError>`.
162
-
163
- 3. Pop methods for each payload type: `pop_audio`, `pop_blendshape`, `pop_sh` β€” each returning `Option<T>` where T is the payload type.
164
-
165
- 4. The `AtomicUsize` head and tail for each buffer must be placed at the *start* of the mmap at known, alignment-safe byte offsets. The slot data follows.
166
-
167
- 5. Every `unsafe` block β€” pointer cast, raw memory read/write β€” must have a `// SAFETY:` comment.
168
-
169
- 6. The implementation must use `bytemuck::bytes_of()` to write a struct as bytes into a slot, and `bytemuck::from_bytes()` to read it back β€” this is the safe, proven path for `#[repr(C)] + Pod` types.
170
-
171
- **What Opus 5 must NOT do:**
172
- - Do not use a `Mutex` or `RwLock` anywhere in the hot path
173
- - Do not use `Ordering::SeqCst`
174
- - Do not use `unsafe` transmute without a `SAFETY` comment
175
- - Do not hardcode the struct sizes as magic numbers β€” use `std::mem::size_of::<T>()`
176
- - Do not make the capacity non-power-of-2
177
-
178
- After implementation, run:
179
  ```
180
  cargo build -p miranda-ipc
181
  ```
182
- Paste the real output. If it does not compile cleanly, fix it β€” do not proceed to T5 until T4 builds.
183
-
184
- ---
185
 
186
- - [ ] [CAT 4] **T5 β€” Write the concurrent round-trip test β€” Claude Sonnet 5**
 
 
 
 
187
 
188
- ⚠️ **Model check:** This task requires Claude Sonnet 5. If you are currently on Opus 5 (from T4), you may switch back to Sonnet 5 for this task, or remain on Opus 5 if you prefer β€” Opus 5 is an acceptable superset for CAT 4 work. If you are on a lower tier, switch to Sonnet 5 first.
189
 
190
- Write a `#[cfg(test)]` module in `miranda-ipc/src/lib.rs` with a test named `test_blendshape_round_trip_concurrent`. This test must:
191
 
192
- 1. Open a `MirandaBus` instance (or two, one for write and one for read, if the bus supports multiple openers).
193
 
194
- 2. Spawn a writer thread that pushes 1,000 `BlendshapeFrame` payloads with distinct, incrementing `timestamp_us` values (0, 1, 2, ... 999) and weights filled with the frame index cast to f32.
195
 
196
- 3. Spawn a reader thread that pops 1,000 `BlendshapeFrame` payloads and asserts each one is byte-identical to the corresponding payload the writer pushed β€” same `timestamp_us`, same `weights`.
197
 
198
- 4. Both threads run **concurrently** β€” do not use `thread::sleep` to serialize them, and do not use a channel to artificially sequence them. The test must exercise actual concurrent read-write access.
199
 
200
- 5. The test must print (using `println!` or `eprintln!`) a message that identifies which thread wrote and which read, with timestamps β€” this is the evidence that proves both threads actually ran concurrently, not sequentially.
 
 
 
 
 
201
 
202
- 6. The test must pass under `cargo test` without `--test-threads=1`.
203
 
204
- **Escalation rule:** If this test fails real concurrent verification twice (a real race condition, a data corruption assertion, a deadlock), emit:
205
- ```
206
- CAT 5 ESCALATION β€” T5 has failed real concurrent verification twice. Switch to Claude Opus 5 before the third attempt.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  ```
208
 
 
 
209
  Run:
210
  ```
211
  cargo test -p miranda-ipc -- --nocapture
212
  ```
213
- Paste the complete output, including any `println!`/`eprintln!` output from the test threads.
 
 
 
 
 
214
 
215
  ---
216
 
217
  - [ ] [CAT 2] **T6 β€” Document every `unsafe` block β€” GLM-5**
218
 
219
- ⚠️ **Model check:** Switch to GLM-5 for this task.
220
 
221
- Open `miranda-ipc/src/lib.rs` and scan for every `unsafe` block or `unsafe` expression. For each one, add or verify a `// SAFETY:` comment directly above or inside the block explaining:
222
- - What the unsafe operation is (e.g., "casting *mut u8 at offset N to *mut AtomicUsize")
223
- - What invariant the caller upholds that makes this sound (e.g., "offset N is 8-byte aligned because it was computed as size_of::<AtomicUsize>() * n from the mmap base, and memmap2 guarantees page alignment")
224
- - What would happen if the invariant were violated (e.g., "undefined behavior: misaligned atomic operations on x86 can tear")
225
 
226
- Every `unsafe` block without a `// SAFETY:` comment is a defect in WO-1 β€” the ring buffer is the single most failure-prone component, and these comments are the written record of why it is correct.
227
-
228
- No build output required for this task (it's a documentation addition), but run:
229
  ```
230
  cargo build -p miranda-ipc
231
  ```
232
- to confirm no accidental syntax errors were introduced. Paste the output.
233
 
234
  ---
235
 
236
  - [ ] [CAT 1] **T7 β€” Final verification pass and commit β€” Qwen3 Coder Next**
237
 
238
- ⚠️ **Model check:** Switch back to Qwen3 Coder Next for this task.
239
 
240
- Run the full test suite from the repo root:
241
  ```
242
  cargo test
243
  ```
244
- and then:
245
  ```
246
  cargo test -p miranda-ipc -- --nocapture
247
  ```
248
 
249
- The first command verifies that adding WO-1's code has not broken any other crate. The second command shows the full concurrent test output with thread-level detail.
 
 
250
 
251
- Both must exit 0. Paste both outputs verbatim.
252
 
253
- Then run the CAT-5 scanner to update the pending backlog:
254
  ```
255
  node scripts/cat-router-check.mjs
256
  ```
257
- All seven WO-1 tasks should now show as done (no unchecked boxes for this Work Order). Paste the scanner output.
258
 
259
- Commit everything with a message that includes the `cargo test` output:
260
  ```
261
  git add -A
262
- git commit -m "WO-1 complete: lock-free IPC backbone, 3 ring buffers, concurrent round-trip test"
263
  ```
264
 
265
- WO-1 is done. The foundation is live. WO-2 (VAD/ASR routing) can begin.
266
 
267
- ---
 
 
 
 
268
 
269
- ## When WO-1 is done β€” what changes
270
 
271
- Once all seven tasks above are checked off with real evidence:
272
 
273
- - **WO-2** can begin: `miranda-audio` can now write `AudioChunk`s to the bus for VAD and parakeet.cpp ASR processing.
274
- - **WO-3** can begin: `miranda-nodes` can now write `BlendshapeFrame`s and `SphericalHarmonics` to the bus from the SIMD kinematics solver.
275
- - **WO-4** (transport) and **WO-5** (renderer) both depend on WO-2 and WO-3 being further along β€” they can begin design work but not integration work until WO-2 and WO-3 are writing real data to the bus.
276
 
277
- The MASTER_PROMPT.md at the repo root is the paste-ready prompt for starting WO-2's Kiro session. It includes the updated CAT table with all five models and references both steering docs automatically.
 
 
 
 
1
  # WO-1: Tasks
2
 
3
+ ## Clarifications β€” read before doing anything else
4
+
5
+ These answer the three questions you asked before starting, plus a correction on a commonly misunderstood part of the project. They are embedded here so this spec is self-contained and you do not have to ask again.
6
+
7
+ ---
8
+
9
+ ### On Hermes β€” it is not integrated and not running
10
+
11
+ Nothing in this repo calls a Hermes API, spawns a Hermes process, or depends on Hermes being installed. The `nobility-posh-framework` Kiro skill references "5 Work Orders as Hermes Execution Prompts" β€” that phrase means the Work Orders were *written in the format* of Hermes execution prompts (a structured prompt style used in multi-agent orchestration). It describes the format, not a running system.
12
+
13
+ **In this Kiro workspace, Kiro is the agent.** The spec files are what Kiro reads and executes. The CAT-5 model switching is controlled by the human changing the model dropdown in Kiro's UI and re-issuing the task. There is no external orchestrator. There is nothing to install or configure for "Hermes." The IPC bus you are building in this Work Order *is* Miranda-Engine's equivalent of what Hermes would coordinate β€” but the bus is what WO-1 builds from scratch in Rust.
14
+
15
+ ---
16
+
17
+ ### On the Pipeline 1 change β€” the node labels are role labels, not product deployments
18
+
19
+ Since this spec was written, the example first pipeline has been updated to a **fully AWS-native, batteries-included implementation**. The node labels you see in THE VANITY's left pane (Riva ASR / Nemotron Agent / Hive TTS / Audio2Face-3D / AnimGraph / Omniverse Stream) are **role labels** β€” they describe the class of work at each position, not literal product deployments.
20
+
21
+ For Pipeline 1, each role is filled by an AWS managed service Kiro already has direct access to:
22
+
23
+ | Node role label | Pipeline 1 AWS service |
24
+ |---|---|
25
+ | Riva ASR | Amazon Transcribe Streaming |
26
+ | Nemotron Agent | Amazon Bedrock (Nova Pro or Claude Haiku via Converse API) |
27
+ | Hive TTS | Amazon Polly Neural TTS |
28
+ | Audio2Face-3D | Amazon Polly Speech Marks (viseme output) |
29
+ | AnimGraph / Omniverse | Amazon Sumerian Hosts SDK (Three.js, `aws-samples/amazon-sumerian-hosts`) |
30
+
31
+ **The IPC bus you are building in WO-1 does not change based on which pipeline fills it.** `BlendshapeFrame.weights` (52 channels) will be populated by Polly viseme-to-blendshape adapter logic in Pipeline 1, and by the SIMD kinematics solver in Pipeline 2. The bus is agnostic — build it once. The full AWS node mapping, Polly viseme→BlendshapeFrame adapter table, and Sumerian Hosts setup are in `.kiro/steering/pipeline-1-aws-native.md`. Read that after WO-1 is done.
32
+
33
+ ---
34
+
35
+ ### On the build target β€” local x86-64 first, ARM64 second
36
+
37
+ Build and verify locally on the **Celeron N4500 (x86-64, native, no cross-compilation)**. The ≀50 ΞΌs target in the requirements is stated against this machine.
38
+
39
+ The AWS plan uses a **t4g.small (Graviton/ARM64)** β€” a different ISA. When you move to EC2:
40
+ - Option A (recommended): SSH into the t4g.small and run `cargo build` + `cargo test` natively there β€” no cross-compilation toolchain needed.
41
+ - Option B: cross-compile locally: `rustup target add aarch64-unknown-linux-gnu`, then `cargo build --target aarch64-unknown-linux-gnu`.
42
+
43
+ **The ≀50 ΞΌs latency target must be re-benchmarked separately on each platform.** ARM64 has weaker memory ordering than x86 (x86 is TSO β€” total store order β€” so atomic `AcqRel`/`Acquire`/`Release` is nearly free there but costs real memory fences on ARM). A benchmark that passes 50 ΞΌs on the Celeron does not guarantee passing on Graviton. In practice, SHM round-trips on Graviton are typically *faster* than on the Celeron β€” but verify rather than assume.
44
+
45
+ **Sequence:** verify correctness locally (T1–T7), then SSH into the t4g.small, re-run `cargo test`, and re-run the latency benchmark from T5 natively. If the benchmark fails on ARM64, the fix is `#[repr(align(64))]` on the atomic control structs to eliminate false sharing between the head/tail atomics and the slot data.
46
+
47
+ ---
48
+
49
+ ### On the session model β€” multi-session with real model switches
50
+
51
+ Use **multi-session with explicit handoff blocks at each CAT transition**, not a single-session planning exercise. The CAT-5 protocol is a real cost-control tool:
52
+
53
+ - T4 (the lock-free ring buffer) is a genuine CAT 5 problem. Wrong-but-compiling lock-free code produces silent data corruption at 60 FPS. It benefits from Opus 5's reasoning depth β€” not from "acknowledging the routing exists" while Sonnet executes it.
54
+ - T1 (verify `cargo build`) costs the same tokens whether it runs on Qwen3 or Opus 5. Sending it through Opus 5 is direct cash spent with zero quality return.
55
+
56
+ **How the session boundaries work in Kiro:**
57
+
58
+ 1. **Qwen3 Coder Next** β€” paste MASTER_PROMPT.md, execute T1 and T2
59
+ 2. **DeepSeek 3.2** β€” execute T3 (struct definitions)
60
+ 3. **Claude Opus 5** β€” paste the T4 handoff block below, execute T4 only
61
+ 4. **Claude Sonnet 5** (or stay on Opus 5 β€” acceptable superset) β€” execute T5
62
+ 5. **GLM-5** β€” execute T6 (SAFETY comments)
63
+ 6. **Qwen3 Coder Next** β€” execute T7 (final verification + commit)
64
+
65
+ Each switch is a 10-second dropdown change in Kiro. The handoff block in T4 is the paste that brings the new model up to speed.
66
+
67
+ ---
68
+
69
  ## Before you start β€” mandatory
70
 
71
+ 1. **Read `requirements.md` and `design.md` in this directory first.** They contain the full context, the pre-flight skill references, the struct designs, and the atomic ordering rationale. Do not skip them.
72
 
73
  2. **Run the CAT-5 scanner now:**
74
  ```
 
76
  ```
77
  from the repo root. Confirm this Work Order's tasks appear in the output. Paste the output as a reply before beginning.
78
 
79
+ 3. **Check your current model against the first task's CAT tag.** This Work Order starts on CAT 1 (Qwen3 Coder Next). If you are running on a different model, switch before proceeding.
80
 
81
+ 4. **Every task requires real command output as evidence.** A description of what the output "should" say is not evidence. Paste the actual terminal output.
82
 
83
  ---
84
 
85
+ ## CAT-5 routing summary for this Work Order
86
 
87
+ | Task | CAT tier | Model |
88
  |---|---|---|
89
  | T1, T2, T7 | CAT 1 | Qwen3 Coder Next |
90
  | T6 | CAT 2 | GLM-5 |
 
108
 
109
  *If you get a "linker not found" or "error[E0]: can't find crate" error: check that the Rust toolchain is installed (`rustup show`) and that all six crate directories exist under the repo root (`ls -d miranda-*/`).*
110
 
111
+ *Note on build targets: this verification runs locally (x86-64, native). The t4g.small (ARM64) verification happens separately after T7 β€” see the build target clarification at the top of this file.*
112
+
113
  ---
114
 
115
  - [ ] [CAT 1] **T2 β€” Add dependencies to `miranda-ipc/Cargo.toml`**
 
122
  ```
123
 
124
  Notes:
125
+ - `memmap2` is the maintained fork of the original `memmap` crate. Do not use the original `memmap` β€” it is unmaintained.
126
+ - `bytemuck` with the `derive` feature enables `#[derive(Pod, Zeroable)]` on the payload structs β€” compile-time proof that the struct has no padding, no uninit bytes, and can be safely cast to/from `&[u8]`.
127
+ - You do not need `crossbeam` β€” `std::sync::atomic::AtomicUsize` with explicit orderings is sufficient.
128
 
129
+ After editing, run `cargo build` again and paste the output. If `memmap2` or `bytemuck` fail to resolve, diagnose β€” do not skip.
 
 
 
 
130
 
131
  ---
132
 
133
  - [ ] [CAT 3] **T3 β€” Define the three payload structs in `miranda-core`**
134
 
135
+ Open `miranda-core/src/lib.rs`. Add the constants and structs exactly as specified in `design.md`. Do not invent different field names or sizes β€” these are fixed by the pipeline science.
136
 
137
+ **Constants:**
138
  ```rust
139
  pub const AUDIO_SAMPLE_RATE_HZ: u32 = 16_000;
140
  pub const AUDIO_CHUNK_FRAMES: usize = 160; // 10 ms at 16 kHz
 
142
  pub const SH_COEFF_COUNT: usize = 9; // L2 spherical harmonic coefficients
143
  ```
144
 
145
+ **Why these numbers:**
146
+ - `160 frames`: 10 ms of audio at 16 kHz β€” the standard VAD/ASR chunk size for streaming speech recognition. Pipeline 1 uses Amazon Transcribe Streaming (sends 10 ms chunks); later pipelines use parakeet.cpp. Same constant, same bus, different implementation.
147
+ - `52 blendshapes`: ARKit face blend shape standard β€” the full facial animation rig. Pipeline 1 populates ~22 of these channels from Amazon Polly Speech Marks (visemes); Pipeline 2 will populate all 52 from the SIMD kinematics solver (WO-3). The bus struct does not change between pipelines.
148
+ - `9 SH coefficients`: L2 spherical harmonics encoding low-frequency ambient lighting β€” used by the Gaussian-splat renderer (WO-5, Pipeline 2) to relight EVE. Pipeline 1's Sumerian Hosts renderer does not use them yet; they default to 0.0.
149
 
150
+ **Structs:**
151
  ```rust
152
  #[repr(C)]
153
  #[derive(Debug, Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
 
173
  }
174
  ```
175
 
176
+ The `bytemuck::Pod` and `bytemuck::Zeroable` derives will fail to compile if the struct has any padding, non-Copy fields, or uninit bytes β€” that is the compile-time safety proof working as intended. A compile error from the derives means the struct layout is not C-ABI safe and must be fixed.
177
+
178
+ Run:
179
  ```
180
  cargo build -p miranda-core
181
  ```
 
 
182
  Paste the real build output.
183
 
 
 
 
 
 
 
 
184
  ---
185
 
186
  - [ ] [CAT 5] **T4 β€” Implement the ring buffer in `miranda-ipc` β€” Claude Opus 5 ONLY**
187
 
188
  ⚠️ **MANDATORY MODEL SWITCH BEFORE THIS TASK**
189
 
190
+ If you are not currently running as Claude Opus 5, STOP. Emit:
 
191
  ```
192
  CAT 5 MODEL SWITCH REQUIRED β€” T4 (ring buffer implementation) requires Claude Opus 5.
193
  Switch the chat model dropdown to Claude Opus 5, then re-issue this task alone.
194
  ```
195
 
196
+ **Handoff block β€” paste this as the first message in the Opus 5 session:**
197
  ```
198
  === CAT 5 HANDOFF β€” switching to Claude Opus 5 ===
199
  Task: T4 β€” Implement the lock-free ring buffer in miranda-ipc
200
+ Status: Ready β€” T1 build verified clean, T2 deps added, T3 structs defined and compiling
201
+ State: miranda-core exports AudioChunk (656B), BlendshapeFrame (216B), SphericalHarmonics (44B)
202
+ All #[repr(C)] + bytemuck::Pod. miranda-ipc has memmap2 and bytemuck as deps.
203
  Incoming needs to know:
204
  - Three separate ring buffers (not one polymorphic), one per struct type
205
  - POSIX shared memory at /dev/shm/miranda_bus (tmpfs, RAM-backed β€” required for ≀50 ΞΌs target)
206
  - AtomicUsize head/tail, AcqRel/Acquire/Release ordering β€” NO mutex, NO SeqCst
207
  - Power-of-2 slot counts: audio=64, blendshape=128, sh=128
208
+ - AtomicUsize cannot be trivially placed in mmap β€” requires raw pointer cast with // SAFETY: comment
209
  - Every unsafe block requires a // SAFETY: comment explaining the invariant
210
+ - bytemuck::bytes_of and bytemuck::from_bytes are the safe cast path for slots
211
+ - The context: this bus serves Pipeline 1 (Polly visemes β†’ BlendshapeFrame) and all future
212
+ pipelines. The bus is pipeline-agnostic. Build it once.
213
  === END HANDOFF ===
214
  ```
215
 
216
  **What Opus 5 must implement in `miranda-ipc/src/lib.rs`:**
217
 
218
+ 1. `MirandaBus` struct β€” opens or creates `/dev/shm/miranda_bus` with `memmap2::MmapMut`, three ring buffers at fixed byte offsets.
219
+ 2. Push methods: `push_audio`, `push_blendshape`, `push_sh` β†’ `Result<(), BackpressureError>`
220
+ 3. Pop methods: `pop_audio`, `pop_blendshape`, `pop_sh` β†’ `Option<T>`
221
+ 4. `AtomicUsize` head/tail at alignment-safe byte offsets at the start of the mmap; slot data follows.
222
+ 5. Every `unsafe` block has a `// SAFETY:` comment.
223
+ 6. Uses `bytemuck::bytes_of()` to write a struct as bytes into a slot, `bytemuck::from_bytes()` to read back.
224
+
225
+ **Must NOT do:**
226
+ - No `Mutex` or `RwLock` in the hot path
227
+ - No `Ordering::SeqCst`
228
+ - No `unsafe` transmute without a `// SAFETY:` comment
229
+ - No hardcoded struct sizes as magic numbers β€” use `std::mem::size_of::<T>()`
230
+ - No non-power-of-2 capacities
231
+
232
+ **Step 1 β€” build:**
 
 
 
 
 
233
  ```
234
  cargo build -p miranda-ipc
235
  ```
236
+ Paste the output. Do not proceed to Step 2 if this does not exit 0.
 
 
237
 
238
+ **Step 2 β€” MIRI undefined behavior check (added requirement):**
239
+ ```
240
+ cargo +nightly miri test -p miranda-ipc
241
+ ```
242
+ MIRI is Rust's interpreter-based undefined behavior checker. It catches invalid pointer casts, misaligned memory accesses, and incorrect atomic memory ordering that `cargo test` on x86 cannot detect (x86's TSO model hides many ordering errors that would crash on ARM or be caught by MIRI). If MIRI is not installed: `rustup component add miri --toolchain nightly`. If MIRI reports any error, the implementation has undefined behavior and must be fixed before T5 starts β€” do not proceed past a MIRI failure.
243
 
244
+ Paste the MIRI output.
245
 
246
+ ---
247
 
248
+ - [ ] [CAT 4] **T5 β€” Write the concurrent round-trip test + latency benchmark β€” Claude Sonnet 5**
249
 
250
+ ⚠️ **Model check:** Claude Sonnet 5. If on Opus 5 from T4, you may stay β€” Opus 5 is an acceptable superset. If on a lower tier, switch to Sonnet 5 first.
251
 
252
+ **Part A β€” concurrent round-trip test:**
253
 
254
+ Write a `#[cfg(test)]` test named `test_blendshape_round_trip_concurrent` that:
255
 
256
+ 1. Opens a `MirandaBus` instance.
257
+ 2. Spawns a writer thread pushing 1,000 `BlendshapeFrame` payloads with distinct, incrementing `timestamp_us` values (0, 1, 2, ... 999) and weights filled with the frame index cast to f32.
258
+ 3. Spawns a reader thread popping 1,000 `BlendshapeFrame` payloads and asserting each is byte-identical to the written payload β€” same `timestamp_us`, same `weights` β€” using `assert_eq!`.
259
+ 4. Both threads run **concurrently** β€” no `thread::sleep` to serialize, no channel to artificially sequence. This must exercise actual concurrent read-write access.
260
+ 5. Prints (via `println!` or `eprintln!`) a message from each thread with thread name and timestamp β€” this is the proof both threads actually ran.
261
+ 6. Passes under `cargo test` without `--test-threads=1`.
262
 
263
+ **Part B β€” latency benchmark (added requirement):**
264
 
265
+ Write a second `#[cfg(test)]` test named `test_round_trip_latency` that measures real round-trip performance:
266
+ ```rust
267
+ #[test]
268
+ fn test_round_trip_latency() {
269
+ let bus = MirandaBus::open_or_create().unwrap();
270
+ let frame = BlendshapeFrame { timestamp_us: 0, weights: [0.0; BLENDSHAPE_COUNT] };
271
+ let start = std::time::Instant::now();
272
+ for _ in 0..10_000 {
273
+ bus.push_blendshape(frame).unwrap();
274
+ let _ = bus.pop_blendshape();
275
+ }
276
+ let elapsed_us = start.elapsed().as_micros() as u64 / 10_000;
277
+ println!("Mean round-trip latency: {} ΞΌs", elapsed_us);
278
+ assert!(
279
+ elapsed_us <= 50,
280
+ "Round-trip latency {} ΞΌs exceeds ≀50 ΞΌs target β€” check for false sharing on head/tail atomics",
281
+ elapsed_us
282
+ );
283
+ }
284
  ```
285
 
286
+ **If the latency benchmark fails (elapsed_us > 50 on the local Celeron N4500):** the most likely cause is false sharing β€” the head/tail `AtomicUsize` values and the slot data are on the same 64-byte cache line, causing the CPU to invalidate the entire line on every write. Fix: add `#[repr(align(64))]` to the control struct that holds the atomics so they occupy their own cache line. Re-run after the fix.
287
+
288
  Run:
289
  ```
290
  cargo test -p miranda-ipc -- --nocapture
291
  ```
292
+ Paste the complete output including `println!`/`eprintln!` from both tests.
293
+
294
+ **Escalation rule:** If the concurrent round-trip test fails real concurrent verification twice (data corruption assertion, deadlock, race), emit:
295
+ ```
296
+ CAT 5 ESCALATION β€” T5 has failed real concurrent verification twice. Switch to Claude Opus 5 before the third attempt.
297
+ ```
298
 
299
  ---
300
 
301
  - [ ] [CAT 2] **T6 β€” Document every `unsafe` block β€” GLM-5**
302
 
303
+ ⚠️ **Model check:** Switch to GLM-5.
304
 
305
+ Scan `miranda-ipc/src/lib.rs` for every `unsafe` block or `unsafe` expression. For each one, add or verify a `// SAFETY:` comment explaining:
306
+ - What the unsafe operation is
307
+ - What invariant the caller upholds that makes it sound
308
+ - What would happen if the invariant were violated
309
 
310
+ Every `unsafe` block without a `// SAFETY:` comment is a defect. After adding comments, run:
 
 
311
  ```
312
  cargo build -p miranda-ipc
313
  ```
314
+ and paste the output to confirm no syntax errors were introduced.
315
 
316
  ---
317
 
318
  - [ ] [CAT 1] **T7 β€” Final verification pass and commit β€” Qwen3 Coder Next**
319
 
320
+ ⚠️ **Model check:** Switch back to Qwen3 Coder Next.
321
 
322
+ Run the full workspace test suite:
323
  ```
324
  cargo test
325
  ```
326
+ then the IPC-specific suite with output:
327
  ```
328
  cargo test -p miranda-ipc -- --nocapture
329
  ```
330
 
331
+ Both must exit 0. The second command must show:
332
+ - The concurrent round-trip test output with thread-level detail proving both threads ran
333
+ - The latency benchmark output showing the mean round-trip ΞΌs and confirming it is ≀50
334
 
335
+ Paste both outputs verbatim.
336
 
337
+ Run the CAT-5 scanner:
338
  ```
339
  node scripts/cat-router-check.mjs
340
  ```
341
+ All seven WO-1 tasks should show as complete (no unchecked boxes for this Work Order). Paste the scanner output.
342
 
343
+ Commit:
344
  ```
345
  git add -A
346
+ git commit -m "WO-1 complete: lock-free IPC backbone, 3 ring buffers, MIRI clean, concurrent test, ≀50ΞΌs latency verified"
347
  ```
348
 
349
+ **After committing β€” ARM64 verification:**
350
 
351
+ SSH into the t4g.small EC2 instance, clone the repo (or `git pull` if already cloned), and run:
352
+ ```
353
+ cargo test -p miranda-ipc -- --nocapture
354
+ ```
355
+ natively on the Graviton box. Re-run the latency benchmark result. Paste the output as a comment on this commit or in the Kiro session. The ≀50 ΞΌs target applies on both platforms β€” if ARM64 fails, apply the `#[repr(align(64))]` fix from T5 and re-run.
356
 
357
+ WO-1 is done. Read `.kiro/steering/pipeline-1-aws-native.md` now β€” it tells you exactly what the Pipeline 1 implementations of WO-2 through WO-5 look like and which AWS services fill each node role. WO-2 (acoustic ingress) can begin.
358
 
359
+ ---
360
 
361
+ ## When WO-1 is done β€” what it unblocks
 
 
362
 
363
+ - **WO-2 (Pipeline 1)**: Amazon Transcribe Streaming client in `miranda-audio` writes `AudioChunk`s to `audio_bus`. No parakeet.cpp yet β€” Transcribe is the batteries-included ASR for Pipeline 1.
364
+ - **WO-3 (Pipeline 1)**: Polly Speech Marks viseme-to-BlendshapeFrame adapter in `miranda-nodes` writes `BlendshapeFrame`s to `blendshape_bus`. The SIMD solver (full WO-3) is Pipeline 2.
365
+ - **WO-4 / WO-5 (Pipeline 1)**: KVS WebRTC (JS SDK) and Amazon Sumerian Hosts (Three.js) in `client-apps/web/` handle transport and rendering without touching the Rust transport crate or WebGPU β€” those are Pipeline 2 targets.
366
+ - **MASTER_PROMPT.md** at the repo root is the paste-ready prompt for opening any subsequent Kiro session. It loads all steering docs and references the Pipeline 1 spec automatically.