Lesson Learned: Dynamic Budget Scaling Was Dead Code

Date: 2025-12-11 Severity: CRITICAL Category: Dead Code, Capital Efficiency, Revenue Impact

ID: LL-014 Impact: - Revenue loss: $100/day potential → $10/day actual (90% loss)

What Happened

The function _apply_dynamic_daily_budget() in scripts/autonomous_trader.py was:

  • Defined at line 305-336
  • Never called in execution flow
  • Comment at line 611 said “SIMPLIFIED PATH: Skip dynamic budget”

This meant the system was hard-coded to $10/day budget regardless of $100k equity.

Impact

  • Revenue loss: $100/day potential → $10/day actual (90% loss)
  • Math impossible: Required 800% return for $100/day goal
  • System not scaling: No path to profitability regardless of capital growth

Root Cause

  1. Simplification gone wrong: Someone commented out the call “to simplify”
  2. No function call coverage test: No test verified critical functions are called
  3. External analysis fabricated claims: Analysis claimed non-existent files existed

Detection Failure

  • Function had docstring and implementation
  • Function was imported/exported
  • But AST analysis would show: 0 call sites

Fix Applied

  1. Wired up _apply_dynamic_daily_budget(logger) in main() at line 614
  2. Updated docstring to reflect actual 1% equity scaling
  3. Added to .env.example with documentation

Prevention Measures

1. Critical Function Call Coverage Test

Add test that verifies critical trading functions are actually called:

# tests/test_critical_function_coverage.py
CRITICAL_FUNCTIONS = [
    ("scripts/autonomous_trader.py", "_apply_dynamic_daily_budget"),
    ("src/orchestrator/main.py", "manage_positions"),
    ("src/analytics/options_profit_planner.py", "evaluate_theta_opportunity"),
]

def test_critical_functions_are_called():
    for file_path, func_name in CRITICAL_FUNCTIONS:
        call_count = count_function_calls(file_path, func_name)
        assert call_count > 0, f"DEAD CODE: {func_name} in {file_path} has 0 call sites"

2. Pre-commit Hook for Dead Code Detection

# .pre-commit-config.yaml addition
- repo: local
  hooks:
    - id: detect-dead-critical-functions
      name: Detect dead critical functions
      entry: python scripts/detect_dead_code.py
      language: python
      types: [python]

3. RAG Query Before Trusting External Analysis

Before implementing suggestions from external sources:

Query: "Does [file/function] exist in codebase?"
Verify: grep -r "def function_name" src/ scripts/

4. CI Integration Test

Add workflow step that runs the trading flow in dry-run and verifies all gates execute.

Prevention Rules

  1. Apply lessons learned from this incident
  2. Add automated checks to prevent recurrence
  3. Update RAG knowledge base

Tags

dead-code dynamic-budget revenue-impact capital-efficiency external-analysis verification

  • ll_010_dead_code_and_dormant_systems_dec11.md
  • ll_009_ci_syntax_failure_dec11.md