Skip to content

feat(osworld): agent support for the FlashREINFORCE OSWorld recipe on AgentENV - #6458

Open
jinglinglingling wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
jinglinglingling:linglinj/osworld-flashreinforce-v2
Open

jinglinglingling wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
jinglinglingling:linglinj/osworld-flashreinforce-v2

Conversation

@jinglinglingling

@jinglinglingling jinglinglingling commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in options to osworld_agent for the FlashREINFORCE OSWorld recipe and a self-contained profile that enables them on AgentENV.

  • Snapshot groups (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.
    • The snapshot is deleted once every rollout of the group has claimed it and finished (shielded against client-disconnect cancellation), or fork_claim_timeout_s after it is ready.
    • Requires num_workers=1 (enforced via OSWorldAgent.multiple_workers_unsupported_reason()). Moving group coordination and OSWorld configs off legacy_agent onto an environment server + agent sessions is tracked in [OSWorld] Migrate OSWorld agent and configs off legacy_agent relay to environment server + agent sessions #7023.
    • Rows without group identity log a one-time warning and get an ordinary fresh guest; rows re-sent after their group closed also get a fresh guest.
    • fork_post_setup_settle_s waits between the setup and the snapshot.
    • Snapshot names start with osworld-group-, so list_snapshots("osworld-group-") finds any a crashed agent left behind.
  • Sync facade (nemo_gym/sandbox/api.py): Sandbox.start(spec, snapshot_id=...) and Sandbox.snapshot(name=...) wrap the existing AsyncSandbox methods.
  • Template weights (sandbox_image_weights): weighted sandbox_spec.image choices, for example AgentENV templates, drawn per rollout; the rollouts of a group share their group's draw.
  • Canonical Nemotron agent (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 optional canonical_harness.root + sha256 pin override if callers want to load an external checkout).
    • Observations put Task: <instruction> and the screenshot first, then each screenshot inside <tool_response> after the previous step's execution feedback.
    • Every served assistant output is replayed.
    • Screenshots follow a K/S window: the first image is pinned and older images are replaced in place by the omission marker.
  • Frozen evaluators (frozen_evaluator_root, frozen_evaluators.py): per-task getters and metrics under <root>/<task_id>/{getters,metrics}/*.py are 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. Missing frozen_evaluator_root raises FileNotFoundError. Tasks with metadata.binary_final_reward: true score 1 only on a full score, otherwise 0.
  • AgentENV osworld-v2 guest compatibility & setup hardening (sandbox_provider.py, client.py):
    • On fresh boots (snapshot_id is None, inherited by snapshot siblings), disables the stale duplicate dl.google.com/linux/chrome/deb apt source (NO_PUBKEY rc=100) and installs a non-root /usr/local/bin/update-desktop-database wrapper on the osworld-v2 template, and disables LibreOffice WarnAlienFormat prompts for silent .xlsx saves.
    • Expands _sanitize_setup_task_config() to preserve killall gnome-terminal-server when installed and fall back to foreground pkill -x gnome-terminal- (matching Linux's 15-char comm name), guard Thunderbird / http.server / generic pkill -f self-matches, escape literal newlines in python -c strings, and make volcano_registry.py idempotent.
    • Centers the mouse pointer off (0, 0) immediately before env.evaluate() so evaluator pyautogui calls do not trigger FAILSAFE.
  • Config: benchmarks/osworld/configs/osworld_nemo_rl_agentenv_flashreinforce.yaml enables all of the above on AgentENV using the bundled canonical prompt/parser/feedback modules (no external harness checkout required), and exposes AGENTENV_TEMPLATE_WEIGHTS, OSWORLD_RLVR_FUNCTIONS_ROOT, OSWORLD_PARSE_RETRIES (default 1 for training, overridable for evaluation), and OSWORLD_CONTEXT_PROMPT_TOKEN_LIMIT.

Compatibility

  • New opt-in options default to off: fork_rollout_groups defaults to false, sandbox_image_weights to {}, frozen_evaluator_root to null.
  • Three guest/evaluator hardening fixes apply beyond the FlashREINFORCE profile and can change scores compared with earlier Gym OSWorld runs:
    1. Pre-evaluation pointer centering (_center_pointer_before_evaluate) runs before every env.evaluate() across all osworld_agent configurations (preventing pyautogui.FAILSAFE aborts on valid trajectories).
    2. LibreOffice WarnAlienFormat configuration (_SAVE_CONFIG_SCRIPT) runs on every fresh guest started through sandbox_provider, for all templates.
    3. _sanitize_setup_task_config runs on every env.reset() across all osworld_agent configurations (including evaluator postconfig commands).
  • Snapshot groups need a provider whose snapshots keep running processes (provider_capabilities(provider).snapshot_keeps contains "processes": E2B / AgentENV) and num_workers=1.
  • No changes to the core sandbox API beyond the two sync wrappers; no new external dependencies.

Verification

  • Full osworld_agent + sandbox unit 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-v2 fresh-boot setup, killall sanitizer, env.close() guard, num_workers > 1 refusal, and pre-evaluation pointer centering).
  • ruff check and ruff format --check pass across all modified and added files.
  • Verified on real AgentENV runs: 200-step FlashREINFORCE training (32 prompts x 4 forked rollouts per step via feat(osworld): FlashREINFORCE B32/N4 OSWorld recipe on AgentENV RL#5304) and full 361-task x 4 rollout osworld-v2 evaluation (non-group rows).
  • Follow-up for migrating OSWorld agent/configs off legacy_agent and moving group coordination to an environment server: [OSWorld] Migrate OSWorld agent and configs off legacy_agent relay to environment server + agent sessions #7023.

@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added risk:high Autobot PR risk: high feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior community-request Issue reported or requested by someone from the community labels Nov 19, 2026
@jinglinglingling
jinglinglingling force-pushed the linglinj/osworld-flashreinforce-v2 branch from c965587 to 865e000 Compare November 26, 2026 04:39
@jinglinglingling jinglinglingling changed the title feat(osworld): FlashREINFORCE same-state forks, canonical harness and frozen evaluators feat(osworld): FlashREINFORCE snapshot groups, canonical harness and frozen evaluators Nov 26, 2026
@jinglinglingling
jinglinglingling marked this pull request as ready for review November 26, 2026 04:39
… 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]>
@jinglinglingling
jinglinglingling force-pushed the linglinj/osworld-flashreinforce-v2 branch from 865e000 to 7edba01 Compare November 26, 2026 06:14
@jinglinglingling jinglinglingling changed the title feat(osworld): FlashREINFORCE snapshot groups, canonical harness and frozen evaluators feat(osworld): agent support for the FlashREINFORCE OSWorld recipe on AgentENV Nov 26, 2026
policy_model:
responses_api_models:
vllm_model:
propagate_context_overflow_errors: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. Which environment server should own the episode for this profile? Could the OSWorld agent use agent sessions, as in the add-harness skill ("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
  2. ForkGroupRegistry and _claim_group_snapshot in OSWorldAgent.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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened follow-up issue #7023 (tagged @yaoyu-33) to track migrating osworld_agent and its configs off legacy_agent onto an environment server + agent sessions and moving ForkGroupRegistry coordination into the environment server, and linked it in the PR description.

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • RFC0015 in the config comment (line 6) and in the canonical_agent.py docstring (line 10) is an internal reference. The docstring already describes the layout, so could the reference go?
  • client.py line 1844 names prepare_osworld_fork. The function is prepare_osworld_snapshot.
  • New lines use Optional[...] and Dict[...]. AGENTS.md asks for X | None and dict.

expiry: Optional["asyncio.Task[None]"] = None


class ForkGroupRegistry:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
jinglinglingling added a commit to jinglinglingling/RL that referenced this pull request Dec 1, 2026
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]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added needs-review PR is ready for code review and waiting on a reviewer waiting-on-maintainers Waiting on maintainers to respond labels Dec 1, 2026

@yfw yfw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

  1. (C1) Please wrap the snapshot delete in finish() in asyncio.shield (fork_groups.py:146), so a client that disconnects cannot leave the group's snapshot in AgentENV forever.
  2. (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.
  3. (C3) Please raise when frozen_evaluator_root is not a directory, so a wrong or unmounted root cannot silently fall back to the built-in evaluators.
  4. (C4) Please guard env.close() in prepare_osworld_snapshot, so a failing close cannot lose the id of a snapshot that was already taken.
  5. (C7) Please run ruff format on the two blocks that the last commit added, so the Lint check passes.
  6. (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_agent configuration, that the LibreOffice change applies to every fresh guest started through sandbox_provider, and that they can change scores.
  7. (C9) Please keep killall gnome-terminal-server where the guest has it and otherwise run pkill -x gnome-terminal- in the foreground, so four tasks that read ~/.bash_history do 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

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Dec 1, 2026
…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]>
jinglinglingling added a commit to jinglinglingling/RL that referenced this pull request Dec 1, 2026
…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]>
@jinglinglingling

jinglinglingling commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @ffrujeri and @yfw for the thorough reviews! Replied inline to each thread above. For the review-body nits (commits f2111e2f0 & 919536ec6):

  • Removed internal RFC0015 references, fixed prepare_osworld_fork -> prepare_osworld_snapshot in client.py, and modernized all added annotations to PEP 585/604 (X | None, dict, list, tuple, set, deque).
  • Updated the PR description with Compatibility impact (C8) and real AgentENV verification details.
  • Re-ran pytest responses_api_agents/osworld_agent/tests/ tests/unit_tests/sandbox/test_sandbox.py (811 passed, 3 skipped, 0 failed) and ruff check / ruff format --check (all passed).

@github-actions github-actions Bot removed the community-request Issue reported or requested by someone from the community label Dec 1, 2026
@yfw

yfw commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

/ok to test 919536e

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team December 3, 2026 01:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants