jgrusewski b435d25bec fix(sp11): B1b bug-hunt fix-up — stale rc[] init + cf_flip ordering
Bug-hunt review on 5e16b67ca found two real bugs in experience_env_step
post-B1b structural refactor — same class as the slot 63 overload
(pre-SP11 invariants exposed by post-decomposition semantic).

Bug 1 (Critical): reward_components_per_sample[+1..+5] not zero-init at
per-bar entry. Slots written only on execution paths that fire (rc[2]
inside segment_complete trail-trigger, rc[3] inside positioned-non-
complete, rc[4] inside flat-with-features, rc[5] inside multiple
bonus paths, rc[1] inside CF block). Non-firing paths leave stale
values from previous batch's same out_off, contaminating SP4
reward_component_ema_kernel -> slots 64..68 -> SP11 mag-ratio canary
-> wrong controller weights.

Fix: zero-init rc[0..6) at the same location where r_<component>
locals are zero-initialized, so locals and buffer reset together.
Eliminates the entire stale-rc class of bugs.

Bug 2 (Important): cf_flip applied BEFORE inventory/churn/conviction
modifiers. Spec section 3.4.4 requires cf_flip LAST so subtractive
penalties operate on the right sign and multiplicative scales
attenuate before direction is flipped. Pre-fix on flipped samples,
inventory/churn ADDED to negated reward (penalty became bonus) and
conviction scaled the wrong-signed value. Asymmetric gradient signals
between flipped/non-flipped -> contaminated SP11 mag-ratio canary at
the cf axis.

Fix: move cf_flip to after conviction_scale, making it the last
modifier before out_rewards write. CF-block contract preserved
(reward at cf_off is still the post-flipped final value; CF block
already does `do_flip ? -reward : reward` to recover unflipped base).

Stale doc-strings: state_reset_registry.rs (2 sites) and
training_loop.rs (1 site) referenced pre-fix-up SP5_PRODUCER_COUNT=186
/ wiener_buffer=771. Updated to formula form
`(71 + SP5_PRODUCER_COUNT) × 3` so they don't drift on the next SP;
current value (post-B1b fix-up slot 360) is SP5_PRODUCER_COUNT=187,
buffer=774 floats.

dqn-wire-up-audit.md: appended SP11 B1b bug-hunt fix-up section
documenting both bugs, the structural fix, the doc-string sweep,
and verification (cargo check/build/tests).

cargo check + build clean; 6/6 SP11 GPU tests + 10/10 sp5_isv_slots
contract tests + 4/4 state_reset_registry tests still pass. The two
bugs were latent in the local smoke (sharpe 3 vs B1a 30 likely
traceable to either or both); structural fix sound. L40S smoke on
this commit will validate the empirical recovery.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:51:55 +02:00

Foxhunt

Production HFT trading system in Rust.

Architecture

The workspace contains 32 crates organized as follows:

Core Libraries (16)

Crate Purpose
trading_engine Order processing, FIX 4.4, IB TWS, SIMD, RDTSC timing
risk VaR, Kelly, circuit breakers, kill switches, compliance
risk-data Risk data types and shared structures
trading-data Trading data types
ml DQN Rainbow, PPO, TFT, Mamba2, ensemble inference
ml-data ML data types and feature definitions
data Market data ingestion and storage
backtesting Replay engine, strategy tester
adaptive-strategy Ensemble execution, microstructure analysis
common Shared types, resilience, error handling
storage S3 and local model storage
model_loader Model serialization and loading
market-data Market data feed handlers
database PostgreSQL access layer (SQLx)
config Configuration management
tli CLI commands and tooling

Services (8)

Service Purpose
backtesting_service gRPC backtesting service
broker_gateway_service FIX routing, broker connectivity
trading_service Core trading operations
ml_training_service Model training orchestration
data_acquisition_service Market data acquisition
trading_agent_service Autonomous trading agents
api_gateway gRPC API gateway with auth
web-gateway Axum REST + WebSocket gateway

Frontend

web-dashboard/ -- React 19 + TypeScript + Vite + TradingView charts.

Building

# Check compilation (no PostgreSQL required)
SQLX_OFFLINE=true cargo check --workspace

# Run tests for a specific crate
SQLX_OFFLINE=true cargo test -p <crate> --lib

# Clippy
SQLX_OFFLINE=true cargo clippy --workspace

ML Models

Four production model architectures on Candle v0.9.1 with CUDA:

  • DQN Rainbow -- Deep Q-Network with prioritized replay, dueling heads, noisy nets
  • PPO -- Proximal Policy Optimization with GAE and LSTM policies
  • TFT -- Temporal Fusion Transformer for multi-horizon forecasting
  • Mamba2 -- State space model for sequence prediction

Each model has a standalone trainer and a UnifiedTrainable adapter for the hyperopt pipeline.

Infrastructure

  • Git: Gitea at git.fxhnt.ai (Tailscale-only), Scaleway DEV1-S
  • Observability: OpenTelemetry OTLP (env OTEL_EXPORTER_OTLP_ENDPOINT)
  • Database: PostgreSQL with SQLx offline mode for CI

License

Proprietary. All rights reserved.

Description
No description provided
Readme 849 MiB
Languages
Rust 88.2%
Cuda 7.7%
Python 1.3%
Shell 1.1%
PLpgSQL 0.8%
Other 0.8%