agent: lumotia-rebrand — fix Codex cross-model review blockers
Codex independent review found 11 blockers post-cascade. All addressed.
CRITICAL (data-loss / crash):
10. crates/core/src/paths.rs — migrate_legacy_data_dir_inner used
fs::rename which fails with EXDEV when source + target are on
different filesystems (encrypted-home, bind mounts, separate
$XDG_DATA_HOME partition). Combined with the Phase 5 QC fix that
made migration errors fatal, this would crash on first launch
for any user whose data dir spans filesystems. Added
rename_or_copy_tree() that falls back to copy_dir_recursive +
remove_dir_all on CrossesDevices / errno 18 (EXDEV). Symlinks
preserved verbatim. Same fallback applied to magnotia.db ->
lumotia.db inside the dir.
11. Added 4 unit tests: copy_dir_recursive preserves nested
structure, rename_or_copy_tree same-filesystem happy path,
is_cross_device classifies CrossesDevices kind + raw errno 18.
Doc residuals (blockers 1-9):
1. crates/cloud-providers/Cargo.toml — "Wyrdnote pending rebrand"
description.
2. crates/cloud-providers/src/provider.rs — module docs + test
fixture Wyrdnote refs.
3. crates/transcription/src/orchestrator.rs — module docs + test
fixture Wyrdnote refs.
4. docs/roadmap/2026-05-10-pkm-phase-tooling-shortlist.md — phase
name + outputs/wyrdnote path refs.
5. docs/architecture-map/04-llm-formatting-mcp/llm-tests.md —
MAGNOTIA_LLM_TEST_MODEL env var.
6. .../cloud-providers-stubs.md — MAGNOTIA_API_KEY_*.
7. docs/architecture-map/03-audio-transcription/tests-and-fixtures.md
— MAGNOTIA_WHISPER_*.
8. docs/gpu-tuning/plan.md — MAGNOTIA_BENCH_RUN.
9. docs/superpowers/specs/2026-05-09-battery-gpu-aware-thread-tuning-
design.md + corresponding plan — MAGNOTIA_POWER_STATE_OVERRIDE,
MAGNOTIA_INFERENCE_THREADS.
cargo test --workspace: 343 pass / 0 fail (up from 339; +4 EXDEV
fallback tests).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -263,7 +263,7 @@ git commit -m "feat(core): parse_power_state_from_dir reads sysfs power_supply A
|
||||
|
||||
This task adds the public probe entry point. Two override paths:
|
||||
1. `with_override(state, |closure|)` — in-process, serialised via a `TEST_LOCK` mutex held for the body. Used by unit tests because cargo's parallel runner makes env-var-based tests flaky.
|
||||
2. `MAGNOTIA_POWER_STATE_OVERRIDE` env var — used by `thread_sweep.rs` integration test (set externally, not from inside `cargo test`'s parallel block).
|
||||
2. `LUMOTIA_POWER_STATE_OVERRIDE` env var — used by `thread_sweep.rs` integration test (set externally, not from inside `cargo test`'s parallel block).
|
||||
|
||||
- [ ] **Step 1: Write failing unit tests using `with_override`**
|
||||
|
||||
@@ -296,21 +296,21 @@ Append inside `mod tests` in `crates/core/src/power.rs`:
|
||||
// env-var path tested in isolation under TEST_LOCK so it
|
||||
// doesn't race with the in-process override tests.
|
||||
with_override(None, || {
|
||||
std::env::set_var("MAGNOTIA_POWER_STATE_OVERRIDE", "battery");
|
||||
std::env::set_var("LUMOTIA_POWER_STATE_OVERRIDE", "battery");
|
||||
assert_eq!(probe_power_state(), PowerState::OnBattery);
|
||||
std::env::remove_var("MAGNOTIA_POWER_STATE_OVERRIDE");
|
||||
std::env::remove_var("LUMOTIA_POWER_STATE_OVERRIDE");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn env_var_override_garbage_falls_through() {
|
||||
with_override(None, || {
|
||||
std::env::set_var("MAGNOTIA_POWER_STATE_OVERRIDE", "nonsense");
|
||||
std::env::set_var("LUMOTIA_POWER_STATE_OVERRIDE", "nonsense");
|
||||
// Garbage value falls through to the platform probe.
|
||||
// We can't assert the platform result so just assert it
|
||||
// doesn't panic.
|
||||
let _ = probe_power_state();
|
||||
std::env::remove_var("MAGNOTIA_POWER_STATE_OVERRIDE");
|
||||
std::env::remove_var("LUMOTIA_POWER_STATE_OVERRIDE");
|
||||
});
|
||||
}
|
||||
```
|
||||
@@ -331,7 +331,7 @@ use std::sync::Mutex;
|
||||
///
|
||||
/// Resolution order (highest to lowest priority):
|
||||
/// 1. In-process test override (set via `with_override` from unit tests).
|
||||
/// 2. `MAGNOTIA_POWER_STATE_OVERRIDE` env var (`ac` | `battery` | `unknown`,
|
||||
/// 2. `LUMOTIA_POWER_STATE_OVERRIDE` env var (`ac` | `battery` | `unknown`,
|
||||
/// case-insensitive). Used by `thread_sweep.rs` integration tests.
|
||||
/// 3. Linux: `parse_power_state_from_dir("/sys/class/power_supply")`.
|
||||
/// 4. macOS / Windows / other: `Unknown`.
|
||||
@@ -351,7 +351,7 @@ pub fn probe_power_state() -> PowerState {
|
||||
}
|
||||
|
||||
fn env_override() -> Option<PowerState> {
|
||||
let raw = std::env::var("MAGNOTIA_POWER_STATE_OVERRIDE").ok()?;
|
||||
let raw = std::env::var("LUMOTIA_POWER_STATE_OVERRIDE").ok()?;
|
||||
match raw.trim().to_ascii_lowercase().as_str() {
|
||||
"ac" => Some(PowerState::OnAc),
|
||||
"battery" => Some(PowerState::OnBattery),
|
||||
@@ -562,7 +562,7 @@ pub const MIN_INFERENCE_THREADS: usize = 2;
|
||||
/// 8 is a conservative ceiling that leaves <5% on the table for
|
||||
/// big-iron desktops while keeping consumer 6c/12t laptops out of
|
||||
/// contention territory. Users can override at runtime via
|
||||
/// MAGNOTIA_INFERENCE_THREADS.
|
||||
/// LUMOTIA_INFERENCE_THREADS.
|
||||
pub const MAX_INFERENCE_THREADS: usize = 8;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -583,13 +583,13 @@ const GPU_FLOOR_WHISPER: usize = 4;
|
||||
/// the battery and GPU-offload heuristics.
|
||||
///
|
||||
/// Resolution order:
|
||||
/// 1. `MAGNOTIA_INFERENCE_THREADS=N` — absolute bypass, returns N.
|
||||
/// 1. `LUMOTIA_INFERENCE_THREADS=N` — absolute bypass, returns N.
|
||||
/// 2. base = num_cpus::get_physical() (fallback: available_parallelism).
|
||||
/// 3. on battery → base /= 2.
|
||||
/// 4. gpu_offloaded → base = min(base, gpu_floor(workload)).
|
||||
/// 5. clamp to [MIN_INFERENCE_THREADS, MAX_INFERENCE_THREADS].
|
||||
pub fn inference_thread_count(_workload: Workload, _gpu_offloaded: bool) -> usize {
|
||||
if let Ok(s) = std::env::var("MAGNOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(s) = std::env::var("LUMOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(n) = s.parse::<usize>() {
|
||||
if n > 0 {
|
||||
return n;
|
||||
@@ -617,7 +617,7 @@ mod tests {
|
||||
// should return physical-core count clamped to [2, 8].
|
||||
// We can't pin physical exactly without mocking num_cpus; just
|
||||
// assert the result is in range.
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
let n = inference_thread_count(Workload::Llm, false);
|
||||
assert!(n >= MIN_INFERENCE_THREADS && n <= MAX_INFERENCE_THREADS,
|
||||
"got {n}, expected within [{MIN_INFERENCE_THREADS}, {MAX_INFERENCE_THREADS}]");
|
||||
@@ -625,10 +625,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn env_var_bypasses_clamps() {
|
||||
std::env::set_var("MAGNOTIA_INFERENCE_THREADS", "10");
|
||||
std::env::set_var("LUMOTIA_INFERENCE_THREADS", "10");
|
||||
let n = inference_thread_count(Workload::Llm, true);
|
||||
assert_eq!(n, 10);
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -672,7 +672,7 @@ Add to `mod tests` in `crates/core/src/tuning.rs`:
|
||||
```rust
|
||||
#[test]
|
||||
fn battery_halves_thread_count() {
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
// Lock both the test override mutex and assert.
|
||||
crate::power::with_override(Some(PowerState::OnBattery), || {
|
||||
let on_battery = inference_thread_count(Workload::Llm, false);
|
||||
@@ -709,7 +709,7 @@ Modify `inference_thread_count` in `crates/core/src/tuning.rs`. Replace the body
|
||||
|
||||
```rust
|
||||
pub fn inference_thread_count(workload: Workload, gpu_offloaded: bool) -> usize {
|
||||
if let Ok(s) = std::env::var("MAGNOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(s) = std::env::var("LUMOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(n) = s.parse::<usize>() {
|
||||
if n > 0 {
|
||||
return n;
|
||||
@@ -760,7 +760,7 @@ Add to `mod tests` in `crates/core/src/tuning.rs`:
|
||||
```rust
|
||||
#[test]
|
||||
fn gpu_offload_clamps_llm_to_floor() {
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
crate::power::with_override(Some(PowerState::OnAc), || {
|
||||
let n = inference_thread_count(Workload::Llm, true);
|
||||
assert!(n <= GPU_FLOOR_LLM.max(MIN_INFERENCE_THREADS),
|
||||
@@ -771,7 +771,7 @@ Add to `mod tests` in `crates/core/src/tuning.rs`:
|
||||
|
||||
#[test]
|
||||
fn gpu_offload_clamps_whisper_to_floor() {
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
crate::power::with_override(Some(PowerState::OnAc), || {
|
||||
let n = inference_thread_count(Workload::Whisper, true);
|
||||
// Whisper floor is 4 on machines with >=4 physical cores;
|
||||
@@ -790,7 +790,7 @@ Add to `mod tests` in `crates/core/src/tuning.rs`:
|
||||
|
||||
#[test]
|
||||
fn gpu_offload_off_does_not_clamp_below_battery_calc() {
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
crate::power::with_override(Some(PowerState::OnAc), || {
|
||||
let no_gpu = inference_thread_count(Workload::Llm, false);
|
||||
let with_gpu = inference_thread_count(Workload::Llm, true);
|
||||
@@ -811,7 +811,7 @@ Modify `inference_thread_count` in `crates/core/src/tuning.rs`:
|
||||
|
||||
```rust
|
||||
pub fn inference_thread_count(workload: Workload, gpu_offloaded: bool) -> usize {
|
||||
if let Ok(s) = std::env::var("MAGNOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(s) = std::env::var("LUMOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(n) = s.parse::<usize>() {
|
||||
if n > 0 {
|
||||
return n;
|
||||
@@ -869,7 +869,7 @@ Add to `mod tests` in `crates/core/src/tuning.rs`:
|
||||
// Smoke: helper should run without panicking when logging is
|
||||
// wired. This is covered by the other tests too, but kept
|
||||
// explicitly to document the behaviour.
|
||||
std::env::remove_var("MAGNOTIA_INFERENCE_THREADS");
|
||||
std::env::remove_var("LUMOTIA_INFERENCE_THREADS");
|
||||
crate::power::with_override(Some(PowerState::OnBattery), || {
|
||||
let _ = inference_thread_count(Workload::Llm, true);
|
||||
let _ = inference_thread_count(Workload::Whisper, false);
|
||||
@@ -903,7 +903,7 @@ Update `inference_thread_count` to log once per tuple:
|
||||
|
||||
```rust
|
||||
pub fn inference_thread_count(workload: Workload, gpu_offloaded: bool) -> usize {
|
||||
if let Ok(s) = std::env::var("MAGNOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(s) = std::env::var("LUMOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(n) = s.parse::<usize>() {
|
||||
if n > 0 {
|
||||
return n;
|
||||
@@ -1313,10 +1313,10 @@ fn thread_count_scaling() -> std::io::Result<()> {
|
||||
("AC, GPU (Vulkan if available)", "ac"),
|
||||
("battery, GPU (Vulkan if available)", "battery"),
|
||||
] {
|
||||
std::env::set_var("MAGNOTIA_POWER_STATE_OVERRIDE", power_var);
|
||||
std::env::set_var("LUMOTIA_POWER_STATE_OVERRIDE", power_var);
|
||||
run_sweep_panel(label, &model_path, &audio, n_threads_values)?;
|
||||
}
|
||||
std::env::remove_var("MAGNOTIA_POWER_STATE_OVERRIDE");
|
||||
std::env::remove_var("LUMOTIA_POWER_STATE_OVERRIDE");
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn probe_power_state() -> PowerState;
|
||||
|
||||
**TTL cache**: `OnceLock<Mutex<(PowerState, Instant)>>` with 10s TTL. Re-probe on expiry. Battery state changes slowly; 10s is far below human-perceptible latency for thread-count adjustment.
|
||||
|
||||
**Test override**: `MAGNOTIA_POWER_STATE_OVERRIDE=ac|battery|unknown` short-circuits the probe. Always-on (not just `cfg(test)`) so `thread_sweep.rs` can drive both states without unplugging hardware. Documented as test-only; users overriding it in production is benign.
|
||||
**Test override**: `LUMOTIA_POWER_STATE_OVERRIDE=ac|battery|unknown` short-circuits the probe. Always-on (not just `cfg(test)`) so `thread_sweep.rs` can drive both states without unplugging hardware. Documented as test-only; users overriding it in production is benign.
|
||||
|
||||
### `tuning.rs`
|
||||
|
||||
@@ -81,8 +81,8 @@ const GPU_FLOOR_LLM: usize = 2;
|
||||
const GPU_FLOOR_WHISPER: usize = 4;
|
||||
|
||||
pub fn inference_thread_count(workload: Workload, gpu_offloaded: bool) -> usize {
|
||||
// 1. MAGNOTIA_INFERENCE_THREADS env override → absolute bypass
|
||||
if let Ok(s) = std::env::var("MAGNOTIA_INFERENCE_THREADS") {
|
||||
// 1. LUMOTIA_INFERENCE_THREADS env override → absolute bypass
|
||||
if let Ok(s) = std::env::var("LUMOTIA_INFERENCE_THREADS") {
|
||||
if let Ok(n) = s.parse::<usize>() {
|
||||
if n > 0 { return n; }
|
||||
}
|
||||
@@ -156,15 +156,15 @@ Compile-time feature check (`whisper-vulkan` is in default features) plus runtim
|
||||
|
||||
### Override behaviour
|
||||
|
||||
- `MAGNOTIA_INFERENCE_THREADS=N` (existing, unchanged) — absolute bypass. Returns N regardless of power/GPU state. For benchmarking, big-iron desktops, and users who want to opt out.
|
||||
- `MAGNOTIA_POWER_STATE_OVERRIDE` — test only.
|
||||
- `LUMOTIA_INFERENCE_THREADS=N` (existing, unchanged) — absolute bypass. Returns N regardless of power/GPU state. For benchmarking, big-iron desktops, and users who want to opt out.
|
||||
- `LUMOTIA_POWER_STATE_OVERRIDE` — test only.
|
||||
- No fine-grained `MAGNOTIA_BATTERY_CLAMP=off` or similar in v1. Add only if real users hit a case where the existing all-or-nothing override is insufficient.
|
||||
|
||||
## Tests
|
||||
|
||||
### Existing test extended
|
||||
|
||||
`crates/transcription/tests/thread_sweep.rs` already runs the JFK clip across n_threads values and prints an RTF table. Extend to four blocks driven by `MAGNOTIA_POWER_STATE_OVERRIDE`:
|
||||
`crates/transcription/tests/thread_sweep.rs` already runs the JFK clip across n_threads values and prints an RTF table. Extend to four blocks driven by `LUMOTIA_POWER_STATE_OVERRIDE`:
|
||||
|
||||
```
|
||||
=== n_threads scaling: AC, CPU ===
|
||||
@@ -181,7 +181,7 @@ Each block uses the same `n_threads` sweep `[1, 2, 4, 6, 8, 12]` and reports xc_
|
||||
|
||||
- `battery_clamp_halves_on_battery` — set override to battery, assert returned value is roughly half of AC.
|
||||
- `gpu_floor_lower_for_llm_than_whisper` — both with `gpu_offloaded=true`, assert Llm ≤ Whisper.
|
||||
- `env_var_bypasses_all_clamps` — set `MAGNOTIA_INFERENCE_THREADS=10`, set battery, set gpu_offloaded; assert returns 10.
|
||||
- `env_var_bypasses_all_clamps` — set `LUMOTIA_INFERENCE_THREADS=10`, set battery, set gpu_offloaded; assert returns 10.
|
||||
- `clamp_to_min_when_low_core_count` — fall through to min on 1-2 logical cores via available_parallelism (use a mock or just verify clamp inside the function).
|
||||
- `clamp_to_max_for_huge_machines` — assert MAX_INFERENCE_THREADS=8 still binds.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user