Gym icon indicating copy to clipboard operation
Gym copied to clipboard

Add CUBE-standard MVP with OSWorld.

Open ffrujeri opened this issue 8 months ago • 2 comments

Summary

Adds a CUBE-backed resources server and cube agent so NeMo Gym can run multi-step tool + environment rollouts (e.g. OSWorld via CUBE), integrated with ng_collect_rollouts and the existing head-server / verify / aggregate-metrics flow.

Also adds optional per-step debug on the rollout client (+debug_each_step) and best-effort cleanup of live CUBE tasks when the resources server shuts down.

image image

What changed

CUBE resources server (resources_servers/cube/)

  • HTTP surface: /seed_session, /step, /verify, /close, /aggregate_metrics.
  • Pluggable env_domain (e.g. osworld) via registry and adapters; shared schemas for verify / step / seed.
  • Config, example JSONL, requirements, README, and HTML docs (architecture + primitives).
  • Shutdown: close_all_open_environments() closes every tracked CUBE task on ASGI lifespan teardown (chained after the router’s existing lifespan, including profiling). Blocking task.close() runs in a thread pool. atexit registers the same closer as a fallback. Does not run on SIGKILL / kill -9 or hard crashes.

Cube agent (responses_api_agents/cube_agent/)

  • Agent loop: seed session → policy /v1/responses → resources /step → verify; options such as render_last_n_obs, transitions vs flattened output, etc.

Rollout collection (nemo_gym/rollout_collection.py)

  • +debug_each_step=true: sends debug_each_step on each POST /run body.
  • cube_agent attaches debug_step_events at the top level of the verify payload (not inside the OpenAI-shaped response object) so it survives JSON round-trip.
  • ng_collect_rollouts prints one line per step on the client terminal, then removes debug_step_events before writing JSONL.
  • +debug=true stays separate: per-/run timing, tqdm, aiohttp request debug, logging.

Schemas

  • CubeAgentVerifyRequest / CubeAgentVerifyResponse: optional debug_step_events.
  • cube_agent: _cube_rollout returns (response, events); run() merges debug_step_events into the verify request.

Tests

  • resources_servers/cube/tests/test_server_shutdown.py: close_all_open_environments closes tasks and clears maps.
  • Additional tests under resources_servers/cube/tests/ and responses_api_agents/cube_agent/tests/ as applicable.

How to verify

  1. Bring up services per resources_servers/cube/README.md.
  2. Run ng_collect_rollouts with +debug_each_step=true (and optionally +debug=true) and confirm per-step lines on the collect_rollouts process stdout.
  3. Stop the CUBE resources server gracefully (Ctrl+C / SIGTERM) and confirm environments / QEMU teardown behaves as expected (subject to CUBE/OS timing).

Limitations

  • SIGKILL, kill -9, and OOM kills cannot run Python teardown.
  • Uvicorn uses a short graceful shutdown window; in-flight HTTP handlers may still race shutdown.
  • Aggregate metrics may show mean/debug_each_step because the boolean flag can appear on verify payloads; that is independent of per-step event printing (which relies on top-level debug_step_events).

ffrujeri avatar Apr 05 '26 18:04 ffrujeri

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

copy-pr-bot[bot] avatar Apr 05 '26 18:04 copy-pr-bot[bot]

Hey Felipe — great work on this integration, the overall design is solid.

One note on resources_servers/cube/domains/osworld/bootstrap.py: I'm assuming this file is here for rapid iteration on your side, which totally makes sense. Just confirming we'll take ownership of this layer on the CUBE side.

osworld-cube already exposes the standard CUBE benchmark pattern, so the 90 lines of manual wiring here can be replaced with:

from osworld_cube.benchmark import OSWorldBenchmark, OSWorldTestSet
from osworld_cube.computer import ComputerConfig

benchmark = OSWorldBenchmark(
    default_tool_config=ComputerConfig(action_space=..., require_a11y_tree=True),
    test_set_name=OSWorldTestSet.TEST_SMALL,
)
benchmark.setup()
task_configs = list(benchmark.get_task_configs())

OSWorldBenchmark already handles VM backend instantiation, repo cloning, metadata loading, and task config generation internally. The _import_class, _parse_test_set, _cfg_extra helpers, ComputerConfig construction, and vm_backend wiring are all things benchmark.setup() takes care of.

We're opening a PR on cube-standard to expose a CubeResourcesServer that wraps this — so from NemoGym's side you'll just import it and point your YAML config at it. The domains/ directory and registry can then go away entirely.

recursix avatar Apr 08 '26 17:04 recursix