1077f1e165ecc2cba7594819d0c1715bf24cb657
Closes Phase 6.5. The consumer-side infrastructure landed in 6.5a (val state retention + accessor); this commit adds the producer. What lands: 1. GpuReplayBuffer::insert_synthetic_via_pinned (ml-dqn) — raw-u64 dev_ptr mirror of insert_batch's scatter pipeline + per_insert_pa. Takes 7 device pointers + count; bridges from mapped-pinned scratch (in ml crate) to PER's scatter kernels. 2. HindsightScratch struct + MAX_SYNTHETIC_HINDSIGHT=32 constant in enrichment.rs. Holds 7 mapped-pinned buffers (states + next_states + actions + rewards + dones + aux_sign + aux_conf), lazy-allocated. 3. hindsight_scratch: Option<HindsightScratch> trainer field. 4. async fn inject_hindsight_experiences trainer helper: looks up val state at (window_index, bar_index) via 6.5a's read_retained_state, encodes factored action (dir × 27 + mag × 9 + 0 × 3 + 1 for Market/Normal defaults), maps optimal_direction to aux_sign (-1/0/+1), writes reward = counterfactual_pnl, done = 1.0 (terminal), aux_conf = 0.0, calls insert_synthetic_via_pinned. 5. Hook in post-enrichment block — non-fatal warn on infrastructure errors per feedback_kill_runs_on_anomaly_quickly. Design choices: - Terminal done=1: Bellman target reduces to target_q = reward. Avoids synthesizing a valid next_state (optimal counterfactual action would produce a DIFFERENT next state, unsimulable from val data alone). Pure value-target injection at (state, action). - Cap at 32 synthetic per epoch: prevents domination of PER buffer. Scratch alloc ≈ 30 KB pinned host RAM total. - Reward in pnl units: counterfactual_pnl is fraction-of-equity; training reward kernel handles natively (PopArt normalizes). Future scaling via ISV[PNL_REWARD_MAGNITUDE_EMA_INDEX=359] is a one-line follow-up if smoke surfaces gradient outliers. - Mapped-pinned bridge: ml-dqn doesn't have MappedF32Buffer (in ml crate). Raw-u64 API takes dev_ptrs directly — clean cross-crate boundary, no type duplication. Files changed: - crates/ml-dqn/src/gpu_replay_buffer.rs: insert_synthetic_via_pinned API - crates/ml/src/trainers/dqn/trainer/enrichment.rs: HindsightScratch struct + cap const - crates/ml/src/trainers/dqn/trainer/mod.rs: hindsight_scratch field - crates/ml/src/trainers/dqn/trainer/constructor.rs: hindsight_scratch: None init - crates/ml/src/trainers/dqn/trainer/training_loop.rs: inject_hindsight_experiences helper + post-enrichment hook - docs/dqn-wire-up-audit.md: 2026-05-11 audit entry Verification (passing): - cargo check -p ml --tests --features cuda: 0 errors - cargo test -p ml --lib sp21_isv_slots: 3/3 - sp20_aggregate_inputs_test: 12/12 - sp20_phase1_4_wireup_test: 2/2 - sp20_emas_compute_test: 4/4 - sp20_controllers_compute_test: 7/7 - sp21_per_trade_predicted_q_test: 3/3 Total: 34 tests, 0 failures. SP21 T2.2 cascade FULLY COMPLETE (Phases 1.5, 2, 3, 4, 4.5, 5+6, 6.5a, 6.5b, 7, 8). All enrichment outputs (E1-E8) wire to real consumers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…
…
…
…
…
…
…
…
…
…
…
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
Languages
Rust
88.2%
Cuda
7.7%
Python
1.3%
Shell
1.1%
PLpgSQL
0.8%
Other
0.8%