## 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

---

## Session 2 — Polish + Fixes (00:00–01:35 EDT)

### Completed
- **Full UX polish**: Tabbed bottom panel (Setup/Train/Log), single-line compact controls, preset buttons with hover animations
- **Smooth 3D rendering**: Agent position lerping (0.25 factor) for 60fps smooth movement between 150ms polls. First-time snap, then interpolate.
- **Seeker scoring fix**: Seekers now earn exploration (+0.05/tick moving), discovery (+5.0 first spot), proximity (up to +0.05 near hiders). Hider stealth reward nerfed to 0.05 (was 0.1). Events logged: "🔍 predator FOUND animal!"
- **Object collision fix confirmed**: `collision_type = COLLISION_TYPE_OBJECT` was missing on UI-placed objects
- **Agent spawn fix**: `add_agent()` creates physics body immediately if sim running
- **Long-run support**: Step dropdown (5K–10M), atexit/SIGTERM save, auto-checkpoint every 25 eps

### NOT Yet Done (Pat's last ask before context clear)
- **World selection flow is broken/confusing**: Pat saved a world called "PM1" (file: `PM1_HIDEANDSEEKworld-1773116825267.json` in `~/.openclaw/neural-lab/worlds/`). It won't load when selected. The save/load buttons in bottom-right of viewport work differently from the Worlds dropdown in the control bar. NEEDS UNIFIED.
- **Need "New Game" button**: Clean slate — stop sim, clear agents, clear world, fresh start
- **Need world delete**: Can't remove bad saved worlds
- **Start flow is confusing**: Two separate systems (environment preset vs saved world) don't mesh. Need one clear path: pick world/env → preview → agents → start.
- **Mixed training models per team**: Pat wants PPO + A2C + A* etc on different agents within same team

### Architecture Notes for Next Session
- Saved worlds at `~/.openclaw/neural-lab/worlds/*.json`
- World save endpoint: `/api/sim/world/save` — saves walls + objects + environment
- World load endpoint: `/api/sim/world/load` — loads from file
- World list endpoint: `/api/sim/world/list` (also `/api/sim/worlds`)
- The bottom-right 💾📂🗑️ buttons in viewport = save/load/clear world layout
- The `simWorldSelect` dropdown in control bar = separate load path
- `simEnvSelect` = environment presets (hide_and_seek, foraging, maze, open_field)
- Both paths call different code — need to merge into ONE world picker
- World files include: name, environment base, walls[], objects[]
- PM1 file is 7KB with full maze layout

### Key Fix Plan (for next session)
1. Replace dual world/env system with single "Map Picker" — shows built-in envs AND saved worlds together
2. Add delete button per saved world
3. "New Game" button = stop + clear all + reset to empty arena
4. Load world = immediately show in viewport (no need to start sim)
5. Preview thumbnails would be nice but not essential

### Git State
- Latest commit: `86fa0aa` (seeker scoring fix)
- All backed up to GitHub