C51 Q-var slot + q_abs_ref outlier clamp
Bundles 4 ISV signal-quality fixes from the audit at
docs/superpowers/specs/2026-04-23-isv-signal-quality-audit.md.
1. Regime signals (slots 8-11) now batch-aggregate over all B samples
instead of reading sample 0 only. Adds `int batch_size` kernel arg
and fixes a latent stride bug (launch passed STATE_DIM=104 but
states_buf has stride STATE_DIM_PADDED=128 — sample 0 worked by
luck because both strides land at the same offset for row 0).
99.994% information loss closed.
2. Health (slot 12) now couples to outcomes: sigmoid(0.1 × sharpe_ema)
EMA-blended. New ISV slot 22 = SHARPE_EMA_INDEX persists the
Rust-side training_sharpe_ema. ISV_DIM 22→23. Prior component-
aggregation health formula was ANTI-correlated with Sharpe
(r=-0.765 per audit) because its components saturated at 0/1
boundaries (q_gap=1.0 / q_var=1.0 for 19/20 epochs, grad_stable
stuck at 0.0 for 20/20 epochs). New formula's sensitive sigmoid
region [-10, +10] Sharpe matches the observed magnitude range.
The Rust-side write_isv_signal_at is preserved as a fallback
initializer at epoch boundaries — the kernel then overwrites
slot 12 every training step based on slot 22's current value.
3. Slot 3 now carries C51 Q-distribution variance (wired via third
c51_loss_reduce launch, same pattern as td_error fix 7f92fa242).
Previously zero-initialised with no writer. Renamed from
"ensemble_var_scratch" to "q_var_scratch" to reflect actual
semantics — it is the batch mean of q_var_buf_trainer (atom-
spread variance from the C51 distributional head), NOT multi-head
ensemble disagreement. True multi-head ensemble variance remains
a separate follow-up if/when a per-head ensemble is wired.
Slot 4 (velocity derivative of slot 3) becomes meaningful
automatically.
4. q_dir_abs_ref (slot 21) and q_abs_ref (slot 16) gain outlier
clamps before EMA update: clamped = min(raw, 10×current + 1) to
prevent single ±10⁵ Q-excursions from poisoning 20 epochs. The
+1 floor handles the cold-start case where current EMA is near 0.
Slot 21 is especially load-bearing because it feeds the Kelly
conviction denominator (q_range / q_dir_abs_ref).
ISV_DIM bump 22→23 changes the flat-param buffer size (w_isv_fc1
tensor [68] grows from [16,22] to [16,23] → +16 floats). Xavier
init at gpu_dqn_trainer.rs:13819 picks up the new dimension
automatically. Pinned allocs scale via ISV_DIM * size_of::<f32>()
expressions. No safetensors / checkpoint format currently encodes
ISV layout directly — checkpoint_state_dim/num_actions/hidden_dims
are the only hashed architectural fields — but the flat param
buffer content differs, so existing live checkpoints will require
rebase. Acceptable for the current pre-production dev state.
Tests: workspace cargo check --workspace --tests passes clean. Ran
magnitude_distribution smoke 3 times locally (RTX 3050 Ti); health
in HEALTH_DIAG now tracks negative Sharpe regime (0.50→0.38
trajectory over 20 epochs with mean sharpe_raw=-7) rather than
climbing monotonically as in the audit's train-mdh86 logs
(0.50→0.64 against Sharpe +34→-67). The magnitude_distribution
eval-dist H10 gate sometimes passes, sometimes fails depending on
the training seed — the pre-existing H10 flakiness persists. The
pre-existing 14 ml-lib test failures are unrelated (OFI features
missing / production profile config mismatch / test_batch_size
test environment issues — all fail on HEAD as well).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>