Repository navigation
feat(osworld): agent support for the FlashREINFORCE OSWorld recipe on AgentENV - #6458
jinglinglingling wants to merge 4 commits into
Conversation
c965587 to
865e000
Compare
… AgentENV Add the FlashREINFORCE profile osworld_nemo_rl_agentenv_flashreinforce.yaml. A group's active siblings share one task setup through a sandbox snapshot (fork_groups.py) and start from it; AgentENV template weights spread groups across images; the canonical-harness runner replays the frozen agent and feedback prompts (canonical_agent.py); and RLVR frozen evaluators score each rollout with a binary final reward (frozen_evaluators.py). The sync Sandbox facade gains start(snapshot_id=) and snapshot(). Signed-off-by: Linglin Jing <[email protected]>
865e000 to
7edba01
Compare
| policy_model: | ||
| responses_api_models: | ||
| vllm_model: | ||
| propagate_context_overflow_errors: true |
There was a problem hiding this comment.
Hi. Could this profile move off the legacy_agent relay? We do not accept new configs that use it.
gym env resolve on this file ends in osworld_nano_omni_environment_server → legacy_agent → osworld_nano_omni_agent. The relay comes in through config_paths (osworld_agent_nano_omni_agentenv.yaml → osworld_agent_nano_omni.yaml → osworld_agent.yaml), so it does not show in this diff.
- Which environment server should own the episode for this profile? Could the OSWorld agent use agent sessions, as in the
add-harnessskill ("move an existing agent off the legacy /run path")? Background: https://gitlab-master.nvidia.com/yuya/how-to-run/-/blob/main/runbooks/gym-resources-server-env-server-migration.md ForkGroupRegistryand_claim_group_snapshotinOSWorldAgent.run()order the rollouts of a prompt group and free the group's snapshot. Could the environment server own that order, so the agent server keeps only the loop of model and tool calls?
There was a problem hiding this comment.
If this move is bigger than this PR, a follow-up issue is fine. Could you open one for the OSWorld agent and its configs, link it here, and tag @yaoyu-33?
There was a problem hiding this comment.
ffrujeri
left a comment
There was a problem hiding this comment.
Thanks for this. Some questions are inline.
Could you also add a real run to the PR description? For example: one prompt group on AgentENV, with the logs that show one snapshot created, each guest started from it and the snapshot deleted, plus one row without group identity. The verification section lists unit tests only.
Nits:
RFC0015in the config comment (line 6) and in thecanonical_agent.pydocstring (line 10) is an internal reference. The docstring already describes the layout, so could the reference go?client.pyline 1844 namesprepare_osworld_fork. The function isprepare_osworld_snapshot.- New lines use
Optional[...]andDict[...]. AGENTS.md asks forX | Noneanddict.
| expiry: Optional["asyncio.Task[None]"] = None | ||
|
|
||
|
|
||
| class ForkGroupRegistry: |
There was a problem hiding this comment.
This registry lives in the memory of one worker. The OSWorld agent supports num_workers > 1, so the rollouts of one group can reach different workers. Then each worker sets up and snapshots the task on its own, and the rollouts do not start from the same desktop. No worker sees every claim, so each snapshot stays until fork_claim_timeout_s (2 h).
How should this work at scale? Could whoever sends out the group own its snapshot (see the thread on the config)?
There was a problem hiding this comment.
Good catch. In f2111e2f0, OSWorldAgent.multiple_workers_unsupported_reason() now refuses num_workers > 1 before uvicorn starts whenever fork_rollout_groups=true, ForkGroupRegistry's docstring notes the num_workers=1 requirement, and test_fork_refuses_multiple_workers covers it. Moving group coordination out of the agent worker into an environment server is tracked in #7023.
| def fork_claim_from_request(request_extra: Mapping[str, Any], task_id: str) -> Optional[ForkClaim]: | ||
| """Read the group identity the trainer stamps on each row; None when the row has none.""" | ||
| group_id = request_extra.get("_ng_group_id") | ||
| active = request_extra.get("_ng_active_generation_indices") |
There was a problem hiding this comment.
Nothing in Gym writes _ng_active_generation_indices; only NVIDIA-NeMo/RL#5304 does. So under gym eval run every row gets a fresh guest, with no warning. Could Gym define and document this field, with a Gym name instead of the trainer's "generation" term?
There was a problem hiding this comment.
Done in f2111e2f0: defined and documented Gym constants in fork_groups.py using Gym's rollout terminology (GROUP_ROLLOUT_INDICES_KEY = "_ng_group_rollout_indices", keeping _ng_active_generation_indices as a backward-compatible fallback), synced NVIDIA-NeMo/RL#5304 to stamp _ng_group_rollout_indices, and added a one-time warning in OSWorldAgent.run() when fork_rollout_groups=true receives rows without group identity.
|
|
||
| LOG = logging.getLogger("nemo_gym.osworld_agent") | ||
|
|
||
| # Snapshots never expire on their own; this name prefix lists any a crashed agent left behind. |
There was a problem hiding this comment.
Who deletes a snapshot that a crash, a restart or a forced cancel leaves behind? A manual list_snapshots cleanup does not scale to training runs. Can the provider expire snapshots, as ttl_s does for sandboxes?
There was a problem hiding this comment.
Checked the E2B and OpenSandbox providers: create_snapshot(name) does not currently support a server-side snapshot TTL (unlike sandbox ttl_s). With asyncio.shield in finish() (C1) and the env.close() guard in prepare_osworld_snapshot() (C4), in-process leak paths (client disconnects and teardown errors) are closed. Provider-side snapshot TTL / automated orphan cleanup for hard process crashes is tracked in #7023.
| task_timeout: ${oc.decode:${oc.env:OSWORLD_TASK_TIMEOUT,7200}} | ||
| agent_kwargs: | ||
| canonical_harness: | ||
| root: ${oc.env:OSWORLD_CANONICAL_HARNESS_ROOT} |
There was a problem hiding this comment.
Where does this harness directory come from? The sha256 pins show which files ran, but others cannot get the files. Could the README name the source repository and commit?
There was a problem hiding this comment.
Resolved in 919536ec6: bundled the canonical system prompts, response parser, and command-execution feedback formatter directly into Gym (canonical_prompt_parser.py and execution_feedback.py, Apache-2.0) and made CanonicalNemotronAgent and osworld_nemo_rl_agentenv_flashreinforce.yaml self-contained by default—no external harness directory or OSWORLD_CANONICAL_* env vars are required (optional canonical_harness.root + sha256 override remains supported).
…nd eval overrides Restore full osworld-v2 evaluation and training parity on AgentENV: - Apply osworld-v2 guest compatibility repairs once on fresh boot (snapshot_id is None) in GymSandboxDesktopProvider.start_emulator(): disable the stale duplicate dl.google.com/linux/chrome/deb apt source (NO_PUBKEY rc=100), install a non-root update-desktop-database wrapper, and disable LibreOffice WarnAlienFormat prompts for silent xlsx saves. - Expand _sanitize_setup_task_config() in client.py to rewrite missing killall gnome-terminal-server commands to detached pkill -x, guard Thunderbird/http.server/generic pkill -f self-matches, escape literal newlines in python -c strings, and make volcano_registry.py idempotent. - Center the mouse pointer off (0, 0) before env.evaluate() so evaluator pyautogui calls do not trip FAILSAFE. - Allow OSWORLD_PARSE_RETRIES env override (default 1 for training, overridable to 8 in eval) alongside OSWORLD_CONTEXT_PROMPT_TOKEN_LIMIT. Signed-off-by: Linglin Jing <[email protected]>
Point 3rdparty/Gym-workspace/Gym at NVIDIA-NeMo/Gym#6458 (6f7223534), adding AgentENV osworld-v2 guest compatibility repairs, setup/postconfig command sanitization, pre-evaluation pointer centering, and the OSWORLD_PARSE_RETRIES override. Signed-off-by: Linglin Jing <[email protected]>
yfw
left a comment
There was a problem hiding this comment.
SHIP WITH CARE. This review found four risks: two to fix before the profile trains at scale (C1-C2), one reward bug in the last commit (C9) and one CI failure caused by this PR (C7). The rest are two smaller fixes (C3-C4) and one PR description fix (C8).
- (C1) Please wrap the snapshot delete in
finish()inasyncio.shield(fork_groups.py:146), so a client that disconnects cannot leave the group's snapshot in AgentENV forever. - (C2) Please make
clear_frozen_evaluators()also remove package attributes and helpers imported while scoring (frozen_evaluators.py:166-167), so the next task in a Ray worker cannot score with the previous task's helper. - (C3) Please raise when
frozen_evaluator_rootis not a directory, so a wrong or unmounted root cannot silently fall back to the built-in evaluators. - (C4) Please guard
env.close()inprepare_osworld_snapshot, so a failing close cannot lose the id of a snapshot that was already taken. - (C7) Please run
ruff formaton the two blocks that the last commit added, so the Lint check passes. - (C8) Please correct the Compatibility bullet in the PR description to say that the pointer centering and the wider setup sanitizer apply to every
osworld_agentconfiguration, that the LibreOffice change applies to every fresh guest started throughsandbox_provider, and that they can change scores. - (C9) Please keep
killall gnome-terminal-serverwhere the guest has it and otherwise runpkill -x gnome-terminal-in the foreground, so four tasks that read~/.bash_historydo not score 0 for a correct trajectory.
The rest looks solid: the new options (fork_rollout_groups, sandbox_image_weights, frozen_evaluator_root) default to off, the two sync sandbox wrappers match AsyncSandbox and are keyword-only, and the snapshot groups reuse the existing sandbox snapshot API.
Process: the Lint check fails at this head (C7). DCO and copyright pass, and there is no merge conflict. Test CI has not run yet. It needs an ok to test comment from a maintainer, with the full head SHA 6f72235345f48f175131ffc42c03c5e209597074. Locally, the osworld_agent tests pass at this head in the component's own environment (693 passed, on CPU, without AgentENV), and tests/unit_tests/sandbox/test_sandbox.py passes.
Generated by Claude Code
…up, frozen evaluators, sanitizer, lint) Fixes from @yfw and @ffrujeri review comments: - Shield ForkGroupRegistry.finish() snapshot deletion against client-disconnect cancellation (C1). - Clear relative-imported package attributes and late-imported task-local helpers in clear_frozen_evaluators() (C2). - Raise FileNotFoundError when frozen_evaluator_root does not exist instead of silently falling back to built-in evaluators (C3). - Guard env.close() in prepare_osworld_snapshot() so close errors do not discard the created snapshot id (C4). - Fix killall gnome-terminal-server sanitizer to preserve killall when present and fall back to foreground pkill -x gnome-terminal- (15-char comm limit) (C9). - Refuse num_workers > 1 via multiple_workers_unsupported_reason() when fork_rollout_groups is enabled. - Define and document _ng_group_rollout_indices (keeping _ng_active_generation_indices fallback) and log a one-time warning when fork_rollout_groups receives rows without group identity. - Remove internal RFC0015 references, fix prepare_osworld_snapshot typo, modernize PEP 585/604 typing on added code, and apply ruff format (C7). Signed-off-by: Linglin Jing <[email protected]>
…k in Gym Make CanonicalNemotronAgent and the FlashREINFORCE OSWorld profile self-contained without requiring an external harness checkout: - Vendor the canonical system prompts and response parser in canonical_prompt_parser.py. - Vendor the command-execution feedback normalizer and renderer in execution_feedback.py. - Default CanonicalNemotronAgent to the bundled modules when canonical_harness.root is omitted, while retaining optional sha256-pinned external directory overrides. - Remove required OSWORLD_CANONICAL_* env vars from osworld_nemo_rl_agentenv_flashreinforce.yaml. Signed-off-by: Linglin Jing <[email protected]>
…le for PR #6458 - Rename NEMO_GYM_ACTIVE_GENERATION_INDICES_KEY to NEMO_GYM_GROUP_ROLLOUT_INDICES_KEY (_ng_group_rollout_indices) to match Gym's documented fork-group field name. - Update 3rdparty/Gym-workspace/Gym pin to 919536ec6 (NVIDIA-NeMo/Gym#6458 review fixes + bundled canonical prompt/parser/feedback). Signed-off-by: Linglin Jing <[email protected]>
|
Thanks @ffrujeri and @yfw for the thorough reviews! Replied inline to each thread above. For the review-body nits (commits
|
|
/ok to test 919536e |
Summary
Adds opt-in options to
osworld_agentfor the FlashREINFORCE OSWorld recipe and a self-contained profile that enables them on AgentENV.fork_rollout_groups,fork_groups.py): the first rollout of a prompt group to arrive runs the task setup on one guest and snapshots it with the existing sandbox snapshot API (Sandbox.snapshot,wait_snapshot_ready). Every rollout the group dispatched together (_ng_group_rollout_indices, with backward-compatible fallback to_ng_active_generation_indices) then starts its guest from that snapshot (start(snapshot_id=...)), so all of them begin from the same desktop state.fork_claim_timeout_safter it is ready.num_workers=1(enforced viaOSWorldAgent.multiple_workers_unsupported_reason()). Moving group coordination and OSWorld configs offlegacy_agentonto an environment server + agent sessions is tracked in [OSWorld] Migrate OSWorld agent and configs off legacy_agent relay to environment server + agent sessions #7023.fork_post_setup_settle_swaits between the setup and the snapshot.osworld-group-, solist_snapshots("osworld-group-")finds any a crashed agent left behind.nemo_gym/sandbox/api.py):Sandbox.start(spec, snapshot_id=...)andSandbox.snapshot(name=...)wrap the existingAsyncSandboxmethods.sandbox_image_weights): weightedsandbox_spec.imagechoices, for example AgentENV templates, drawn per rollout; the rollouts of a group share their group's draw.canonical_agent.py,canonical_prompt_parser.py,execution_feedback.py,CanonicalNemotronAgent): self-contained canonical system prompts, XML/code response parser, and command-execution feedback formatter bundled directly in Gym (with optionalcanonical_harness.root+ sha256 pin override if callers want to load an external checkout).Task: <instruction>and the screenshot first, then each screenshot inside<tool_response>after the previous step's execution feedback.frozen_evaluator_root,frozen_evaluators.py): per-task getters and metrics under<root>/<task_id>/{getters,metrics}/*.pyare loaded for their task, replace same-named built-in evaluators, and are cleared (including relative-imported package attributes and late-imported helpers) before the worker runs another task. Missingfrozen_evaluator_rootraisesFileNotFoundError. Tasks withmetadata.binary_final_reward: truescore 1 only on a full score, otherwise 0.osworld-v2guest compatibility & setup hardening (sandbox_provider.py,client.py):snapshot_id is None, inherited by snapshot siblings), disables the stale duplicatedl.google.com/linux/chrome/debapt source (NO_PUBKEYrc=100) and installs a non-root/usr/local/bin/update-desktop-databasewrapper on theosworld-v2template, and disables LibreOfficeWarnAlienFormatprompts for silent.xlsxsaves._sanitize_setup_task_config()to preservekillall gnome-terminal-serverwhen installed and fall back to foregroundpkill -x gnome-terminal-(matching Linux's 15-char comm name), guard Thunderbird /http.server/ genericpkill -fself-matches, escape literal newlines inpython -cstrings, and makevolcano_registry.pyidempotent.(0, 0)immediately beforeenv.evaluate()so evaluatorpyautoguicalls do not triggerFAILSAFE.benchmarks/osworld/configs/osworld_nemo_rl_agentenv_flashreinforce.yamlenables all of the above on AgentENV using the bundled canonical prompt/parser/feedback modules (no external harness checkout required), and exposesAGENTENV_TEMPLATE_WEIGHTS,OSWORLD_RLVR_FUNCTIONS_ROOT,OSWORLD_PARSE_RETRIES(default1for training, overridable for evaluation), andOSWORLD_CONTEXT_PROMPT_TOKEN_LIMIT.Compatibility
fork_rollout_groupsdefaults tofalse,sandbox_image_weightsto{},frozen_evaluator_roottonull._center_pointer_before_evaluate) runs before everyenv.evaluate()across allosworld_agentconfigurations (preventingpyautogui.FAILSAFEaborts on valid trajectories).WarnAlienFormatconfiguration (_SAVE_CONFIG_SCRIPT) runs on every fresh guest started throughsandbox_provider, for all templates._sanitize_setup_task_configruns on everyenv.reset()across allosworld_agentconfigurations (including evaluator postconfig commands).provider_capabilities(provider).snapshot_keepscontains"processes": E2B / AgentENV) andnum_workers=1.Verification
osworld_agent+sandboxunit test suite:811 passed, 3 skipped(covering snapshot groups including disconnect-cancellation shielding, frozen evaluators including relative/late helper cleanup and missing-root errors, built-in and sha256-pinned canonical agent,osworld-v2fresh-boot setup,killallsanitizer,env.close()guard,num_workers > 1refusal, and pre-evaluation pointer centering).ruff checkandruff format --checkpass across all modified and added files.osworld-v2evaluation (non-group rows).legacy_agentand moving group coordination to an environment server: [OSWorld] Migrate OSWorld agent and configs off legacy_agent relay to environment server + agent sessions #7023.