2026-05-06 - Phase 1 Dead Code Detection
Pre-market pass with vulture (function/class level) and grep import-graph analysis (module level) against 46,346 Python LOC across 109 files in src/ + scripts/. Codebase is healthier than the 70k LOC estimate suggested. ~960 LOC of scripts and 5 plist .bak files are confirmed deletable. Function-level dead code is minimal (11 vulture findings, all small).
Headline numbers
- Total Python: 46,346 LOC, 109 files (src/ + scripts/, excluding tests)
- Confirmed deletable now: ~960 LOC across 10 scripts + 5 plist .bak files
- Vulture high-confidence findings (≥80%): 11 (mostly unused imports)
- Module-level orphans: 1 confirmed (morning_e2e.py is NOT dead despite 0 inbound imports - it’s a CLI invoked via
python -m)
Confirmed dead - safe to delete now
Scripts (~960 LOC across 10 files)
| File | Lines | Why dead |
|---|---|---|
scripts/force_close_184.py | ~120 | Incident-response from Apr; broker-side fix |
scripts/force_close_195.py | ~120 | Same |
scripts/force_close_233.py | ~120 | Same |
scripts/force_close_264.py | ~120 | Same |
scripts/flatten_182.py | 127 | Incident-specific |
scripts/nuke_close_184.py | 124 | Incident-specific (duplicate of force_close_184) |
scripts/backfill_exec_links.py | 80 | Superseded by audit_trade_contracts.py |
scripts/backfill_trade_contracts.py | 181 | Superseded by audit_trade_contracts.py |
scripts/backtest_new_rules.py | 221 | Experimental / never wired in |
scripts/diag_margin.py | 53 | One-off diagnostic, no caller |
Total: ~1,266 LOC across 10 scripts. All have zero inbound references in src/, tests/, or other scripts.
Operational backups (5 plist files)
~/Library/LaunchAgents/com.cortanaroi.dashboard.plist.bak-pre-prod-symlink-20260422
~/Library/LaunchAgents/com.cortanaroi.e2e-preflight.plist.bak-pre-prod-symlink-20260422
~/Library/LaunchAgents/com.cortanaroi.eod-report.plist.bak-pre-prod-symlink-20260422
~/Library/LaunchAgents/com.cortanaroi.ibgateway.plist.bak-pre-prod-symlink-20260422
~/Library/LaunchAgents/com.cortanaroi.mk2.plist.bak-pre-prod-symlink-20260422
Pre-prod-symlink-rotation backups from 2026-04-22, kept “just in case.” All 5 of those plists have current versions in scripts/ and live versions in ~/Library/LaunchAgents/ (without .bak suffix).
Vulture findings (function/class scope)
Only 11 high-confidence items. Most are 1-line cleanups:
scripts/build_daily_report.py:10: unused import 'REPORTS_ROOT'
scripts/daily_dashboard.py:581: unused variable 'border_b'
scripts/e2e_test.py:156: unused variable 'entry_num'
src/cortana/alerts/telegram.py:29: unused import 'BrokerClient'
src/cortana/app.py:2837: unused variable 'frame'
src/cortana/app.py:2837: unused variable 'sig'
src/cortana/broker/ibkr.py:77: unused import 'Contract'
src/cortana/clock.py:12: unused import '_is_half_day'
src/cortana/engines/price_tape.py:341 unused variable 'resist_high'
src/cortana/engines/scoring.py:590: unused import '_trend_time'
src/cortana/utils/smc_levels.py:122: unused variable 'max_age_hours'
These are real but trivial. Codex tab can clean all 11 in one ~10-min run. Worth doing as a polish pass but not high-priority.
Module-level analysis
Top 5 largest modules:
4,872 src/cortana/engines/spy_0dte.py
2,888 src/cortana/app.py
1,712 src/cortana/storage/trade_tracker.py
1,553 src/cortana/broker/ibkr.py
1,460 src/cortana/engines/scoring.py
spy_0dte.py at 4,872 LOC is the giant. It contains both V1 and V2 engine logic. If V1 is no longer firing in production (V2 is the live path per Tasks 67 fix history), there could be 1-2k LOC of V1 cruft inside. Worth a focused folder-pass investigation in Phase 2 (#75).
NOT dead despite low/zero inbound imports
False positives my initial grep flagged that are actually live:
| File | Inbound imports | Why kept |
|---|---|---|
src/cortana/clock.py | 41 | Heavy use; my regex bug |
src/cortana/config.py | 11 | Real usage |
src/cortana/watchdog.py | 4 | Live engine component |
src/cortana/tools/morning_e2e.py | 0 | CLI entry point invoked via python -m, used by e2e-preflight plist |
src/cortana/tools/replay_harness.py | 1 (via main.py) | CLI entry point |
src/cortana/dashboard/__main__.py | 0 | Module entry point |
Phase 2 prep
Now that we have evidence-backed dead-code list, Phase 2 (#75) can be focused:
- Quick wins (#77) - delete the 10 scripts + 5 plist .bak files. ~1,266 + ops backups gone. ~30 min Codex.
- Vulture cleanup pass - fix the 11 high-confidence findings in one sweep. ~10 min Codex.
- Folder-by-folder review - start with
src/cortana/engines/(biggest, most complex, V1/V2 mix). Codex tab per folder asking “what’s essential / nice-to-have / dead given V2 is the live engine path?” - spy_0dte.py focused review - 4,872 LOC is the elephant. Likely 1-2k of V1 cruft removable.
Estimated total prunable
- Phase 1 confirmed: ~1,300 LOC + 5 plist .bak files
- Phase 2 expected (V1 cruft + folder-level): 3-5k LOC
- Total estimate: ~5-7k LOC removable (~13% of the 46k Python LOC)
Substantially less than my initial “10-15k LOC” guess from yesterday - codebase is healthier than I assumed.
Recommended order for tomorrow
- Today (pre-market): ship #77 quick wins via Codex (delete the 10 scripts + 5 plist .bak files, tag git ref
v0.9-pre-prunefirst). - Today (during paper trading): vulture cleanup pass (11 trivial fixes).
- This weekend: Phase 2 (#75) - folder-by-folder, spy_0dte.py first.
- Next week: lifecycle tagging (#76) on what remains.
See Also
- Task #74 (this work)
- Task #75 Phase 2 folder prune
- Task #76 lifecycle tagging
- Task #77 quick wins
- Codex Sandbox Silent Drop - verify after every Codex tab
Timeline
2026-05-06 04:50 CDT | Pre-market run before engine kicks at 8:10. vulture + import-graph analysis. 46k LOC across 109 files, ~1.3k LOC of dead scripts identified. Codebase is in better shape than the strategic discussion last night assumed.