## Session Summary [00:00:21 ] (auto-generated)
**Agent Profile: Multi-Agent RL Training System**
*   **Role:** Multi-Agent Reinforcement Learning Agent
*   **Primary Objective:** Train agents to navigate complex environments (Maze, Hide & Seek) while managing energy and maximizing score.
*   **Core Mechanisms:**
    *   **Physics Engine:** Uses PyMunk for rigid body dynamics.
    *   **Reward System:** Dynamic rewards based on energy conservation, score, and survival.
    *   **Environment:** Customized to handle different modes (Maze, Hide & Seek) with specific reward functions.

**Key Decisions Made:**
*   **Collision Resolution:** Fixed object collision handling in `add_object()` by explicitly setting `collision_type = COLLISION_TYPE_OBJECT` on all newly created shapes. Previously, agents passed through objects due to missing collision definitions.
*   **Agent Initialization:** Modified `add_agent()` to automatically create a physics body if the simulation is already running, preventing agents from sitting at (0,0) with no movement.
*   **Long-Running Stability:** Implemented signal handling to ensure RL training does not crash or timeout on service restarts, with automatic re-entrancy.
*   **Energy Management:** Integrated energy recovery logic into the reward function for Hide & Seek agents, allowing them to sustain while hiding.

**Completed vs. In Progress:**
*   **Completed:**
    *   Fixed collision types for all UI-placed objects (boxes, ramps, crates, barrels).
    *   Implemented signal handling for long-running training stability.
    *   Configured energy recovery rewards for Hide & Seek modes.
    *   Verified agent placement logic at (13,82).
*   **In Progress:**
    *   Debugging specific object collision types in Hide & Seek mode.
    *   Finalizing the "Long Run" feature configuration.

**Next Step:**
*   **Execute:** Run the training loop with the new collision and energy recovery configurations.
*   **Verify:** Check agent performance metrics (score, energy, survival) and confirm no crashes during long training sessions.

---

## Neural Lab v3.2 Continued (00:00–00:10 EDT)

### Bug Fixes This Pass
- **Object collision fix**: `add_object()` was missing `collision_type = COLLISION_TYPE_OBJECT` on shapes — agents passed through all UI-placed objects (boxes, ramps, platforms). Walls worked because they used a different code path. Fixed.
- **Food works in ALL environments now**: Food collection (distance < 20) gives +0.5 score and +10 energy in every mode. Previously only worked in foraging. Hiders can eat while hiding, seekers between hunts.
- **Agent spawn after start**: `add_agent()` now calls `_create_agent_body()` immediately if sim is already running. Previously agents added mid-sim had no physics body, sat at (0,0).
- **Static vs sensor objects clarified**: food/flag/tool are sensors (don't block), ramp/platform/crate when static are solid collision bodies.

### Long-Run Training Support
- Step selector changed from input to dropdown: 5K, 10K, 50K, 100K, 500K, 1M (~10hr), 5M (~2days), 10M (~4days)
- Emergency save: `atexit.register(_emergency_save)` + `SIGTERM` signal handler saves RL progress on shutdown
- systemd `Restart=on-failure` keeps service alive across crashes
- Auto-save every 25 episodes (existing), max 25 episodes lost on hard crash

### Setup Overhaul
- **6 Preset Teams** (one-click): 2v2 H&S, 3v3 H&S, Forage 4, Build Team, Predator/Prey, Full Match
- Each preset sets environment + spawns agents with correct roles/teams
- **Agent removal**: ✕ button per agent, 🗑️ Clear All button
- **Agent list in Setup section** shows all agents with team color, role, remove button
- **Saved Worlds dropdown**: `simWorldSelect` loads from `/api/sim/worlds`, picks saved layouts
- Setup section renamed from "Sim Agents" to "⚙️ Setup" — cleaner organization

### Pat's Request: Mixed Training Models Per Team
- Currently all RL agents share one PPO model
- Pat wants per-agent model assignment: PPO, A2C, DQN, A*, rule-based mixed in same team
- Not yet implemented — flagged as next architecture step

### Git Commits
- `d9a9068` Fix object collisions, food in all modes, agent spawn, long runs
- Backup pushed to GitHub

### Files Modified
- `tools/neural-lab/simulation.py`: collision_type fix, food-everywhere, agent spawn fix
- `tools/neural-lab/orchestrator.py`: emergency save handler, atexit/signal
- `hub/31-neural-lab/index.html`: setup panel, presets, agent list with remove, world selector, step dropdown