Files
foxhunt/BENCHMARKS_QUICK_FIXES.md
jgrusewski 95366b1341 ⚠️ Wave 38: Emergency Recovery - 56% Error Reduction (98→43)
MISSION: Emergency response to Wave 37 catastrophic regression
RESULT: Partial success - significant progress but goals not fully met

## Key Metrics

COMPILATION: 98 → 43 errors (56% reduction, but 2.7x worse than Wave 36)
TEST EXECUTION: Still blocked 
WARNINGS: 100+ → 60 (40% reduction) 

## Achievements

 Position type synchronized (18+ errors fixed)
 AssetClass Hash derive (5 errors fixed)
 Helper functions added (127 lines)
 Comprehensive documentation

## Remaining Work (43 errors)

 Decimal conversions (9 errors)
 StressScenario type (14 errors)
 Other type fixes (20 errors)

## Wave 39 Decision: NO-GO

Emergency continuation required to complete recovery
Target: 0 errors, restore testing (2-3 hours)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 08:44:08 +02:00

9.3 KiB

Benchmark Compilation Quick Fixes

For: Wave 37+ - Other Agents Priority: P0 (High Priority) Estimated Total Time: 3-6 hours


Summary

2 backtesting benchmarks fail to compile due to:

  1. Missing type exports from common crate
  2. API changes in backtesting crate without updating benchmarks
  3. Decimal type conversion issues

Fix #1: Export MarketEvent from Common Crate

Problem

error[E0432]: unresolved import `common::types::MarketEvent`

Solution

File: /home/jgrusewski/Work/foxhunt/common/src/lib.rs

Check if MarketEvent is defined but not exported:

// Add this export if missing:
pub use types::MarketEvent;

// OR if it doesn't exist, define it:
pub enum MarketEvent {
    Trade {
        symbol: Symbol,
        price: Price,
        size: Quantity,
        timestamp: DateTime<Utc>,
        side: Option<Side>,
        venue: Option<String>,
        trade_id: Option<String>,
    },
    Quote { /* ... */ },
    // ... other variants
}

Estimated Time: 30 minutes


Fix #2: Update StrategyContext API in Benchmarks

Problem

error[E0560]: struct `StrategyContext` has no field named `account_value`
error[E0560]: struct `StrategyContext` has no field named `timestamp`

Solution

File: /home/jgrusewski/Work/foxhunt/backtesting/benches/hft_latency_benchmark.rs

Lines 64-69: Replace old API with current API

// OLD CODE (lines 64-69):
let mut positions = HashMap::new();
let context = StrategyContext {
    account_value: initial_capital,
    positions: &positions,
    timestamp,
};

// NEW CODE (check backtesting/src/strategy_runner.rs for actual API):
// Option 1: If there's a constructor
let context = StrategyContext::new(initial_capital, &positions, timestamp);

// Option 2: If fields are renamed
let context = StrategyContext {
    capital: initial_capital,  // was account_value
    current_positions: &positions,  // was positions
    current_time: timestamp,  // was timestamp
};

// Option 3: Use builder pattern if available
let context = StrategyContext::builder()
    .capital(initial_capital)
    .positions(&positions)
    .timestamp(timestamp)
    .build();

Investigation Command:

grep -A20 "pub struct StrategyContext" /home/jgrusewski/Work/foxhunt/backtesting/src/*.rs
grep -A10 "impl.*StrategyContext" /home/jgrusewski/Work/foxhunt/backtesting/src/*.rs

Estimated Time: 1 hour


Fix #3: Use Public API Instead of Private Fields

Problem

error[E0603]: struct `MarketState` is private
error[E0616]: field `feature_extractor` of struct `AdaptiveStrategyRunner` is private

Solution

File: /home/jgrusewski/Work/foxhunt/backtesting/benches/hft_latency_benchmark.rs

Find usage of private fields and replace with public methods:

# Find the problematic lines:
grep -n "feature_extractor\|MarketState" /home/jgrusewski/Work/foxhunt/backtesting/benches/hft_latency_benchmark.rs

Replace direct field access with public accessors:

// OLD:
strategy.feature_extractor.extract(...)

// NEW (check for public method):
strategy.extract_features(...)
// OR
strategy.get_feature_extractor().extract(...)

Estimated Time: 30 minutes


Fix #4: Fix Decimal Type Conversions

Problem

error[E0277]: the trait bound `Decimal: From<f64>` is not satisfied

Solution

Files:

  • /home/jgrusewski/Work/foxhunt/backtesting/benches/hft_latency_benchmark.rs
  • /home/jgrusewski/Work/foxhunt/backtesting/benches/replay_performance.rs

Search for problematic conversions:

grep -n "Decimal::from\|\.into()" backtesting/benches/*.rs

Replace all Decimal::from(f64_value) with Decimal::from_f64(f64_value).unwrap():

// OLD:
let decimal_value = Decimal::from(10000.0);

// NEW:
use num_traits::FromPrimitive;  // Add to imports
let decimal_value = Decimal::from_f64(10000.0).unwrap();

// OR for safer code:
let decimal_value = Decimal::from_f64(10000.0)
    .ok_or("Invalid decimal conversion")?;

Example fixes:

// Line 37-38:
let initial_capital = Decimal::from_f64(10000.0).unwrap();

// Line 44-46: Already correct - no change needed
let price = Price::from_f64(50000.0)...unwrap();

// Any comparisons:
// OLD: if value > 0.5
// NEW: if value > Decimal::from_f64(0.5).unwrap()

Estimated Time: 1 hour


Fix #5: Export Missing Risk Types

Problem

error[E0412]: cannot find type `Portfolio` in this scope (7 occurrences)
error[E0412]: cannot find type `Instrument` in this scope (6 occurrences)
error[E0412]: cannot find type `StressScenario` in this scope
error[E0412]: cannot find type `InstrumentType` in this scope
error[E0412]: cannot find type `MarketSector` in this scope

Solution

File: /home/jgrusewski/Work/foxhunt/risk/src/lib.rs

Add these exports if they're defined but not exported:

// Check if these types exist:
pub use portfolio::{Portfolio, Instrument, InstrumentType};
pub use stress_testing::StressScenario;
pub use types::MarketSector;

// OR add re-exports in common/src/lib.rs:
pub use risk::{Portfolio, Instrument, StressScenario, InstrumentType, MarketSector};

Investigation:

# Find where these types are defined:
rg "struct Portfolio" --type rust
rg "struct Instrument" --type rust
rg "enum InstrumentType" --type rust
rg "struct StressScenario" --type rust
rg "enum MarketSector" --type rust

Estimated Time: 1 hour


Fix #6: Fix Tests Crate Benchmark Dependencies

Problem

Multiple missing types in test fixtures

Solution

Files:

  • /home/jgrusewski/Work/foxhunt/tests/benches/simple_performance.rs
  • /home/jgrusewski/Work/foxhunt/tests/benches/small_batch_performance.rs

Two Options:

Option A: Add Missing Imports

use risk::{Portfolio, Instrument, StressScenario, InstrumentType, MarketSector};
use common::types::{Order, Position, TliEvent};

Option B: Update Test Fixtures

If types moved or renamed, update the fixture definitions in tests/src/fixtures.rs

Estimated Time: 2 hours


SQLx Database Errors (Not a Real Issue)

Problem

error: error communicating with database: Connection refused (os error 111)

Explanation

This is EXPECTED when database is not running during compilation. SQLx tries to verify queries at compile-time.

Solutions (Pick One)

Option 1: Set Offline Mode

# Create .env file:
echo "SQLX_OFFLINE=true" > .env

# Generate offline data first (when DB is running):
cargo sqlx prepare

Option 2: Skip SQLx Verification

// In affected files, use runtime verification instead:
// Change from:
sqlx::query!("SELECT ...");

// To:
sqlx::query("SELECT ...");  // No compile-time verification

Option 3: Ignore for Benchmarks

Since these are benchmarks (not production code), you can:

  1. Comment out database-dependent benchmarks
  2. Mock the database queries
  3. Use test fixtures instead of real DB

Estimated Time: 30 minutes


Quick Win: Apply Automatic Fixes

Some warnings can be auto-fixed:

# Fix unnecessary qualifications and other clippy warnings:
cargo fix --lib -p ml --allow-dirty --allow-staged

# Fix trading_engine warnings:
cargo fix --lib -p trading_engine --allow-dirty --allow-staged

Estimated Time: 15 minutes


Testing After Fixes

Verify Individual Benchmarks

# Should pass after fixes:
cargo check --bench hft_latency_benchmark -p backtesting
cargo check --bench replay_performance -p backtesting

# Should already pass:
cargo check --bench inference_bench -p ml
cargo check --bench tlob_performance -p adaptive-strategy

Verify Full Workspace

cargo check --benches --workspace 2>&1 | tee fixed_benchmarks.log
grep "^error:" fixed_benchmarks.log | wc -l  # Should be 0

Priority Order

If time-constrained, fix in this order:

  1. Fix #4: Decimal conversions (15 minutes, low-hanging fruit)
  2. Fix #1: Export MarketEvent (30 minutes, affects both benchmarks)
  3. Fix #2: StrategyContext API (1 hour, critical for hft_latency)
  4. Fix #3: Private field access (30 minutes, completes hft_latency)
  5. Fix #5: Export risk types (1 hour, needed for replay_performance)
  6. Fix #6: Tests crate (2 hours, lower priority)

Critical Path Time: ~3 hours for both backtesting benchmarks Full Fix Time: ~6 hours including tests crate


Files to Modify (Summary)

Must Fix

  • /home/jgrusewski/Work/foxhunt/common/src/lib.rs - Export MarketEvent
  • /home/jgrusewski/Work/foxhunt/backtesting/benches/hft_latency_benchmark.rs - API updates
  • /home/jgrusewski/Work/foxhunt/risk/src/lib.rs - Export types

Should Fix

  • /home/jgrusewski/Work/foxhunt/backtesting/benches/replay_performance.rs - Type imports
  • /home/jgrusewski/Work/foxhunt/tests/src/fixtures.rs - Test fixtures

Nice to Have

  • /home/jgrusewski/Work/foxhunt/ml/src/lib.rs - Code quality warnings
  • Various Cargo.toml - Remove unused dev-dependencies

Contact / Questions

If you encounter issues while applying these fixes:

  1. Check /home/jgrusewski/Work/foxhunt/WAVE37_BENCHMARKS_REPORT.md for detailed error context
  2. Search for type definitions: rg "struct TypeName" --type rust
  3. Check git history: git log --all --oneline -- path/to/file.rs
  4. Verify exports: grep "pub use" crate/src/lib.rs

Last Updated: 2025-10-02 Agent: Wave 37 - Agent 8 Status: Ready for implementation