Lesson Learned 011: Missing Function Imports Blocked Trading (Dec 11, 2025)
Lesson Learned 011: Missing Function Imports Blocked Trading (Dec 11, 2025)
ID: LL-011 Date: December 11, 2025 Severity: CRITICAL Category: CI/CD, Imports Impact: 0 scheduled trades executed for the entire day
Incident Summary
Root Cause: Missing functions in mental_toughness_coach.py that were imported by debate_agents.py
Resolution Time: ~2 hours (discovered late in trading day)
What Happened
- PR #384 added psychology integration including
debate_agents.pywhich imports:get_prompt_context()frommental_toughness_coach.pyget_position_size_modifier()frommental_toughness_coach.py
-
A force push (
b6d46345 feat: consolidate valuable changes) overwrote main and lost the functions -
The scheduled trading workflow ran but failed at âExecute daily tradingâ step with ImportError
- Because
debate_agents.pywas imported during orchestrator initialization, the entire trading script crashed
Technical Details
# debate_agents.py imports (lines 24-26):
from src.coaching.mental_toughness_coach import get_position_size_modifier
from src.coaching.mental_toughness_coach import (
get_prompt_context as get_psychology_context,
)
When these functions donât exist, Python raises ImportError before any trading code runs.
Why It Wasnât Caught
- No import verification test: CI didnât explicitly test that all inter-module imports resolve
- No pre-merge import gate: PRs werenât required to pass import verification
- Force push overwrote changes: Git rebase/force push silently discarded the psychology functions
- Scheduled run failures not monitored: Many consecutive failures didnât trigger alerts
Prevention Measures Implemented
1. Import Verification Test (tests/test_critical_imports.py)
def test_all_critical_imports():
"""Verify all inter-module imports resolve correctly."""
# Test psychology integration imports
from src.coaching.mental_toughness_coach import get_prompt_context, get_position_size_modifier
from src.agents.debate_agents import DebateModerator, BullAgent, BearAgent
from src.coaching.reflexion_loop import ReflexionLoop
# Test orchestrator can be imported (catches all downstream import errors)
from src.orchestrator.main import TradingOrchestrator
2. Pre-Merge Import Gate (.github/workflows/ci.yml)
- name: Verify Critical Imports
run: |
python3 -c "
from src.orchestrator.main import TradingOrchestrator
from src.agents.debate_agents import DebateModerator
print('â
All critical imports verified')
"
3. Import Dependency Graph (scripts/verify_imports.py)
Static analysis tool that:
- Parses all Python files for import statements
- Builds dependency graph
- Verifies all imported symbols actually exist
- Runs in CI before merge
Key Learnings
- Inter-module dependencies are fragile: When Module A imports from Module B, changes to B can silently break A
- Force pushes are dangerous: They can silently discard commits without warning
- Import errors are silent killers: They crash the entire application before any logic runs
- Scheduled workflow failures need monitoring: Multiple consecutive failures should alert immediately
RAG Query Keywords
- import error
- missing function
- ModuleNotFoundError
- ImportError
- debate_agents
- mental_toughness_coach
- get_prompt_context
- get_position_size_modifier
- psychology integration
- scheduled workflow failure
- force push
- rebase
- consolidate
Prevention Rules
- Apply lessons learned from this incident
- Add automated checks to prevent recurrence
- Update RAG knowledge base
Related Incidents
- LL_009: CI syntax failure (Dec 11) - Similar âimport time failureâ pattern
- LL_010: Dead code and dormant systems (Dec 11) - Code exists but isnât connected
Checklist for Future PRs
- Run
python3 -c "from src.orchestrator.main import TradingOrchestrator"locally - If adding new imports, verify the symbols exist in target module
- Never force push to main without verifying all imports still work
- Check CI âVerify Critical Importsâ step passed before merging