# Entropy Audit Findings: Data-Oriented Python Optimization Pass

## Phase 5 Status: In Progress - Focused Audit Complete

**Approach:** Muratori-style - focused on actual issues, not style. "The less Python the better" means:
- Duplicate logic (same thing done in multiple places) = BAD
- Long functions that are linear and single-purpose = OK
- Nested imports in hot paths = BAD (performance)
- Mutable default arguments = BAD (bugs)

## Already Fixed This Session

### ✓ GUI Indentation Bug causing crash (commit f6feab9)
The `_render_mma_dashboard` had code incorrectly indented inside an `if` block.

### ✓ Duplicate Line Bug in `rag_emb_provider.setter` (commit f6feab9)
`app_controller.py` had two identical lines.

### ✓ Nested Imports in Hot Paths (commit 54afbb9)

**`multi_agent_conductor.py`:**
- Removed `import sys` from inside `run()` - was unused
- `from src.personas import PersonaManager` and `from src import paths` were already available at module level

**`gui_2.py`:**
- Removed `import traceback` from inside `_gui_func` exception handler
- `import uvicorn` in `run()` remains lazy-loaded for `--headless` mode only

**`app_controller.py`:**
- Added `import traceback` and `import inspect` at module level
- Removed 3 nested `import traceback` from `_process_pending_gui_tasks`, `_handle_request_event`, `_do_generate`

## Actual Issues Found (Design - Require Architecture Changes)

### 1. Parallel Ticket Representations
**Severity:** HIGH - Maintenance burden

`active_tickets` (Dict-based) is accessed/modified in THREE files:
- `api_hooks.py` - API endpoint handling
- `app_controller.py` - Main controller state
- `gui_2.py` - UI state

While `dag_engine.py` uses `List[Ticket]` objects. This creates state sync burden.

### 2. Duplicate Blocking Logic
**Severity:** MEDIUM - Potential state inconsistency

| Component | Has Blocking Logic? |
|-----------|-------------------|
| gui_2.py | Yes: `_cb_block_ticket`, `_cb_unblock_ticket` |
| dag_engine.py | Yes: `cascade_blocks` |

If GUI manually blocks tickets without going through DAG, state can diverge.

## Issues Not Addressed (Lower Priority)

### Widespread Mixed Indentation
Many files have 4-space blocks within 1-space files. Style inconsistency only.

### Pattern Usage Across Files
These patterns appear in multiple files (by design - not duplicates):
- `calculate_track_progress`: gui_2.py, project_manager.py
- `topological_sort`: app_controller.py, conductor_tech_lead.py, dag_engine.py
- `push_mma_state`: app_controller.py, gui_2.py

## Summary
- **Fixed:** Nested imports in hot paths (performance), 2 bugs
- **Design Issues:** 2 (parallel ticket state, duplicate blocking logic) - require architectural changes
- **Cosmetic:** Mixed indentation - intentional for readability in some places
