File size: 2,202 Bytes
80d8c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Server Map - `server/app.py`

> FastAPI backend with REST + WebSocket endpoints. The normal path now uses
> the real `ReplicaLabEnv`; `_StubEnv` remains only as a fallback if the env
> package cannot be imported.
>
> **Tasks implemented:** API 01-09, 13, 15

## Environment path

### `ReplicaLabEnv`
Primary environment implementation imported from
`replicalab.env.replicalab_env`.

### `_StubEnv`
Legacy fallback kept so the server can still boot if the real env import
fails. It is no longer the intended local or Docker runtime.

### `_make_env()`
Factory that prefers `ReplicaLabEnv` and falls back to `_StubEnv` only on
import failure.

## REST endpoints

### `GET /health`
Returns a liveness payload. When the real env path is active, the response
includes `env: "real"`.

### `POST /reset`
Starts a new episode and returns:

- `session_id`
- `episode_id`
- typed `Observation`

### `POST /step`
Submits a typed `ScientistAction` and returns `StepResult`.

When `done=true`, the terminal `StepResult` is also used to build the replay
log so `reward_breakdown`, `judge_notes`, and `verdict` stay aligned with the
real env result.

### `GET /scenarios`
Returns the available scenario families and supported difficulties.

### `GET /replay/{episode_id}`
Returns the stored `EpisodeLog` for a completed episode or 404 if not found.

## WebSocket endpoint

### `WS /ws`
Per-connection isolated environment session supporting:

- `reset`
- `step`
- `ping`

Idle timeout and disconnect cleanup are implemented and verified.

## Session management

| Store | Purpose |
| --- | --- |
| `_sessions` | Active REST sessions |
| `_replay_store` | Completed episode logs |

## Key helpers

| Function | Purpose |
| --- | --- |
| `_build_episode_log(episode_id, state, result)` | Build replay log from final state and terminal step result |
| `_touch(session_id)` | Refresh REST session last-active timestamp |
| `_cleanup_stale_sessions()` | Remove expired REST sessions |

## Current deployment state

- Local OpenEnv validation passes
- Local Docker build and run verification passes
- HF Spaces metadata is present in the root `README.md` and root `Dockerfile`
- Live hosted verification remains `API 10`