HF Space State Persistence Issue
Problem
RAM usage and rewards stay the same after pressing step in HF Space app, regardless of action type/intensity.
Root Cause Analysis
✅ Backend is working correctly - direct environment tests confirm:
- Step 1 (reduce_ram 0.8): 80% → 72% ✓
- Step 2 (reduce_ram 0.8): 72% → 64% ✓
- Rewards update correctly: 0.080 each step ✓
❌ Issue is in HF Space app request handling:
- Each HTTP POST request may be creating a new environment instance
- State is not persisting across requests
- Session management might not be working correctly
Solution
For HF Space Users:
- Clear browser cache - Sometimes old state is cached
- Use WebSocket /ws endpoint instead of REST (this should be automatic)
- Check browser console for HTTP 422 errors
- Refresh the page completely before starting new episode
For Developers:
The OpenEnv framework manages this automatically via:
POST /reset → Creates new environment instance
WebSocket /ws → Maintains session state across multiple steps
POST /step → Updates persistent environment state
The 422 errors in server logs indicate malformed requests from HF Space. Check:
- Request body format matches EnergyOptimizationAction schema
- Content-Type header is application/json
- Session/connection is properly maintained
Verification (Local Testing)
✅ Direct Python test: PASSED ✅ Environment state updates: CONFIRMED ✅ Reward calculation: WORKING ✅ RAM reduction logic: FUNCTIONAL
Test Summary:
- Reset: RAM=80%, Energy=8.0
- Step1: RAM→72%, Reward=0.08
- Step2: RAM→64%, Reward=0.08
- Status: ✅ WORKING CORRECTLY
Next Steps
- Rebuild HF Space Docker image to ensure latest code
- Test with curl/Postman to verify API works
- Check WebSocket connection in browser dev tools