Commit Graph

155 Commits

Author SHA1 Message Date
jgrusewski
6b01b70c3e docs(sp6): implementation plan — 3-sub-project parallel refactor (Pearls 2, 3, 5)
Three independent sub-projects (one per Pearl), each an atomic commit,
each running in its own git worktree (sp6-pearl-2/3/5). Pearl 2 expands
compute_adaptive_budgets() to per-branch [f32;4] arrays + trunk-mean
scalars, dispatches branch-correction SAXPY sub-launches. Pearl 3
replaces noise_sigma: f32 with noise_sigma_per_branch: [f32;4] in
ExperienceCollectorConfig and extends add_advantage_noise to per-branch
lookup. Pearl 5 adds 4-branch tau buffer triplets to GpuIqnHead, runs
4 IQN forward passes per step (Approach B), each contributing
iqn_trunk/4 to prevent 4x gradient accumulation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 01:47:07 +02:00
jgrusewski
11979d7c08 docs(sp5): comprehensive implementation plan — 4 layers, ~21 tasks
SP5 implementation plan covering:
  Layer A: 8 per-pearl commits (Tasks A0-A8)
    A0: ISV slot constants foundation
    A1: Pearl 1 per-branch atom span + Q-stats source
    A2: Pearl 3 per-branch NoisyNet σ
    A3: Pearl 2 per-branch loss budget (after Pearls 1+3)
    A4: Pearl 4 per-group Adam β/β/ε
    A5: Pearl 5 per-branch IQN τ schedule
    A6: Pearl 6 cross-fold-persistent Kelly
    A7: Pearl 8 per-direction trail distance
    A8: Pearl 1-ext per-branch num_atoms

  Layer B: 1 atomic commit (Task B1) — 11 consumer migrations

  Layer C: validation + cleanup (Tasks C1-C6)
    C1: Local GPU unit tests
    C2: L40S 5-epoch smoke
    C3: L40S 3-seed × 50-epoch full validation
    C4: Pearl 7 investigation (post-validation)
    C5: Audit doc + 8 memory pearls
    C6: Layer C commit

  Layer D: separate atomic commit (Tasks D1-D4)
    D1: PnL aggregation kernel
    D2: Health composition kernel
    D3: Training metrics EMA kernel
    D4: Layer D atomic commit

Total: 21 numbered tasks, ~110 ISV slots, 9-11 producer kernels,
11 consumer migrations.

Plan follows SP4's high-fidelity-for-Task-A1 + differential-pattern-
for-A2-A8 structure. Each task has concrete file paths, code blocks,
verification commands, exact commit messages.

Self-review:
  - Spec coverage: all 9 pearls + 4 layers covered
  - No TBD/TODO placeholders in step bodies
  - Type/slot consistency verified across tasks

Refs: docs/superpowers/specs/2026-05-01-sp5-magnitude-differentiation-and-eval-collapse-design.md (HEAD 6e6e0fa11)
2026-05-01 20:01:27 +02:00
jgrusewski
24accea774 fix(sp4): migrate fast/slow grad-norm EMA update to GPU per feedback_no_cpu_compute_strict
Layer C close-out C1 redesigned. Original plan claimed
grad_norm_slow_ema_pinned was orphan post-Mech-6 migration; verification
surfaced a SECOND live consumer (fold_warmup_factor_update, commit
4ef1d8ebb) that legitimately reads the slow EMA as cross-fold
steady-state baseline.

The actual defect: the EMA UPDATE at update_adaptive_clip:22720-22737
was host-side `(1-α)*prev + α*obs` arithmetic — exactly the pattern
feedback_no_cpu_compute_strict (saved 2026-05-01) strictly forbids.

Migrated:
  - New `update_grad_norm_emas_kernel.cu` — single-thread fused fast+slow
    EMA update kernel. Reads `grad_norm_buf[0]`, updates two mapped-pinned
    EMA scalars via dev_ptr. `__threadfence_system()` ensures the
    `fold_warmup_factor_kernel` consumer sees freshly-written values.
  - `launch_update_grad_norm_emas` Rust launcher chained on the
    producer's stream — graph-capture-compatible, no host sync.
  - update_adaptive_clip's host-side `unsafe { ... }` block replaced
    with the GPU launcher call (warn-and-continue on launch failure
    mirroring the launch_h_s2_rms_ema / launch_fold_warmup_factor
    per-step ISV producer pattern at training_loop.rs:3450/3464).

Preserved:
  - grad_norm_slow_ema_pinned mapped-pinned buffer (cross-fold persistent;
    legitimate consumer is fold_warmup_factor_update).
  - Fixed-α design (FAST_ALPHA=0.1, SLOW_ALPHA=0.001) — Pearls A+D
    adaptive α would defeat the cross-fold-baseline semantic the warmup
    factor depends on.
  - Cold-start sentinel (`prev ≤ 0.0` ⇒ assign obs directly) — same
    formula as the deleted host code.
  - Host-side update_adaptive_clip early-return guard — kernel only
    launches when observed_grad_norm is finite and > 0.
  - grad_norm_emas_step_count host counter — scalar control-flow
    metadata for warmup-window gating, not compute.

Plan/spec docs updated to remove stale "orphan" claim. State-reset
registry doc-comment + field doc-comments updated to reflect GPU-only
update path. fold_warmup_factor_kernel docstring no longer describes
its grad-norm EMA inputs as host-side-fed.

Build clean, sp4 + state_reset_registry lib tests pass (11/11), 16/16
SP4 producer GPU tests pass on RTX 3050 Ti. No behavior change — pure
architectural fix.

Refs: SP4 Layer C C1 redesigned (was: retire). Original plan
docs/superpowers/plans/2026-04-30-sp4-signal-driven-magnitude-control.md
lines 2184-2221.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 14:07:10 +02:00
jgrusewski
c06169136c docs(sp4): implementation plan for signal-driven magnitude control
Comprehensive 3-layer implementation plan for the SP4 spec at
docs/superpowers/specs/2026-04-30-sp4-signal-driven-magnitude-control-design.md.

Layer A — additive infrastructure (Tasks A1-A18, no behavior change):
- A1: 40 ISV slot index constants in new sp4_isv_slots.rs module
- A2: wiener_state_buf (141 floats) + clamp_engage_per_block_buf (2048 ints)
- A3: Pearls A+D shared helper (sp4_wiener_ema.rs) + 5 unit tests
- A4: linear-histogram p99 device function (sp4_histogram_p99.cuh) + GPU test
- A5-A9: 5 producer kernels (target_q + atom_pos × 4 branches + param_group_oracle
   × 8 groups + grad_norm + h_s2 = 15 fused producers per Pearl B)
- A10-A11: wire 4 captured-graph + 10 cold-path launch sites
- A12: 181 StateResetRegistry entries (40 ISV + 141 Wiener-state float +
   2048 Pearl C int)
- A13: retrofit 7 existing pre-SP4 producers with Pearls A+D
- A14-A15: Pearl C engagement counter in 5 Adam kernels + host-side
   rate-deficit EMA + force-bump trigger
- A16-A18: 40-test integration validation + L40S regression smoke + audit
   doc draft

Layer B — atomic consumer migration (Task B1, ONE coordinated commit):
- Mech 1, 2, 5, 6, 9, 10 consumers flip simultaneously to ISV-driven
- Adam kernels' weight_decay arg from ISV[WD_RATE[group]]
- L1 lambda from ISV[L1_LAMBDA_TRUNK_INDEX]
- HyperParams config fields removed
- Per `feedback_no_partial_refactor`

Layer C — validation + cleanup (Tasks C1-C5):
- C1: retire grad_norm_slow_ema infrastructure (Mech 6 migrated away)
- C2: remove dead Mech 5 fused-kernel parameters
- C3: L40S smoke validation against spec pass criteria
- C4: comprehensive Invariant 7 audit-doc entry
- C5: 5 new pearl memory entries + SP4 close-out project entry

Estimated effort: 3500-4500 LOC across ~25 commits, 1.5-2 weeks of focused
work, 1 L40S smoke validation. Bite-sized TDD tasks with exact file paths,
complete code blocks, and exact build/test commands per task.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 21:48:03 +02:00
jgrusewski
9b35fe9d45 plan(dqn): SP2 + SP3 implementation — fused NaN kernel + 5-mechanism Q-stability
Implementation plan for the approved combined design spec
(commit ed727b51c). Three phases:

Phase A — SP2 (5 tasks A1-A5 + Gate 1 smoke task A6):
- A1: Append dqn_nan_check_fused_f32_kernel to dqn_utility_kernels.cu
- A2: Add nan_check_buf_ptrs / nan_check_buf_lens device buffers (separate
      ptr + len arrays per the design fork resolution; cleaner than packed)
- A3: populate_nan_check_meta + launch_nan_check_fused_f32 wrappers
- A4: Replace 8 individual check_nan_f32 calls with single fused launch
- A5: Audit doc Phase E + wire-up Invariant 7 entries
- A6: Gate 1 smoke — F0 ≥ 53.08 (must pass before Phase B)

Phase B — SP3 (8 tasks B1-B8 + Gate 2 smoke task B9):
- B1: Slot 36-47 diagnostic accessors (Adam m/v + weight slice + target_q + atoms)
- B2: Mech 1 — target_q clip after compute_denoise_target_q (single-point)
- B3: Mech 2 — C51 atom-position growth bounds in EMA-update kernel
- B4: Mech 3 — hard target sync (DQN main + IQN) at fold boundary
- B5: Mech 4 — comprehensive Adam EMA reset at fold transitions
- B6: Mech 5 — fused kernel extended to 24 slots with inline threshold-by-
      slot-index logic (no per-step HtoD; q_abs_ref_eff passed as single arg)
- B7: Name table entries for slots 36-47 (both halt_nan + halt_grad_collapse)
- B8: Audit doc Phase F + wire-up Invariant 7 entries
- B9: Gate 2 smoke — full SP1 7-criterion validation

Phase C — Closure (2 tasks C1-C2):
- C1: project_sp2_sp3_resolved.md memory entry + SP1 closure update
- C2: Audit doc closure + wire-up final entry + push

Operating principles enforced throughout:
- ISV-driven bounds (Q_ABS_REF=16, ε on multiplier per SP1 pearl)
- No new ISV slots
- No DtoD/HtoD per step (inline-compute resolution for thresholds)
- Permanent diagnostic always-on (no debug flags)
- Per-task commits during dev; SP3 mechanisms ship together
- F0 paper-review documented per ISV bound

Plan covers ~1000 LOC across multiple commits, 2 L40S smokes (Gate 1 +
Gate 2), 4-7 days estimated. Self-review confirms full spec coverage.
2026-04-30 08:49:36 +02:00
jgrusewski
05958d3a0c plan(dqn): SP1 numerical stability — F1 NaN root-cause investigation
Implementation plan for SP1 (Sub-project 1 of 3) of the numerical
stability investigation. Follows the γ + β methodology from the spec
at docs/superpowers/specs/2026-04-29-numerical-stability-investigation-design.md.

8 tasks across 4 phases:
- Phase A (Task 1): γ read-only audit producing docs/dqn-backward-nan-audit.md
- Phase B (Tasks 2-5): always-landing β instrumentation expanding
  nan_flags_buf 24→48 with 12 new backward-kernel NaN check slots
  + 12 reserved slots for future coverage
- Phase C (Task 6): surgical fix(es), content-driven by audit + smoke
  topology, ISV-driven for any dynamic bound (mandatory)
- Phase D (Task 7): multi-fold L40S smoke validation against 7 pass
  criteria (F0 ≥ 95% baseline, F1+F2 monotone improvement, zero
  NaN-CLAMPED-TO-ZERO, all 48 NaN flag slots remain at zero)
- Closure (Task 8): audit doc closure, memory entry, SP2/SP3 handoff

Operating principles (mandatory per spec):
- No deferrals — anomalies discovered during investigation get fixed
  within SP1, not punted to SP2/SP3
- Combined RELATED fixes ship as rich commits (per
  feedback_no_partial_refactor)
- ISV-driven design for any dynamic bound

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 23:21:26 +02:00
jgrusewski
5de5e546a4 fix(dqn): Plan C T2 amendment — match production adaptive C51 support
Plan C as authored assumed:
  - c51_probs_dir = post-softmax probabilities (didn't exist on collector;
    only raw exp_b_logits is materialised)
  - atom_values = single global linear support (production uses per-sample
    per-direction adaptive [v_min, v_max, delta_z] + optional atom_positions)
  - iqn_quantiles_dir = rollout-side IQN inference (doesn't exist; IQN is
    training-only)

Amended kernel signature uses the production architecture:
  - b_logits_dir [N, b0_size, n_atoms] — raw direction-branch logits
  - per_sample_support [N, b0_size, 3] — adaptive per-direction support
  - atom_positions [b0_size, n_atoms] — non-linear positions (NULL = linear)
  - n_atoms

Direction-branch Thompson is now single-distribution over C51 (with adaptive
support), not joint C51+IQN. Single-distribution still provides the
principled posterior sample that fixes the UCB selector/target asymmetry —
the goal of Plan C is preserved, just sourced from the existing rollout-time
distribution instead of a non-existent IQN inference path.

New device-inline helpers: softmax_c51_inline, compute_atom_values_inline.

Plan + audit doc updated. Phase 0 standalone test kernel gained two new
entry points (direction_thompson_v2_test, argmax_eq_v2_test) matching the
amended production API; original Plan A entry points retained for tests
0.B-0.F. Tasks 3+4 (buffer wiring) unblocked — collector/evaluator already
have per_sample_support_buf and exp_b_logits in production.
2026-04-29 17:26:22 +02:00
jgrusewski
fc4addaabf spec+plan(moe): correct gate input dim 42 → STATE_DIM=128
T1.6 implementer correctly identified that the gate input dim is
ml_core::state_layout::STATE_DIM=128, not the literal 42 the spec/plan
incorrectly stated. The 42-dim figure was the bar-feature subset; the
actual state vector is 128-dim (42 features + portfolio + MTF + OFI
padded to 128 for cuBLAS alignment).

Updated spec §3 architecture diagram, §4.1 gate subnetwork description
+ parameter count (3,272 → 8,776), and plan header architecture line.
Implementation in commit 28c707f6a is correct; this commit just makes
the spec match the implementation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 18:22:40 +02:00
jgrusewski
76e55047ec spec+plan(moe): add no-HtoD/HtoH constraint; mapped pinned only
Per feedback_no_htod_htoh_only_mapped_pinned.md (newly recorded): every
CPU<->GPU path in this redesign uses mapped pinned memory exclusively.
No cudaMemcpy HtoD, no Vec-to-Vec defensive copies, including in test
code. CPU is strictly read-only on the production surface.

Plan changes:
- New Task 2.0 promotes MappedF32Buffer / MappedI32Buffer from
  distributional_q_tests.rs local definitions to a shared
  crates/ml/src/cuda_pipeline/mapped_pinned.rs module so all kernel
  test wrappers (Test 0.F, upcoming MoE tests) share one
  implementation. Adds write_from_slice helper for direct host_ptr
  write (no memcpy).
- Task 2.1 test wrapper rewritten to allocate mapped pinned buffers
  + write to host_ptr + read GPU-written output via host_ptr. No more
  memcpy_stod / memcpy_dtov in test code.

Spec: new section 6.4 codifies the mapped-pinned-only constraint and
references the shared module + reference implementation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 17:46:41 +02:00
jgrusewski
69141d6266 plan(dqn): MoE regime redesign — bite-sized implementation plan
Implementation plan for the approved MoE spec at
docs/superpowers/specs/2026-04-27-moe-regime-redesign-design.md.

6 phases:
- Phase 0: use_* flag cleanup + count_bonus refactor (precondition,
  partially in stash@{0})
- Phase 1: MoE infrastructure (additive — moe_lambda hyperparameter,
  9 ISV slots, MoeGate/MoeExpert skeletons, params_buf layout extension)
- Phase 2: 4 new CUDA kernels (mixture forward/backward,
  load_balance_loss, expert_util_ema_update) with TDD unit tests
- Phase 3: wire MoE into the training graph (forward, backward, loss
  aggregation, ISV producer launch, HEALTH_DIAG aux_moe line)
- Phase 4: atomic deletion of vestigial RegimeConditionalDQN (per
  feedback_no_partial_refactor.md)
- Phase 5: Layer 3/5 tests + L40S 30-epoch validation with explicit
  kill criteria

Each task has bite-sized steps (2-5 min each) with exact file paths,
copy-pasteable code, exact commands, and TDD pattern (test fails first,
implement to make pass, commit).

Self-review: spec section coverage verified, no placeholders, type
consistency verified across phases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 17:42:07 +02:00
jgrusewski
3c61ee52ce plan(dqn): Thompson sampling rollout — Plans A+B+C+D (4 sequential phases)
Implementation plans for the distributional-RL aggregation spec
(docs/superpowers/specs/2026-04-26-distributional-rl-aggregation-design.md).

Plan A — Phase 0: TDD hypothesis verification (8 tasks)
  - Standalone GPU test kernel: sample_c51_inverse_cdf,
    sample_iqn_quantile_interp, compute_e_c51, compute_e_iqn,
    thompson_direction_test, argmax_eq_test
  - 6 unit tests (5 GPU + 1 CPU synthetic edge)
  - GPU integration on converged checkpoint (Test 0.F)

Plan B — Phase 1: existing-lever audit (8 tasks)
  - 6 unit tests covering B.2/CF/PopArt/Q-target audit fixture
  - Exit gate: all 6 PASS = no reward-shaping bug; Phase 2 unblocked

Plan C — Phase 2: Thompson sampling integration (11 tasks)
  - Direction branch of experience_action_select rewritten:
    eps-greedy + Boltzmann → Thompson (training) + argmax E[Q] (eval)
  - C51 + IQN buffers wired to gpu_dqn_trainer + gpu_backtest_evaluator
  - train_active_frac HEALTH_DIAG instrumentation
  - 4 GPU-direct tests against production kernel
  - Aggregation Contract table + memory pearl

Plan D — Phase 3: long verification + dead-code cleanup (8 tasks)
  - Test 3.A: regression anchor against original C51 Flat bias
  - L4: 1 seed × 6 folds × 30 epoch (~1 hour)
  - L5: 5 seed × 6 fold matrix per Plan 5 Task 5 (Tier 1+2+3 PASS)
  - Direction-only eps_dir adaptive boost + Boltzmann tau-floor cleanup
    (per feedback_no_partial_refactor.md)
  - nsys regression check; final architecture/spec footer

Plans gated sequentially: each phase exit gate must pass before next.
2026-04-27 08:10:42 +02:00
jgrusewski
e9100073b9 plan(dqn-v2): Plan 4 Task 2c GRN — further decomposed into 2c.1/2c.2/2c.3+4/2c.5
A first dispatch of monolithic Task 2c was refused with a second scope
assessment that surfaced three architectural facts beyond what 2a/2b
had captured:

(d) attn_layer_norm_bwd_dx is a SIMPLIFIED element-wise approximation
    (d_x = d_out * gamma / std), not the full LN Jacobian. Reusing
    it in the GRN backward would propagate the approximation into
    trunk gradients silently. Task 2c.1 must write a new full
    Jacobian: (1/D) * rstd * (D * d_out_g - sum_d(d_out_g) -
    normed * sum_d(d_out_g * normed)).

(e) IQN target-trunk migration is not a clean swap. iqn_compute_
    target_h_s2 reproduces the legacy LeakyReLU trunk independently
    in CUDA. Deleting it requires a target_encoder_forward_only
    extraction on the target path (Task 4-style refactor on the
    target side). Sub-task in itself.

(f) Three relu_mask removal sites have three different save-buffer
    lifetimes (online trunk per-step, IQN-aux per-step in different
    trainer, target-sync per-target-update). Three plumbing tasks,
    not one.

Decomposition:
- 2c.1: grn_kernel.cu with full LN Jacobian backward + GLU + ELU +
  residual-add. Module compiles standalone (additive, dead code).
- 2c.2: gpu_grn.rs Rust wrapper with 5 save-for-backward state
  buffers per block (not 3 as the prior plan suggested).
- 2c.3+4: ATOMIC commit — compute_param_sizes 86→95 + fingerprint
  rewrite + xavier init for 13 new tensors + all 98 padded_byte_
  offset migrations + 3 relu_mask sites with different save-buffer
  plumbing each + iqn target trunk delete + target_encoder_forward_
  only + mag_concat RMS-match adaptive ISV.
- 2c.5: docs flip.

No code changes. Plan-doc only.
2026-04-25 11:53:10 +02:00
jgrusewski
c0d3d7b2ff plan(dqn-v2): Plan 4 Task 2 GRN — decomposed into 2a/2b/2c with reality checks
After a first dispatch attempt of monolithic Task 2 (GRN ADOPT) was
correctly refused with a thorough scope assessment, this revision
records the decomposition and the structural facts that drove it:

1. layout_fingerprint_seed() only fingerprints ISV slots, not
   param-tensor layout. The "fingerprint will auto-update" assumption
   in the original Task 2 spec was wrong for param-tensor reshuffles.
2. compute_param_sizes has 86 tensors (docstring saying 42 is stale).
   Inserting GRN's 9 sub-tensors shifts 82 downstream tensors and
   98 padded_byte_offset call sites.
3. At least 12 kernels consume h_s2 expecting ReLU non-negativity.
   GRN's LayerNorm output is zero-mean (signed). Per-consumer
   verification needed before swap.
4. crates/ml-supervised::tft::gated_residual is incompatible as a
   port: different formula (sigmoid gate, not GLU split) and
   incompatible tensor abstraction. New CUDA kernels from scratch.

Decomposition:
- Task 2a (research, no code): audit h_s2 consumers for ReLU vs
  LayerNorm semantics. Output: per-consumer table.
- Task 2b (small, checkpoint break): extend fingerprint seed to
  include param-tensor names + sizes. Pearl-aligned: complete
  fingerprint coverage rather than partial.
- Task 2c (large, checkpoint break): GRN kernels + 98 call-site
  migration + h_s2 consumer shims (per 2a). Blocked on 2a+2b.

Recommended order updated to thread 2a → 2b → 2c. Tasks 1, 6, 3
remain independent of 2c and can land in parallel where useful.
Pearl rules section added documenting the safety constraints
applied throughout the plan.

No code changes. Plan-doc only.
2026-04-25 11:11:13 +02:00
jgrusewski
fab7758916 plan(dqn-v2): Plan 4 full-scope reality reconciliation
Comprehensive revision to match landed Plan 1+2+3 codebase state. Pattern
mirrors the Plan 3 second revision: per-task "Reality reconciliation"
blocks at the top of each task body identifying what's stale vs. landed,
with concrete file paths in the actual cuda_pipeline tree.

Added:
- Task dependency graph with recommended execution order:
  5 (light ISV) → 4 (refactor) → 2 (GRN ADOPT) → 1 (Full VSN) →
  6 (aux heads) → 3 (multi-Q IQN) → 7 (audit) → 8 (Argo)
- Per-task implementation surface with concrete trunk hooks:
  - Task 1: pre-h_s1 VSN gate in batched_forward.rs::forward_online_raw
  - Task 2: GRN audit confirms ADOPT branch (GRN absent from DQN trunk;
    only in ml-supervised TFT). Replaces h_s1/h_s2 Linear blocks.
  - Task 3: re-scoped — IQN already runs num_quantiles=32 with random τ.
    Task is CONSTRAINING to fixed τ ∈ {.05, .25, .5, .75, .95}.
  - Task 4: pure Rust API split (no kernel changes, no checkpoint break)
    around existing forward_online_raw structure
  - Task 5: split into Mode A (light, pre-Task-1, 3 ISV slots) and
    Mode B (full, post-Task-1, 7 ISV slots). Mode A recommended first.
  - Task 6: aux head loss scaled by ISV[LEARNING_HEALTH] per pearl
- Checkpoint-break consolidation note: Tasks 2/1/6/3 each break checkpoint
  compatibility; land in sequence with no Argo run between (one fingerprint
  shift per commit; final Argo at Task 8 amortizes retraining cost)
- Task 8 absorbs Plan 3's deferred Argo Tier 1 gate (combined validation)

No code changes.
2026-04-25 09:30:09 +02:00
jgrusewski
3bfbcd7137 plan(dqn-v2): Plan 4 reality reconciliation
Plan 4 was drafted 2026-04-24 against an earlier Plan 3 design. After
Plan 3 landed (commits 44539d8f4..3cb083f18), the pre-plan gate
referenced slot names that don't exist in the landed implementation:

- PLAN_PARAMS_0_EMA_INDEX → became READINESS_EMA_INDEX (Task 4)
- STATE_KL_THRESHOLD_EMA_INDEX → eliminated; Task 7 uses kernel-internal
  trailing-EMA-of-self pattern (no separate threshold slot)
- TEMPORAL_REWARD_{PERSIST,REGIME_SHIFT,CONSISTENCY}_EMA_INDEX → consolidated
  into rc[5] → ISV[68] REWARD_BONUS_EMA_INDEX via Plan 3 Task 6a/6b/6c

Updated:
- Pre-plan slot-existence check matches landed slot names
- Validation-doc gate softened: Plan 3 Argo Tier 1 PASS becomes OPTIONAL;
  local 5-epoch multi-fold smoke is the de-facto gate (user choice
  to proceed without burning Argo cycles)
- Status table at top shows landed Plan 3 baseline (ISV_TOTAL_DIM=87,
  PS_STRIDE=43, fingerprint at [85,86]) and per-task difficulty estimate
- Reality-reconciliation note documents the rename trail

No task body changes; subsequent commits will revise individual task
specs as they become next-up for execution.
2026-04-25 09:21:36 +02:00
jgrusewski
e1626876af plan(dqn-v2): mark Tasks 8+9 LANDED; 11/12 done 2026-04-25 09:15:43 +02:00
jgrusewski
0c48dc7192 plan(dqn-v2): mark Task 7 LANDED 2026-04-25 02:26:39 +02:00
jgrusewski
aa8e6f8ec1 plan(dqn-v2): mark Task 4 LANDED 2026-04-25 01:36:24 +02:00
jgrusewski
3af2c79def plan(dqn-v2): mark Task 6c LANDED 2026-04-25 01:11:04 +02:00
jgrusewski
efb4e529a4 plan(dqn-v2): mark Task 6a, 6b LANDED with iteration history 2026-04-25 00:51:10 +02:00
jgrusewski
87b52ea946 plan(dqn-v2): Plan 3 second revision — reconcile with landed reality
Tasks 1, 2, 3, 5 landed on main between a59e7599c and a0abc3da3. The
remaining Task 4/6/7/8/9 bodies in the plan had accumulated drift:

- Task 4: allocated slot 49 (already PLAN_THRESHOLD_INDEX); EMA'd
  plan_params[0] (kernel compares against readiness).
- Task 6: allocated 59/60/61 (now collides with Plan 2 Q-quantile
  [50..58) and Task 1 reward EMAs [63..69)); required 6 new PS memo
  fields and included tuned 0.5e-4f penalty.
- Task 7: allocated 58/63/64 (63/64 collide with REWARD_TRAIL_EMA /
  REWARD_MICRO_EMA from Task 1); amplification formula had tuned
  2.0× trigger, 0.02 decay, 1.0/2.0 endpoints.
- Task 8: referenced trainer helpers that don't exist
  (sample_state_feature_pair, step_scripted, replay_insert_with_
  priority_scale); tuned priority_scale=0.5.
- Task 9: used pre-pivot CPU-compute AdaptiveMonitor pattern with
  tuned 0.9/0.1 EMA rates.

This revision:
- Adds per-task "Reality reconciliation" sub-header flagging the
  stale premise being fixed.
- Marks landed tasks with  LANDED <SHA> and records actual outcomes
  (vs. the planned outcomes the original text described).
- Rewrites Task 4/6/7/8/9 bodies to use tail-append slot allocation
  (indices recomputed from ISV_TOTAL_DIM at impl time), GPU kernel
  producer + read-only AdaptiveMonitor consumer pattern, and
  ISV-derived adaptive coefficients in place of tuned constants.
- Splits Task 6 into 6a/6b/6c with independent PS-slot additions
  (MIN_PNL / REGIME_SHIFT_BAR / PRE_ENTRY_CONVICTION_EMAs).
- Enumerates concrete trainer-helper prereqs for Task 8.
- Updates Task 10 metric bands to match actual landed ISV slot names.
- Updates exit criteria summary to check off what landed.

No code changes.
2026-04-24 23:48:07 +02:00
jgrusewski
a59e7599c8 plan(dqn-v2): Plan 3 revision — GPU-drives-CPU-reads, ISV tail-append, AdaptiveMonitor
Aligns Plan 3 with post-Plan-2 reality:

1. AdaptiveController → AdaptiveMonitor throughout (spec §4.C.6
   2026-04-24 revision). Tasks 4 (plan-threshold) and 9 (cql_alpha
   seed-coupled) become GPU kernel + read-only CPU monitor pairs
   instead of CPU-compute controllers — uniform with Plan 1's
   tau/epsilon/gamma/kelly_cap and Plan 2's per-branch γ pattern.

2. Stale ISV slot indices [49..65) replaced with tail-append language.
   Current post-Plan-2 ISV_TOTAL_DIM = 63; new slots start at 63 and
   grow. Fingerprint at 61-62 auto-re-tails.

3. Architecture paragraph updated to document replay-seed orchestration
   (Task 8 dqn_replay_seed.rs) as constructor-time cold-path pre-training
   — not a GPU-drives violation.

4. Prerequisites section clarified: Plan 2 state — ISV_TOTAL_DIM 63,
   TLOB at SL_TLOB_START, layout fingerprint auto-recomputes.

No scope changes to individual Tasks 1-10. Just terminology + slot
indexing aligned with current main state.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 21:46:38 +02:00
jgrusewski
79b7d3fc8b plan(dqn-v2): Plan 2 revision — GPU-drives architecture + Mamba2 validation scope
Revises Plan 2 to match the post-Plan-1 reality:

1. AdaptiveController → AdaptiveMonitor throughout (read-only observers
   per spec §4.C.6 2026-04-24 revision; GPU kernels compute, CPU reads).
   Applies to Task 3 (per-branch gamma) and Task 5 (liquid_mod audit).

2. Task 2 (D.1 Mamba2 backward) scope narrowed from "implement" to
   "validate existing". Plan 1 A.5 audit confirmed
   mamba2_scan_projected_bwd kernel + mamba2_backward host call are
   already fully wired. Task 2 now adds a finite-difference grad-check
   smoke + non-zero grad-propagation smoke; escalates if either fails.

3. Task 3 (D.2 per-branch gamma) rewritten for GPU-drives compliance:
   - Replace scalar GAMMA_EFF_INDEX=43 with 4 per-branch slots at
     43-46 (DIR/MAG/ORD/URG).
   - New per_branch_gamma_update_kernel.cu reads v-range + health,
     writes 4 slots. Deletes the Plan 1 gamma_update_kernel.cu.
   - 4 read-only monitors (or one consolidated PerBranchGammaMonitor).
   - ISV slots 44-48 shift downstream; fingerprint re-tails at 50-51;
     ISV_TOTAL_DIM grows 49 → 52.
   - c51_loss_kernel and iql_value_kernel read per-branch γ from ISV.
   - No CPU-side γ computation anywhere.

4. Header architecture block updated: new ISV slot count target,
   GPU-drives principle explicit, current Plan-1 layout table inline
   for reference.

5. Pre-plan verification updated: expects AdaptiveMonitor trait (not
   AdaptiveController); checks for 6 Plan-1 monitor files.

6. Removed "schema version bump 1 → 2" language — layout fingerprint
   auto-recomputes from seed bytes; no integer version space exists.

Task 4 (D.5 soft fold transitions), Task 5 content (D.7 liquid audit),
Task 6 (D.3+D.6+D.8 coordinated state-layout migration), Task 7
(validation run) structure preserved. Internal slot numbers in those
tasks will reconcile to the new layout when they land (no pre-emptive
edits since those indices depend on whether Task 1 quantile slots or
Task 3 per-branch gamma slots land first — re-compute at exec time).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 19:04:56 +02:00
jgrusewski
d7f1b9e9ae plan(dqn-v2): Plan 1 substrate + refactor complete (Tasks 9-17)
Appends Plan 1 completion note to the substrate plan doc, recording
all 10 commit SHAs from Tasks 8-17 and the exit criteria status.
Tasks 8-17 fully implemented: AdaptiveMonitor trait, 6 CPU-side read-only
monitors (atoms, gamma, kelly_cap, tau, epsilon, grad_balancer), 5 cold-path
GPU kernels (atoms_update, gamma_update, kelly_cap_update, tau_update,
epsilon_update), 3 static ISV constructor writes (cql_alpha, conviction_floor,
plan_threshold). All adaptive computation is now GPU-driven; CPU never
computes adaptive values (§4.C.6). Tasks 18.1-18.7 (validation run) pending.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 18:29:34 +02:00
jgrusewski
cf36091eeb spec+plan(dqn-v2): GPU drives, CPU reads (§4.C.6 revision)
User raised that the CPU-controller pattern (where CPU computes adaptive
values from ISV and writes back to ISV) violates the architectural
principle: GPU kernels should compute adaptive decisions; CPU-side code
is pure observation.

Replaces the AdaptiveController trait with read-only AdaptiveMonitor:
- No update() — CPU doesn't compute adaptive values.
- No write_output() — CPU doesn't write adaptive values to ISV.
- read() returns the GPU-computed value from ISV.
- diagnose() emits HEALTH_DIAG snapshot.
- observe() + fire_rate() track how often the GPU-computed value changes.

Reclassifies the 9 adaptive mechanisms:
- 6 reactive get GPU kernel + CPU monitor: atoms, gamma, kelly_cap, tau
  (Polyak EMA), epsilon, grad_balancer (last is already GPU-driven).
- 3 static get ISV constructor-write, no monitor: cql_alpha,
  conviction_floor, plan_threshold.

New ISV slots for GPU-written adaptive outputs (EPSILON_EFF, TAU_EFF,
GAMMA_EFF, KELLY_CAP_EFF) and CPU-born inputs (EPOCH_IDX, TOTAL_EPOCHS),
plus slots for the 3 static configs.

Rationale:
- Unified adaptive machinery, no CPU-side special cases.
- Per-sample granularity available (Expected SARSA τ in c51_loss_kernel
  is already the exemplar — reads ISV q_gap + health per sample).
- Zero CPU→GPU config transfer in any path.
- ISV is single source of truth for every adaptive value.

Plan 1 Tasks 8-17 restructured:
- Task 8 creates AdaptiveMonitor trait (not AdaptiveController).
- Tasks 9, 10, 11, 13, 14, 17: GPU kernel + monitor pairs.
- Tasks 12, 15, 16: static ISV writes only.

Follow-up commits will revert Batch A (d76849f31) and Batch B (4189da563)
which implemented the old CPU-compute pattern, then re-implement under
this design.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 16:20:24 +02:00
jgrusewski
fb6d0f40f9 audit(dqn-v2): A.5 orphan audit complete
Populated docs/dqn-wire-up-audit.md with every pub module and CUDA
kernel in the DQN path. Each entry classified Wired / Partial / Orphan /
Ghost / OUT-of-DQN-scope with the action plan linking to the plan+task
that resolves any non-Wired status.

No Orphan left unclassified. Orphans fall into three buckets:
1. Scheduled for wiring by a later Plan (gpu_statistics → Plan 2 D.2;
   tlob_loader → Plan 2 D.8).
2. OUT-of-DQN-scope because supervised consumers exist (PPO kernels,
   xLSTM, KAN trainable adapter, flash_attention, benchmarks).
3. Genuinely unused — escalated to user review in the task output,
   not deleted autonomously (streaming_dbn_loader, unified_data_loader,
   training/orchestrator, training_pipeline, inference_validator,
   model_loader_integration, paper_trading/mod.rs,
   portfolio_transformer, regime_detection/mod.rs).

Summary: 109 total modules/kernels, 74 wired, 7 partial, 11 orphan,
0 ghost, 17 OUT-of-DQN-scope.

Plan 1 Task 6. Spec §4.A.5, Invariant 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 13:10:49 +02:00
jgrusewski
1353e71ae6 spec+plan(dqn-v2): layout fingerprint replaces schema version (§4.A.2)
User raised a backward-compat concern: integer "schema version"
semantically implies a family of coexisting versions with upgrade
paths between them, inviting the forbidden pattern
(feedback_no_legacy_aliases.md, feedback_no_partial_refactor.md).

Replace with a compile-time structural fingerprint:
- ISV[0..2) stores a u64 FNV-1a hash of the slot layout (split across
  two f32 lanes preserving raw bits).
- The hash is computed by a const fn over the slot list; any slot
  change automatically updates the fingerprint. No human decides
  "what version is this now".
- Checkpoint load is fail-fast only. Error message does NOT mention
  migration as an option.
- Pre-commit hook rejects any `fn migrate_isv|upgrade_isv` to make
  the no-migration rule structurally enforced (landed as part of
  Plan 1 Task 5 hook extension).
- StateResetRegistry entry renamed ISV_SCHEMA_VERSION →
  ISV_LAYOUT_FINGERPRINT (Task 2's landed code touched in Task 5's
  commit per no-partial-refactor).

Updated:
- spec §4.A.2 (fingerprint design + rationale)
- spec §5 landing-order note (fingerprint auto-updates on layout change)
- Plan 1 architecture line
- Plan 1 Task 2 StateResetRegistry test + entry naming
- Plan 1 Task 5 — full rewrite of implementation steps
- Plan 1 exit criteria #6
- Plan 2 pre-plan verification (grep fingerprint constants, not version==0)
- Plan 2 Task 6D.1 (update fingerprint seed, not bump version)
- Plan 2 Task 6D exit criteria #7
- Plan 3 pre-plan verification
- docs/isv-slots.md ISV[0..2) row

No code changed. Plan 1 Task 5 is not yet implemented — this commit
realigns the spec + plans so the implementer subagent works from the
corrected design.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 11:47:07 +02:00
jgrusewski
3ab87d7672 plan(dqn-v2): Plan 3 self-review fix — remove unimplemented!() from example
Self-review caught that the CqlAlphaSeedCoupledController read_signals
example used unimplemented!("plumbed by caller"), which violates the very
Invariant 9 the plan enforces. Replaced with a concrete implementation
that reads SEED_FRACTION_EMA_INDEX from the ISV bus (a Plan 1 reserved
controller-signal slot).

No other plan had placeholder violations. The remaining TBD/TODO/FIXME
grep hits across Plans 1-5 are either the pre-commit hook's rejection
patterns (correctly quoted) or enforcement scans that DETECT the markers
in audit docs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 10:07:10 +02:00
jgrusewski
74071af908 plan(dqn-v2): Plan 5 — validation substrate + final pass implementation plan
Fifth and final plan decomposing the DQN v2 unified spec
(docs/superpowers/specs/2026-04-24-dqn-v2-unified-design.md §2, §4.A.3,
§4.A.4, §4.A.4.1). No new policy mechanisms — orchestration, automation,
regression detection, and the final sign-off run.

Covers spec sections:
- §4.A.3 Multi-seed × multi-fold Argo harness (N=5, K=6 defaults via
  --multi-seed / --folds flags on argo-train.sh)
- §4.A.4 Regression detection hard-stop (2N consecutive error-band
  metrics → self-SIGTERM with TerminationReason)
- §4.A.4.1 nsys profile harness with --profile flag and
  compare-nsys-profiles.py for 20% per-epoch regression detection
- §2 Tier 1 + Tier 2 + Tier 3 final exit criteria via scripts/validation/
  suite (tiered tier1/tier2/tier3 check scripts + wrapper)
- §2 DQN v2 rollout close-out (spec marked LANDED, retrospective,
  plan-level validation docs archived)

Plan structure: 6 tasks — 4 infrastructure (harness, regression-detect,
nsys, validation-scripts) + final-run task + rollout-closeout task. The
final-run task is the sole exit-gate for the DQN v2 rollout: ALL THREE
tiers must PASS on the first final-validation run (per stop-on-anomaly:
retrying with different seeds hoping for a different outcome is anti-
pattern).

Preserves all 9 invariants. Every mechanism wired, no stubs, no TODO/FIXME.
Retrospective written from actual implementation experience after Plans
1-5 all land.

This is the terminal plan. Plans 1-5 together constitute the complete
DQN v2 rollout. After Plan 5's final-run exit passes, the spec is marked
LANDED and the rollout is declared complete.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 10:06:25 +02:00
jgrusewski
691d769bb3 plan(dqn-v2): Plan 4 — supervised→DQN concept adoption implementation plan
Fourth of five sequential plans decomposing the DQN v2 unified spec
(docs/superpowers/specs/2026-04-24-dqn-v2-unified-design.md §4.E).

Covers the six Part E IN decisions:
- §4.E.1 TFT Variable Selection Network across 6 feature groups
  (market/OFI/TLOB/MTF/portfolio/plan_isv) with vsn_feature_selection kernel
- §4.E.2 Gated Residual Network — CONDITIONAL branch (ADOPT vs CANONICALISE)
  based on docs/ml-supervised-to-dqn-concept-audit.md row
- §4.E.3 Multi-quantile IQN heads (5/25/50/75/95) replacing single CVaR output
- §4.E.4 Encoder-Decoder separation — explicit StateEncoder + per-branch
  ValueDecoder with D.3 horizon-decomposed V_short/V_long sub-heads
- §4.E.5 Attention-weight interpretability — 7 new ISV slots [65..72) for
  per-group attention focus EMAs + Mamba2 retention proxy
- §4.E.6 Multi-task auxiliary heads — next-bar return MSE + 5-bar regime CE,
  ISV-coupled aux-weight schedule (sharpe-reactive)

ISV_TOTAL_DIM seals at 72 with this plan's allocations. Part E audit doc
closes out all rows (zero TBD/evaluate remain per Invariant 9).

Plan structure: 8 tasks (6 feature tasks + audit close-out + validation).
TDD-disciplined steps. Task 2 documents the CONDITIONAL branch decision
pathway explicitly (ADOPT vs CANONICALISE Branch A/B structure).

Plan 4 exit gate: Tier 1 convergence RETAINED (no regression vs Plan 3
baseline) + aux heads produce measurable signal. Tier 2 + Tier 3 checked
by Plan 5.

Preserves all 9 invariants. Zero stubs. Zero TODO/FIXME. Every Part E item
either lands fully or is explicit OUT (xLSTM, KAN); no third path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 10:03:13 +02:00
jgrusewski
c70bbd5d15 plan(dqn-v2): Plan 3 — behavioural core implementation plan
Third of five sequential plans decomposing the DQN v2 unified spec
(docs/superpowers/specs/2026-04-24-dqn-v2-unified-design.md).

Covers spec sections:
- §4.C.2 Reward-component attribution (6 ISV slots [52..58), reward_split[..]
  in HEALTH_DIAG) — lands first as diagnostic substrate for the rest
- §4.B.1 ISV-driven continuous Flat opp-cost (scales by isv[Q_DIR_ABS_REF])
- §4.B.2 Novelty-weighted trade-attempt bonus (2 ISV slots [50, 51])
- §4.B.4 Adaptive plan-MLP activation threshold (1 ISV slot [49] +
  PlanMlpThresholdController via the AdaptiveController trait)
- §4.C.4 Temporal timing bonus (trade-exit, bars_early / hold_time)
- §4.D.4 Generalised temporal reward coupling (3 ISV slots [59..62):
  persistence credit, regime-shift penalty, conviction consistency)
- §4.C.3 State-distribution divergence signal (3 ISV slots [58, 63, 64])
- §4.B.3 Replay buffer seeded warm-start (4 scripted policies,
  ≥100K experiences, CQL α decoupled from seed phase)
- §4.C.5 CQL alpha schedule coupled to seed-phase decay via
  CqlAlphaSeedCoupledController

Plan structure: 9 implementation tasks + pre-plan verification + exit-gate
validation task (Task 10). Each task TDD-disciplined with bite-sized
steps. Task 1 (C.2 diagnostic audit) ordered first so subsequent
reward-shape tasks can verify contributions rather than log-archaeology.

Plan 3 exit gate: multi-seed (N=5) × multi-fold (K=6) run passes Tier 1
(convergence) + Tier 2 behavioural subset (val trades/bar ≥ 0.005,
val_active_frac > 0.2). Tier 3 profitability deferred to Plan 5.

Preserves all 9 invariants. Zero stubs. Zero TODO/FIXME. Every new module
wired to its consumer in the same task it lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 09:59:32 +02:00
jgrusewski
a5101eb2f8 plan(dqn-v2): Plan 2 — temporal core implementation plan
Second of five sequential plans decomposing the DQN v2 unified spec
(docs/superpowers/specs/2026-04-24-dqn-v2-unified-design.md).

Covers spec sections:
- §4.C.1 Quantile-based atom support (8 new ISV slots, q_quantile_reduce kernel)
- §4.D.1 Mamba2 backward pipeline completion (no atomicAdd — per-sample arrays + host reduce)
- §4.D.2 Per-branch gamma via AdaptiveController (4 new ISV slots)
- §4.D.5 Soft fold-boundary transitions (extends StateResetRegistry with SoftReset category)
- §4.D.7 Liquid Time-constant audit (trace fire rate, decide wire-or-delete)
- §4.D.3 + §4.D.6 + §4.D.8 coordinated state-layout migration (horizon-decomposed V +
  plan_isv[6] + TLOB integration with atomic ISV schema version bump 1→2)

Plan structure: 7 tasks + pre-plan verification, all TDD-disciplined with
bite-sized steps (test → fail → implement → pass → commit). Task 6 is
explicitly atomic to preserve Invariant 5 (state-layout consistency).

Plan 2 prerequisites: Plan 1 landed (StateResetRegistry, AdaptiveController
trait, ISV schema version, audit docs). Plan 2 exit: all 9 invariants
preserved; convergence-scaffolding run passes with 16 new ISV slots
populated; ISV schema version == 2.

Preserves all 9 invariants. No stubs. No TODO/FIXME. Every new module
wired to production path in the same task it lands in.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 09:53:11 +02:00
jgrusewski
e5f6afca8d plan(dqn-v2): Plan 1 — substrate & refactor implementation plan
First of 5 implementation plans for the DQN v2 unified integrated
policy system spec (d13b53586, 336ee40b9). Plan 1 covers:

  Task 1: Audit doc scaffolding + pre-commit hook (Invariant 7, 9)
  Task 2: StateResetRegistry definition (A.1)
  Task 3: Wire StateResetRegistry into fold-boundary reset (A.1)
  Task 4: Named-dimension refactor — ps[], plan_isv[], plan_params[],
          branch indices, dir/mag sub-indices (Invariant 8)
  Task 5: ISV schema version at ISV[0], fail-fast on checkpoint
          mismatch (A.2)
  Task 6: Orphan audit populated (A.5)
  Task 7: Hot-path purity audit populated; MIGRATE calls fixed (A.6)
  Task 8: AdaptiveController trait + harness (C.6)
  Tasks 9–17: Migrate each adaptive controller to the trait in spec-
            specified order (atoms → gamma → Kelly → cql_alpha → tau
            → epsilon → conviction_floor → plan_threshold → balancer)
  Task 18: Plan 1 validation run (smoke + 3-epoch L40S)

Plan 1 landing criteria: all 9 invariants preserved across every
commit, all smoke tests pass, audit docs fully populated. Plan 2
(temporal core) starts only after Plan 1 passes exit criteria.

Plans 2–5 cover Parts B, C (minus C.6 already in Plan 1), D, E, and
final validation. Planned as separate documents in docs/superpowers/
plans/2026-04-24-dqn-v2-plan-{2..5}-*.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 09:41:22 +02:00
jgrusewski
d1068de2b8 plan(policy-quality): reframe DELETE tasks per no-functionality-removal rule
User directive: "we don't remove functionality at all, we fix what's
broken". Standing rule captured in
~/.claude/projects/-home-jgrusewski-Work-foxhunt/memory/feedback_no_functionality_removal.md.

Phase 2 plan reframed:
  * Task 2.3 (R5 micro-reward): was DELETE; now FIX — either (a) set a
    non-zero scale that delivers real signal, or (b) document why it's
    intentionally disabled while preserving the code path.
  * Task 2.4 (R6 loss-aversion): unchanged — the relocation to C51
    Bellman target is consolidation, not removal. Invariant preserved.
  * Task 2.6 (E4 entropy-reg): was DELETE-CANDIDATE; now TUNE — if the
    signal doesn't reach magnitude, re-route it rather than remove.
  * Task 2.7 (C4 grad-clip): was DELETE-CANDIDATE; now
    KEEP-AND-DOCUMENT — gradient clipping is a safety feature; run the
    ablation for diagnostic, not for removal.
  * H9 delete-magnitude-branch fallback: rejected permanently. On
    magnitude convergence failure the fallback is per-magnitude reward
    shaping / per-bin advantage weighting / curriculum / state enrichment.

Task 2.5 wiring-bug sweep unchanged (correctness fixes, not removal).

This commit updates only the planning narrative. Task execution hasn't
started on 2.3/2.6/2.7 yet, so no code changes required here. When
those tasks run, they will implement the fix-paths, not the
delete-paths.
2026-04-22 11:18:28 +02:00
jgrusewski
7e78bf4f85 plan(policy-quality): Phase 2 pivot — H4 REJECTED by Task 2.0 data
Task 2.0 instrumentation (commits d60e5375a / 980f3b07f / 41b0c559c)
revealed two silent bugs in Task 0.4's grad_ratio_mag_dir accessor:

  Bug A — readback size mismatch: pinned buffer allocated at
  total_params, but grad_buf length is total_params+cutlass_tile_pad,
  so size check always failed → Err silently coerced to 0.0 by proxy.

  Bug B — readback timing wipe: estimate_avg_q_value_with_early_stopping
  in process_epoch_boundary replays the forward graph, which zeros
  grad_buf. Any subsequent readback sees all zeros.

Both fixed in 41b0c559c; snapshot hoisted to top of process_epoch_boundary.

With those bugs fixed, the measured gradient ratio is NOT 0.0000 — it is
50–400× mag/dir across 60 epochs. Magnitude branch is over-fed, not
starved. Direction gradient is small but non-zero (~2e-2 to 7e0).
Direction policy is observably healthy (Short/Hold/Long/Flat 38/12/42/14%).

Track 1 triage's H4 CONFIRMED verdict was a measurement artefact
produced by Bugs A+B. H4 as originally defined is now REJECTED.

Plan changes:
  - Add new "Task 2.0 findings" section after cross-cutting concerns,
    documenting bug A, bug B, observed data, and revised strategy.
  - Task 2.1 marked DEFERRED (not deleted — kept for reference).
  - Task 2.2 promoted to PRIMARY fix.
  - New fallback: H9 delete-magnitude-branch as replacement for Task 2.1
    if Task 2.2 alone is insufficient.
  - Task 2.0 inventory row updated with LANDED status and commit chain.

Net effect: Phase 2 simplifies. The hardest task (2.1 three-branch
architectural fix) is skipped; primary path is Task 2.2 (~25 LOC).
2026-04-22 11:13:48 +02:00
jgrusewski
5a4d561451 plan(policy-quality): Task 2.0 revised approach — in-graph pinned snapshots
First Task 2.0 dispatch escalated BLOCKED: the four loss-component
backward kernels are captured inside the fused training graph, so
host-side snapshot-between-components isn't possible mid-graph without
a force-ungraphed diagnostic step (~210 LOC + cross-stream sync risk).

Revised approach (chosen after cost analysis):

  cudaMemcpyAsync(device → pinned host) IS captureable in a CUDA graph.
  Even better: DtoD into per-component scratch buffers, then an in-graph
  reduction kernel computes per-component (mag_norm, dir_norm) and writes
  8 floats to a pinned result slot. Only the 8-float result crosses
  PCIe (at epoch boundary), keeping per-step PCIe traffic to zero.

Changes to the plan's Step 2 + Step 3 + Step 4:
  - Step 2: added 4 device-side scratch buffers (one per component,
    ~10 MB each = 40 MB device) + 8-float pinned result slot + new
    reduction kernel grad_decomp_kernel.cu spec'd out.
  - Step 3: clarified that DtoD snapshot + backward + reduction kernel
    are ALL captured in the graph; graph replays them every step;
    no force-ungraphed dance needed.
  - Step 4: added refresh_grad_component_norms() accessor that reads
    the 8-float pinned slot at epoch boundary (zero-copy) and populates
    the host-side cache.

Approach matches Task 0.4 pattern (commit bb42c9963) extended four-fold.
No atomicAdd (reduction uses shared-mem tree), no non-captured replay,
no cross-stream sync risk.

LOC estimate: ~90 (was ~210 for the rejected option).
2026-04-22 09:46:17 +02:00
jgrusewski
2a54edc92d plan(policy-quality): Phase 2 plan refinements (tolerance bands + decision tables)
Three polish items from the plan review:

1. Task 2.4 Step 5 — replaced vague "must not regress" with a numeric
   tolerance-band table: multi_fold best_val_metric ±15% per fold,
   Best Sharpe ≥ 20 floor, and hard F_Half/F_Full ≥ 0.05 + cf_flip ≥ 0.1
   BLOCKERS. Anchors to the baseline metrics doc values captured at
   policy-quality-baseline.

2. Task 2.6 — converted the ad-hoc text decision at Step 1 into the same
   five-row decision table format Task 2.1 uses (DELETE / KEEP / KEEP-as-
   safety-net / INCONCLUSIVE / DELETE-because-inseparable). Step 2
   ablation got its own 4-row outcome table keyed to ent_mag delta,
   multi-fold Sharpe regression, and NaN appearance.

3. Task 2.7 Step 1 — added "Repeat 3× with different seeds" clause and
   explicit total wall-clock note: ~75 min (3 × 25 min) for the ablation
   pass before the Step 2 decision. Aligns with the Cross-cutting concern
   #6 about sample-noise rejection.

No task count change (still 11: 2.0–2.10). Net code-delta estimate
unchanged. Standing-rule compliance unchanged (no stubs / no atomics
/ no quickfixes / no hiding / no feature flags / no push-per-task).
2026-04-22 09:29:16 +02:00
jgrusewski
1ce99efc53 plan(policy-quality): Phase 2 implementation — synthesis of 4 tracks
Consolidates Phase 1 triage findings from Tracks 1-4 into an 11-task
Phase 2 plan at docs/superpowers/plans/2026-04-21-policy-quality-phase2.md.

Task inventory:
  - 2.0  Per-component gradient decomposition (H4 keystone diagnostic)
  - 2.1  H4 fix — magnitude-head gradient starvation (decision tree from 2.0)
  - 2.2  H10 fix — stable argmax tie-break at eval
  - 2.3  DELETE R5 micro-reward
  - 2.4  DELETE R6 loss-aversion; relocate neg-tail to C51 target smoothing
  - 2.5  Wiring-bug sweep (7 bugs: C1 fire, epsilon gen_range, if !true,
         sigma_mean scale, fold-boundary reset, stale docstring, C5 ISV null)
  - 2.6  E4 entropy-reg DELETE-or-KEEP (data-driven, post-2.0)
  - 2.7  C4 adaptive grad-clip ablation + DELETE-or-KEEP
  - 2.8  L40S validation run — all 4 tracks re-measured
  - 2.9  Mandatory-gate verification + phase3-results.md
  - 2.10 Tag policy-quality-phase2-complete (and policy-quality-v1 if soft pass)

Matches Phase 0/1 plan formatting (checkbox steps, concrete file paths,
code snippets, bash commands, per-task commit templates). References
project standing rules (no quickfixes, no stubs, no atomic-adds on hot
paths, no feature flags, no hiding errors) and the pinned-readback
pattern from Task 0.4 (commit bb42c9963).
2026-04-22 09:23:52 +02:00
jgrusewski
944fecd913 docs(policy-quality): main-branch workflow — cut feat/wip branches
User preference: everything lands on main, ~500 LOC is small enough
that feature-branch isolation isn't needed.

Spec changes:
  * §2.3 outcome paths: drop "unmerged branch" vocabulary
  * §3 architecture: main-branch timeline, no feat/, no wip/
  * §4 Phase 0: commits on main, tag policy-quality-baseline at end
  * §5 Phase 1: experiments are worktree edits reverted after, only
    triage docs commit (to main)
  * §6 Phase 2: commits land on main, author chooses granularity,
    each leaves smokes green
  * §7.3 outcome handling: iterate on main, baseline tag for rollback
  * §7.4 closing: tag policy-quality-v1, update status

Plan changes:
  * Task 0.1: verify-starting-state (not branch creation)
  * Task 1.x: temp-edit-then-revert (not wip branches)
  * Task 1.5: triage docs commit directly to main
  * Phase 4: tag + close (not merge + cleanup)
  * Rollback: one git reset --hard command
2026-04-21 21:06:33 +02:00
jgrusewski
1456094a5a plan(policy-quality): implementation plan for 4-track V7 audit
Produced by superpowers:writing-plans from the approved spec at
docs/superpowers/specs/2026-04-21-policy-quality-design.md.

Plan structure:
  * Phase 0 (tasks 0.1-0.17): measurement substrate — TDD-detailed,
    exact code + commands. Produces 6 new smoke tests + ~25 HEALTH_DIAG
    fields across 4 tracks.
  * Phase 1 (tasks 1.0-1.5): parallel investigation tracks — process
    tasks (run instrumentation, record evidence, classify hypotheses).
    No code to pre-write; output is 4 triage documents + a Phase-2
    planning doc.
  * Phase 2 (template only): convergence fix. Concrete tasks produced
    by a Phase-2-specific plan AFTER Phase 1 triage — can't pre-write
    the fixes without knowing which hypotheses confirm.
  * Phase 3 (tasks 3.1-3.4): L40S validation gates, surrogate-noise,
    branch decision (merge or iterate).
  * Phase 4 (tasks 4.1-4.4): merge via --no-ff, tag, cleanup.
  * Rollback procedure: git reset --hard policy-quality-baseline.
2026-04-21 20:56:45 +02:00
jgrusewski
ab7567875a plan: adaptive learning dynamics — 19 tasks across 5 phases
Implementation plan for unified LearningHealth system (all gems/pearls/novels):
- Phase A (A1-A4): ISV extension, LearningHealth module, training loop wiring,
  HEALTH_DIAG logging
- Phase B (B1-B4): G2 uncertainty-gated CQL, G3 health-coupled tau,
  G4 temp-continuous Expected SARSA, G5 adaptive gradient budget
- Phase C (C1-C4): P1 health-weighted PER priorities, P2/P3 subsumed by A3,
  P4 temporal-coupled gamma
- Phase D (D1-D8): N1 temporal self-distillation, N2 Q-gap barrier,
  N3 health-triggered plasticity, N4 CF curriculum, N5 information bottleneck,
  N6 ensemble oracle, N7 contrarian override, N8 meta-Q collapse predictor
- Phase E (E1-E2): collapse-recovery smoke test + L40S deployment verification

Spec: docs/superpowers/specs/2026-04-20-adaptive-learning-dynamics-design.md
Target: WinRate >55% by epoch 20, Q-gap stays above 0.1 (no collapse).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 19:12:41 +02:00
jgrusewski
bc8fde9a2b plan: unified state layout implementation — 8 tasks
Task 1: Rust constants (ml-core/state_layout.rs)
Task 2: CUDA header (state_layout.cuh + assemble_state())
Task 3: Refactor experience_state_gather to use shared assembly
Task 4: Delete backtest_gather_kernel, replace with shared function
Task 5: Remove configurable state_dim everywhere (131 call sites)
Task 6: Update OFI_DIAG indices + checkpoint validation
Task 7: Layout match integration test
Task 8: Deploy and verify on H100

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 14:36:03 +02:00
jgrusewski
063fd27166 feat: target_dim 4→6 + spec v5 with pearls (bar duration, book CoM, retrospective hold)
target_dim expansion: adds raw_open (OHLCV) and mid_price_open
(MBP-10 midpoint at bar formation) to fxcache targets. FXCACHE_VERSION
2→3 for auto-rebuild. Legacy v2 files handled with close-price fallback.

Spec v5 adds 3 pearls:
- Bar duration encoding in Mamba2 (continuous-time SSM awareness)
- Order book center of mass from all 10 MBP-10 levels (aggression signal)
- Retrospective hold quality bonus (teaches exit timing)

Plus: Hold action (4th direction), DSR Sharpe EMA fix, counterfactual
magnitude/order sign fix, MFT mid-price mark-to-market.

OFI embed MLP now 18→10 (was 16→8). Mamba2 width SH2+10 (was SH2+8).
Attention width D+10 (was D+8).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 23:47:04 +02:00
jgrusewski
f7cf02f363 plan: OFI momentum + dense micro-reward — 9 tasks, full gradient flow
9-task implementation plan covering:
- fxcache target_dim 4→6 (raw_open + mid_price_open from MBP-10)
- OFI data pipeline fix (ofi_gpu wiring, indices 42→66, PORTFOLIO_STRIDE 30→38)
- Dense micro-reward (OFI momentum × price confirm × adaptive cost tolerance)
- OFI embed MLP (16→8 cuBLAS) with full backward gradient flow
- Mamba2 history enrichment (SH2→SH2+8) + d_h_history backward
- Attention enrichment (D→D+8) + d_input_scratch exposure

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 23:21:24 +02:00
jgrusewski
d751d2ad4f plan: kernel optimization — 8 tasks, 7 kernels → cuBLAS + batch-parallel
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 12:15:04 +02:00
jgrusewski
4f7b1f4804 plan: true single-graph — 7 tasks, zero CPU on hot path
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 00:06:05 +02:00
jgrusewski
c054b4e1d8 plan: unified single-graph — 5 tasks, zero ungraphed kernel launches
Task 1: CUfunction audit (map every kernel to its child graph)
Task 2: Expose submit methods (post_aux + maintenance + prev_grad_buf)
Task 3: Add new child graphs (capture + launch 7 children)
Task 4: Verify remaining outside-graph code is kernel-free
Task 5: Deploy and validate (target: adam ~30ms, epoch ~64s)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 21:26:40 +02:00
jgrusewski
f851119e2d plan: Phase 2 multi-stream parallelism — 7 tasks
Task 1: Allocate aux streams + workspaces + events
Task 2: IQN/Attention accept workspace+stream override
Task 3: Fork-join in submit_aux_ops (IQN+Attention parallel)
Task 4: Switch capture mode GLOBAL → RELAXED
Task 5: Forward backward branch parallelism
Task 6: Fix adam child event timing (verify)
Task 7: Deploy + verify child graph breakdown

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 16:07:06 +02:00
jgrusewski
45d8f4661c plan: rewrite Task 9 for child graph architecture
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 23:58:32 +02:00
jgrusewski
750b228ed9 plan: Trade Plan Head — 5 tasks, hierarchical plan-based trading
Task 1: PORTFOLIO_STRIDE 23→30, plan slots ps[23-29]
Task 2: trade_plan_forward kernel + 4 weight tensors (82→86)
Task 3: Plan activation + enforcement in env_step
Task 4: Direction lock in action_select + counter-plan Q (N14)
Task 5: Smoke test + compute-sanitizer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 00:48:18 +02:00