# Implementation Plan: Asyncio Decoupling Refactor (asyncio_decoupling_refactor_20260306)

> **TEST DEBT FIX:** This track is responsible for permanently eliminating the `RuntimeError: Event loop is closed` test suite crashes by ripping out the conflict-prone asyncio loops from the AppController.

## Phase 1: Event System Migration
- [x] Task: Initialize MMA Environment `activate_skill mma-orchestrator`
- [x] Task: Refactor `events.py`
    - [x] WHERE: `src/events.py`
    - [x] WHAT: Replace `AsyncEventQueue` with `SyncEventQueue` using `import queue`.
    - [x] HOW: Change `async def get()` to a blocking `def get()`. Remove `asyncio` imports.
    - [x] SAFETY: Ensure thread-safety.
- [x] Task: Conductor - User Manual Verification 'Phase 1: Event System'

## Phase 2: AppController Decoupling
- [x] Task: Refactor `AppController` Event Loop
    - [x] WHERE: `src/app_controller.py`
    - [x] WHAT: Remove `self._loop` and `asyncio.new_event_loop()`.
    - [x] HOW: Change `_run_event_loop` to just call `_process_event_queue` directly (which will now block on queue gets).
    - [x] SAFETY: Ensure `shutdown()` properly signals the queue to unblock and join the thread.
- [x] Task: Thread Task Dispatching
    - [x] WHERE: `src/app_controller.py`
    - [x] WHAT: Replace `asyncio.run_coroutine_threadsafe(self.event_queue.put(...))` with direct synchronous `.put()`. Replace `self._loop.run_in_executor` with `threading.Thread(target=self._handle_request_event)`.
    - [x] HOW: Mechanical replacement of async primitives.
    - [x] SAFETY: None.
- [x] Task: Conductor - User Manual Verification 'Phase 2: Decoupling'

## Phase 3: Final Validation
- [x] Task: Full Suite Validation
    - [x] WHERE: Project root
    - [x] WHAT: `uv run pytest`
    - [x] HOW: Ensure 100% pass rate with no hanging threads or event loop errors.
    - [x] SAFETY: None.
- [x] Task: Conductor - User Manual Verification 'Phase 3: Final Validation'
