# Challenge Report: Milestone M5 Encounter Architecture Empirical Stress Testing

**Agent**: `challenger_m5_2` (Empirical Challenger / Critic)  
**Parent**: `1cc48fc5-ce57-4f48-8964-24cab4bfcacc`  
**Timestamp**: 2026-10-01T22:40:00Z  

---

## Challenge Summary

**Overall risk assessment**: LOW (Robust with 1 minor defensive design recommendation)

All 4 critical stress dimensions passed empirical testing:
1. **Cohesive Pack Leashing Stress**: PASS (Disengages at distance > 9.0 tiles, returns to anchor within <= 0.6 tiles, Waypoint safe radius 8.0 immediately disengages mobs and blocks all damage).
2. **POI Wave Ambush Stress**: PASS (Triggers exactly once upon rapid multi-traversal; all 1,188 minions spawned across 300 procedural POIs land exclusively on passable tiles).
3. **Boss Gate Progression Stress**: PASS (50/50 simulated zones successfully track kills, mutate gate tile strictly to FLOOR (1), clear collision in `collision_engine.js`, and enforce proximity lore hysteresis at <= 3.0 and > 3.5).
4. **Performance & Test Suites**: PASS (0 stationary re-bakes in `map_render_benchmark.js`, all 12 tests in `test_encounter_zones.py` pass).

---

## Empirical Challenges & Stress Test Results

### [Low] Challenge 1: POI Ambush Minion Fallback Near Narrow Walls

- **Assumption Challenged**: In `ambush_trigger_system.js`, when an ambush minion's initial radius (`1.6 + rand * 0.6`) lands on a blocked tile, the fallback formula pulls it to `poiCenterX + Math.cos(angle) * 0.8`.
- **Attack Scenario**: If an arbitrary POI were placed directly adjacent to a wall (e.g. 1-tile wide hallway), `0.8` offset from `0.5` center equals `1.3`, which crosses into the adjacent tile (`Math.floor(x + 1.3) = x + 1`). If `x + 1` is also a wall, the fallback lands in the wall.
- **Empirical Validation**:
  - In an adversarial test where POIs were forced onto arbitrary narrow corridors next to solid walls, 41/396 mobs landed on walls.
  - However, testing against **300 genuine procedural POIs across 100 seeds** generated by `WildernessMapGenerator` showed **0 blocked spawns out of 1,188 minions**. This is because `WildernessMapGenerator` carves 5x5 clearings (`_carve_dead_ends`) around POIs.
- **Blast Radius**: None in current map generation. Minor risk if custom maps or tighter dungeons place POIs directly touching 1-tile walls.
- **Mitigation Recommendation**: In future refactors, verify the fallback tile itself via `getTileAt` before finalizing spawn coordinates, or fallback to `(poiCenterX, poiCenterY)` which is guaranteed walkable.

### [Verified Robust] Challenge 2: Cohesive Pack Leashing & Waypoint Safe Radius

- **Stress Scenario**: Monster pack leader dragged across 15.0 tiles by player.
- **Result**: Monster reaches `distToOrigin = 9.09 > 9.0` (leash radius), immediately sets `hasAggro = false, isLeashing = true, isInvulnerable = true`. Moves continuously back to origin, reaches `distToOrigin <= 0.6`, resets `isLeashing = false`, and resumes gentle idle patrol.
- **Waypoint Safe Radius**: When player steps within 8.0 tiles of waypoint (`zone_tang_kiem_nhai`), chasing monsters immediately enter `isLeashing = true, hasAggro = false`. When monster attacks player inside safe radius, `executeMonsterAttackOnPlayer` returns immediately, resulting in 0 damage taken.

### [Verified Robust] Challenge 3: Rapid POI Multi-Traversal

- **Stress Scenario**: Player oscillates rapidly back and forth across POI coordinates 100 times.
- **Result**: Ambush wave spawns exactly once (`triggersDetected = 1, initialCount = 4-5`), `poi.isTriggered` remains `true`, and no duplicate waves or memory leaks occur.

### [Verified Robust] Challenge 4: Boss Gate 50-Zone Progression & Proximity Hysteresis

- **Stress Scenario**: 50 simulated zones with varying pack counts (1 to 6 packs) cleared incrementally.
- **Result**:
  - Exact remaining pack count displayed in proximity lore popup at `dist <= 3.0`.
  - Lore popup remains active in hysteresis band `(3.0, 3.5]`.
  - Lore popup closes when `dist > 3.5`.
  - Upon clearing the final pack, Boss Gate tile strictly mutates to `FLOOR` (1), `BossGateController.state` transitions to `UNLOCKED`, and `isPositionBlocked(gateX + 0.5, gateY + 0.5)` returns `false` across both controller and `collision_engine.js`.

---

## Performance Stress Benchmark

- **Stationary 0-Bake Test**: 0 re-bakes over 50 frames (Target: 0) -> PASS
- **Average Frame Time**: 0.008 ms (Target <= 33.33 ms) -> PASS
- **Equivalent FPS**: 131,497 FPS (Target >= 30.0 FPS) -> PASS
- **Draw Calls**: Avg 6.41, Max 8 (Target avg <= 6.5, max <= 8) -> PASS
- **RAM Footprint**: 16.01 MB / 16.50 MB budget -> PASS
