# DISPATCH: Worker M2 Fix 1 (Milestone M2 Iteration 2 Remediation)

## Assigned Agent
- Name: `worker_m2_fix_1`
- Type: `teamwork_preview_worker`
- Working Directory: `c:\Projects\FreeExile\.agents\teamwork\worker_m2_fix_1`

## Mandatory Reference Documents
1. `c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md` (specifically section `## 2026-10-01T19:19:13Z` - R2)
2. `c:\Projects\FreeExile\GEMINI.md`
3. `c:\Projects\FreeExile\AGENTS.md`
4. `c:\Projects\FreeExile\.agents\teamwork\orchestrator_11\PROJECT.md`
5. Explorer Reports for Iteration 2:
   - `c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_1\handoff.md` (Chunk sizing & 8 slots capacity)
   - `c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_2\handoff.md` (Frustum SAT diamond culling & edge cases)
   - `c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_3\handoff.md` & `map_render_benchmark_proposed.js`

## MANDATORY INTEGRITY WARNING
DO NOT CHEAT. All implementations must be genuine. DO NOT hardcode test results, create dummy/facade implementations, or circumvent the intended task. A teamwork_preview_auditor will independently verify your work. Integrity violations WILL be detected and your work WILL be rejected.

## Objective & Tasks
Remediate the LRU cache thrashing defect identified in Milestone M2 Iteration 1 Gate:
1. Update `client/webapp/js/engine/tile_map_renderer.js`:
   - Set `this.MAX_SLOTS = 8;` (or appropriate constant) so the LRU pool holds the entire visible set on mobile portrait ($390 \times 844$), completely eliminating per-frame re-bakes on static camera (0 re-bakes over 50 static frames).
   - Implement 4-plane Separating Axis Theorem (SAT) Diamond Culling to replace coarse canvas rectangular AABB culling:
     - 4 overlap axes: X, Y, Diagonal 1 ($2Y + X$), Diagonal 2 ($2Y - X$).
     - Eliminates phantom chunks at $(30, 30)$ and $(50, 50)$, keeping visible chunks strictly within 4–6 typical and $\le 8$ peak.
     - Average draw calls over full traversal must be $\le 6.0$ blits/frame.
   - Add 0x0 viewport early return: `if (viewport && (viewport.clientWidth <= 0 || viewport.clientHeight <= 0)) return;`.
   - Add extreme pan guard: `if (minTx > maxTx || minTy > maxTy) { this.visibleCount = 0; return; }`.
   - Keep file length strictly $\le 320$ lines (Soft cap 350, Hard cap 500 lines).
2. Update `tools/perf/map_render_benchmark.js`:
   - Replace with validated blueprint from `c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_3\map_render_benchmark_proposed.js`.
   - Traversal $(15, 15) \to (90, 65)$ over 1,000 frames.
   - 50 stationary frames at $(30, 30)$ asserting `stationaryRebakes === 0`.
   - Budget assertions: avg FPS $\ge 30.0$, draw calls avg $\le 6.0$ and peak $\le 8$, 0 stationary re-bakes.
   - Keep file length strictly $\le 200$ lines (Soft cap 350, Hard cap 500 lines).
3. Execute and verify all test suites:
   - `node tools/perf/map_render_benchmark.js` (Must PASS with exit code 0)
   - `node tools/perf/stress_test_lru_cache.js`
   - `pytest tests/e2e/test_poe2_map_system_e2e.py -v` (81/81 PASS)
   - `pytest tests/unit/test_waypoint_safe_radius.py -v` (17/17 PASS)
   - `pytest tests/unit/test_wilderness_map_generator.py -v` (26/26 PASS)
   - `pytest tests/unit/ -q` (935/935 PASS)
   - `python tools/lint/check_code_and_doc_hygiene.py --strict` (0 violations)
4. Write `handoff.md` in `c:\Projects\FreeExile\.agents\teamwork\worker_m2_fix_1\` and send notification to parent orchestrator.

## 2026-10-01T20:35:09Z
You are M2 Fix Worker (worker_m2_fix_1).
Your working directory is: c:\Projects\FreeExile\.agents\teamwork\worker_m2_fix_1
Your dispatch assignment is: c:\Projects\FreeExile\.agents\teamwork\worker_m2_fix_1\DISPATCH.md
MANDATORY: Read the authoritative user request at:
c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md (specifically section ## 2026-10-01T19:19:13Z - R2).
Also consult c:\Projects\FreeExile\GEMINI.md and c:\Projects\FreeExile\AGENTS.md.
