jgrusewski 93126504ca plan5(task5-F): compile-time fxcache schema fingerprint via build.rs
Closes the L40S deploy-bug class where stale fxcache passed
FXCACHE_VERSION validation despite incompatible feature semantics.
Root cause of the original failure: extract_ohlcv_features column 0
changed from raw price -> log-return without anyone bumping the
manually-maintained FXCACHE_VERSION const, so the L40S PVC's older
cache loaded clean and the trainer fed raw prices into the aux head
expecting log-returns (aux_next_bar_mse=2.587e7).

Fix:

* crates/ml/build.rs::emit_feature_schema_hash() runs unconditionally
  (before the existing CUDA-feature gate so non-CUDA builds also pick
  up the env var) and FNV-1a-hashes the raw bytes of the three
  schema-defining sources -- crates/ml/src/features/extraction.rs,
  crates/ml/src/fxcache.rs, crates/ml-core/src/state_layout.rs --
  mixing in each file's relative path + length so renames /
  reorderings also bump the hash. Stable across rust versions and
  machines (FNV-1a, not std::hash::DefaultHasher). Emits
  cargo:rustc-env=FEATURE_SCHEMA_HASH=<decimal_u64> + three
  cargo:rerun-if-changed= lines.

* crates/ml/src/fxcache.rs::FEATURE_SCHEMA_HASH consumes the env var
  via env! + const u64::from_str_radix(_, 10) (const-stable since
  rust 1.83; workspace MSRV 1.85). FxCacheHeader grows a
  feature_schema_hash: u64 field; header size 64->72 bytes;
  FXCACHE_VERSION bumped 5->6 to flag the wire-format change.
  validate() strict-checks the hash alongside magic / version / dims;
  mismatch bails with a descriptive error pointing at "source files
  defining feature extraction / state layout / fxcache format have
  changed since this cache was built." The existing
  precompute_features.rs:218 delete-and-regen-on-Err path handles
  recovery automatically; the Argo ensure-fxcache step is unchanged.

* FXCACHE_VERSION docstring now declares it tracks WIRE-FORMAT
  changes only -- schema-level changes (feature column semantics,
  dimensionality) are tracked automatically by FEATURE_SCHEMA_HASH.
  Removes the manual ritual that broke the L40S deploy.

* docs/dqn-wire-up-audit.md entry under Plan 5 Task 5 Phase F.

Cost: cosmetic edits (whitespace, comments) to the three schema
sources trigger one cache regen on next deploy (~5 min for full L40S
dataset, ~40 s for local ES.FUT). Acceptable trade -- false negatives
(missed schema drift) are not.

Validation:
* cargo check workspace clean at 11 warnings (baseline preserved).
* Local ES.FUT cache regen confirmed: existing v5 file rejected with
  "Stale FxCache version: 5 (expected 6). Delete and regenerate.",
  regenerated v6 cache loads clean on retry (40 s, 175874 bars).
* Auto-detection verified: comment-only edit to extraction.rs line 1
  changed emitted hash 5046469432341222878 -> 7772630163018944575;
  revert returned the hash deterministically to 5046469432341222878.
* multi_fold_convergence smoke PASSED (1 passed, 0 failed; 689.24 s,
  ~11.5 min). All 3 folds produced best-checkpoints. Per-fold best
  Sharpe: F0=-9.7831 (epoch 1), F1=37.9597 (epoch 2),
  F2=40.4789 (epoch 5). aux next_bar_mse range across all 15 epochs:
  6.097e-2 -- 4.722e-1 (O(0.1), not 1e7 as in the L40S regression).

No new pip/cargo deps (FNV-1a is ~10 LOC stdlib).
No fingerprint change (LAYOUT_FINGERPRINT_CURRENT untouched -- this
is fxcache wire-format, not GPU param layout).

Files touched:
* crates/ml/build.rs
* crates/ml/src/fxcache.rs
* docs/dqn-wire-up-audit.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 16:18:22 +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%