## 2026-10-01T00:43:18Z

You are teamwork_preview_explorer (M3 Hideout Instance Session Cleanup Explorer) for FreeExile.
Your working directory is: c:\Projects\FreeExile\.agents\teamwork\explorer_m3_r2_3
Your parent is: af73d9ec-d3ff-4501-b986-47b632c5d073 (via orchestrator_1 at c:\Projects\FreeExile\.agents\teamwork\orchestrator_1).

MANDATORY FIRST STEPS:
1. Read the authoritative user request at:
   c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md
2. Read the project specification at:
   c:\Projects\FreeExile\PROJECT.md
3. Read reviewer_m3_2 handoff report at:
   c:\Projects\FreeExile\.agents\teamwork\reviewer_m3_2\handoff.md

Scope and Task:
Milestone 3 Remediation (Iteration 2): Hideout Instance Session Cleanup.
1. Inspect `server/world/hideout_engine.py` (around lines 314-325 in `enter_map_portal`).
2. Review reviewer_m3_2's finding: when `dev.portals_remaining == 0`, `dev.active_map` is set to `None`, but `dev.active_instance_id` is retained, leaving stale sessions in `ZoneEngine.active_instances`.
3. Formulate the exact fix in `enter_map_portal(player_id, portal_index, zone_engine=None)`:
   - When `dev.portals_remaining == 0`:
     - If `zone_engine is not None and hasattr(zone_engine, "active_instances")` and `dev.active_instance_id in zone_engine.active_instances`:
       pop/delete `zone_engine.active_instances[dev.active_instance_id]`.
     - Set `dev.active_instance_id = None`.
4. Inspect and update unit test designs in `tests/unit/test_hideout_engine.py` to assert that exhausting all 6 portals clears `active_instance_id` and unregisters the instance from `ZoneEngine.active_instances`.
5. Check file length of `hideout_engine.py` (must remain strictly under the 500-line Hard Cap).
6. Formulate recommendations and patch for the downstream Worker. Do NOT write source code directly.
7. Write your report to: `c:\Projects\FreeExile\.agents\teamwork\explorer_m3_r2_3\handoff.md`.
8. Update `progress.md` and notify orchestrator_1 via `send_message`.
