Skip to content

feat(osworld): OSWorld environment stack - #4209

Merged
yfw merged 29 commits into
NVIDIA-NeMo:mainfrom
jinglinglingling:linglinj/flashreinforce-agentenv-osworld
Nov 20, 2026
Merged

yfw merged 29 commits into
NVIDIA-NeMo:mainfrom
jinglinglingling:linglinj/flashreinforce-agentenv-osworld

Conversation

@jinglinglingling

@jinglinglingling jinglinglingling commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in options to osworld_agent for the Nemotron Nano Omni OSWorld training recipe, plus a NeMo RL training profile that sets them through OSWORLD_* environment variables. Every new option defaults to the current behavior.

  • history_layout: cc_chat (adapter_agents.py): chat-style history. Every turn stays a chat turn, the first screenshot is always kept, and older screenshots are replaced by an omission marker so the image count cycles between cc_keep_last_groups + 1 and cc_max_active_images. Options: cc_keep_last_groups (>= 1), cc_max_active_images, cc_actions_per_chunk, cc_chunk_turns_as_generated (continue a chunk from the generated tokens), and cc_prompt_token_guard (start a new chunk before a prompt would exceed this many tokens).
  • assistant_history_replay (adapter_agents.py): fixes a training mismatch on main. main rebuilds every earlier assistant turn from the parsed fields (<think>{thought}</think> plus ## Action:), which drops the ## Code block and anything else the model wrote, so the replayed turn is not the model's own output. Under token capture the next prompt then no longer extends the previous prompt plus generation, and one rollout splits into many physical traces. raw_live replays the served output, reasoning included, inside the live window; raw_full also keeps the model's original Code (before coordinate projection) in compacted turns. normalized (the current behavior) stays the default; cc_chat requires raw_full, and the NeMo RL profile sets it.
  • legacy_response_parser (legacy_parser.py): the OSWorld mm_agents Nemotron response parser, including its Action header completion. Source below.
  • Response handling: validate_python_syntax, require_clean_finish, and train_invalid_terminal_call (train the rejected generation that ends an episode in FAIL, with the episode reward).
  • Rollout ending: unterminated_episode_policy=fail (execute FAIL when the policy never terminates, as the reference agent does), mask_unterminated, mask_context_limit, and rollout_timeout_s (per-rollout agent-loop budget; reaching it ends the rollout as a timeout, which is not trained).
  • reward_mode: binary (default) or raw (the evaluator's partial score).
  • Episode-end metrics: each row reports done, agent_fail, forced_fail, unterminated or aborted (no terminal action and an infrastructure failure) as episode_end_* scalars.
  • Served-call output under token capture: loss_member marks a rejected terminal call as accepted history when train_invalid_terminal_call is set. ng_trajectory is a typed TrajectoryRecord with one turn per accepted call and ModelCallRef(model_ref, response_id), so the trainer can join accepted calls to capture records. A reply that context_prompt_token_limit rejects is not named as the terminal; the last accepted call is.
  • Exact trace: each model call's evidence now carries its response_id. The exact-trace output itself is unchanged from main.
  • Configs: osworld_nemo_rl_opensandbox.yaml (NeMo RL profile; also sets propagate_context_overflow_errors: true on the policy server so context refusals reach the agent as errors), osworld_nemo_rl_agentenv.yaml (NeMo RL profile for the AgentEnv provider), and transport_backend: httpx in osworld_opensandbox.yaml.

Source of copied code

parse_response_to_cot_and_action and project_coordinate_to_absolute_scale in responses_api_agents/osworld_agent/legacy_parser.py are copied, with logging changed, from mm_agents/nvidia/nemotron_agent.py in terrykong/OSWorld at commit 5d8c93592be588ab8e9909bed82f3b480fd4f533 (Apache-2.0, a fork of xlang-ai/OSWorld).

Compatibility

  • With no new option set, the agent contract IDs are the same as main. New result fields are the episode_end_* scalars on every row, and ng_trajectory when token capture is on.
  • osworld_opensandbox.yaml switches the OpenSandbox transport to httpx for every OSWorld OpenSandbox run, because OSWorld's synchronous sandbox wrapper owns its own event loop.
  • The Ray rollout task no longer receives NEMO_GYM_CONFIG_DICT; it builds its HTTP client with default limits (see fix(http): build worker clients without parsing unrelated argv #5093). NEMO_GYM_CONFIG_PATH is still forwarded.
  • The NeMo RL profile inherits chat_template_kwargs: {truncate_history_thinking: true} from osworld_agent_nano_omni.yaml, which the tested inference recipe needs. That per-request value overrides the serving default, so the chat template strips the reasoning that raw_full replays. Training callers set it to false; RL #4581 does so in its recipe.
  • NeMo RL: only accepted calls train, so a rollout whose last step has only rejected replies fails NeMo RL's returned-history selection unless train_invalid_terminal_call is set. The recipe below sets it, and RL #4581 will pin this PR and set it in its env.example.

Training recipe

The NeMo RL run below changes these keys from the NeMo RL profile defaults (the full set is in RL #4581 examples/nemo_gym/osworld_v2/env.example):

OSWORLD_* variable Value Profile default
HISTORY_LAYOUT cc_chat osworld
CC_CHUNK_TURNS_AS_GENERATED true false
CC_PROMPT_TOKEN_GUARD 38000 null
LEGACY_RESPONSE_PARSER true false
PARSE_RETRIES 1 5
VALIDATE_PYTHON_SYNTAX false true
REQUIRE_CLEAN_FINISH false true
TRAIN_INVALID_TERMINAL_CALL true false
REWARD_MODE raw binary
ROLLOUT_TIMEOUT_S 1200 null

NeMo RL side: GRPO with 8 prompts x 8 generations per step and one step of prompts in flight (synchronous), 64 steps, 49152-token sequence length, 4 x 8 H100.

Training result

All rows use the same evaluation setup:

  • Tasks: 361 OSWorld tasks (the OSWorld test set without the Google Drive tasks). Training uses the same 361 tasks, so this measures training progress on the training tasks, not held-out generalization. 29 of the 361 tasks are infeasible.
  • Scoring: four rollouts per task; accuracy is the mean over all rollouts, and pass@4 counts a task as solved if any rollout solves it. A rollout counts as solved only when the OSWorld evaluator returns 1.0.
  • Sampling: temperature 0.6, top_p 0.95, up to 16384 generated tokens per turn, up to 200 turns.
  • Agent: the recipe's osworld_agent settings above, except that evaluation uses the default response parser (legacy_response_parser=false), no prompt-token guard, and cc_chunk_turns_as_generated=false. An episode ends when the prompt no longer fits the 49152-token window.
    | Model | Step | Accuracy, all 361 | Accuracy, 332 feasible | Pass@4, all 361 |
    |---|---:|---:|---:|---:|
    | SFT (starting point) | — | 46.88% | 44.95% | 67.87% (245/361) |
    | This PR, sync recipe | 64 | 53.81% | 51.58% | 67.87% (245/361) |

Paired per-task difference (this PR − SFT, ± standard error): +6.93 ± 1.39 points on all 361 tasks, +6.63 ± 1.45 points on the 332 feasible tasks.

Under unterminated_episode_policy=fail, an adapter-forced FAIL scores 1.0 on an infeasible task, as in the reference agent. Both rows are evaluated the same way. In the episode logs (about 1% of rollouts lack an end line), forced FAILs solved 73 of SFT's 111 logged infeasible-task rollouts and 63 of this PR's 112, so the gain does not come from them.

Verification

  • OSWorld agent tests: 546 passed on this branch merged with main.
  • tests/unit_tests/test_public_api_facades.py passes; ruff 0.9.9 check and format are clean.
  • NeMo RL selection, checked offline with the RL fix(stirrup_agent): don't load the agent when importing its helper modules #4581 selector on this branch's /run results: a trained invalid terminal call, a reply rejected by context_prompt_token_limit, and parser retries under capture all select the expected calls. A rejected terminal call without train_invalid_terminal_call still raises "Declared terminal differs from accepted history", as described under Compatibility.

@jinglinglingling
jinglinglingling requested a review from a team as a code owner October 8, 2026 01:26
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 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.

@jinglinglingling
jinglinglingling force-pushed the linglinj/flashreinforce-agentenv-osworld branch from 80f12b7 to 959dcd5 Compare October 8, 2026 01:54
@jinglinglingling jinglinglingling changed the title feat(osworld): add context compaction and AgentEnv fork oversampling feat(osworld): add OSWorld v2 environment stack Oct 8, 2026
@jinglinglingling jinglinglingling changed the title feat(osworld): add OSWorld v2 environment stack feat(osworld): OSWorld v2 environment stack Oct 8, 2026
@yaoyu-33 yaoyu-33 added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 8, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 9, 2026
@jinglinglingling
jinglinglingling force-pushed the linglinj/flashreinforce-agentenv-osworld branch from d34091a to 3d5f308 Compare October 14, 2026 15:21
@jinglinglingling

jinglinglingling commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebase/validation update:

  • Rebased onto current main (79dee227e0).
  • Focused/full Gym validation passed after conflict resolution; lint, copyright, secret scan, and DCO checks pass on head 65c0560412.
  • The rebased runtime was exercised through feat(osworld): OSWorld v2 SingleController training recipe RL#4581 in 4-node / 32-GPU OSWorld smoke Job 20192123; the job completed 8/8 rollout groups, training step 1/1, refit, and checkpoint save with ExitCode=0:0.

@jinglinglingling jinglinglingling changed the title feat(osworld): OSWorld v2 environment stack feat(osworld): OSWorld environment stack Oct 15, 2026
@jinglinglingling
jinglinglingling force-pushed the linglinj/flashreinforce-agentenv-osworld branch 6 times, most recently from 35a5422 to da4ead3 Compare October 20, 2026 02:44
@jinglinglingling
jinglinglingling force-pushed the linglinj/flashreinforce-agentenv-osworld branch from 6efe0e4 to 51eed0a Compare October 29, 2026 05:03
Linglin Jing added 8 commits November 15, 2026 19:50
The exact per-call token-evidence path again exports all calls, including parser retries,
as the README and NVIDIA-NeMo#4896 describe. Capture-on returned history is unchanged.

Signed-off-by: Linglin Jing <[email protected]>
Ray logs a task's runtime_env env_vars at INFO, which exposed literal keys in the Gym config.
Since NVIDIA-NeMo#5093 the child builds its HTTP client without parsing argv, so the dict is not needed.
NEMO_GYM_CONFIG_PATH is still forwarded for sandbox attribution.

Signed-off-by: Linglin Jing <[email protected]>
A row with no terminal action and an infrastructure_failure_reason (reset failure, policy
transport failure, rollout timeout) now reports episode_end=aborted instead of unterminated.

Signed-off-by: Linglin Jing <[email protected]>
With 0, a chunk re-base dropped the current screenshot from the prompt.

Signed-off-by: Linglin Jing <[email protected]>
Without propagate_context_overflow_errors, vllm_model turns an engine context refusal into an
empty length reply, so context_overflow_policy and mask_context_limit never see it.

Signed-off-by: Linglin Jing <[email protected]>
The parser functions come from mm_agents/nvidia/nemotron_agent.py in terrykong/OSWorld at
5d8c93592be588ab8e9909bed82f3b480fd4f533 (Apache-2.0).

Signed-off-by: Linglin Jing <[email protected]>
No OSWorld configuration sets endpoint_file; Gym NVIDIA-NeMo#3532 carries this fix with a test.

Signed-off-by: Linglin Jing <[email protected]>
…ce-agentenv-osworld

Resolve the import conflict in responses_api_agents/osworld_agent/app.py by keeping both imports.

Signed-off-by: Linglin Jing <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the community-request Issue reported or requested by someone from the community label Nov 19, 2026
yfw
yfw previously approved these changes Nov 19, 2026
@yfw

yfw commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

/ok to test f62867a

@yfw
yfw enabled auto-merge November 19, 2026 02:29
@nemo-automation-bot nemo-automation-bot Bot removed the community-request Issue reported or requested by someone from the community label Nov 19, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 19, 2026 02:30
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the community-request Issue reported or requested by someone from the community label Nov 19, 2026
Signed-off-by: Linglin Jing <[email protected]>

# Conflicts:
#	responses_api_agents/osworld_agent/adapter_agents.py
auto-merge was automatically disabled November 20, 2026 00:46

Head branch was pushed to by a user without write access

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 20, 2026
@yfw
yfw enabled auto-merge November 20, 2026 00:57
@yfw

yfw commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

/ok to test 7c44845

@nemo-automation-bot nemo-automation-bot Bot removed the community-request Issue reported or requested by someone from the community label Nov 20, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 20, 2026 00:58
@yfw
yfw added this pull request to the merge queue Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44651864995

Merged via the queue into NVIDIA-NeMo:main with commit dae7204 Nov 20, 2026
69 of 71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers complexity:high Cross-component or shared-contract change with a large review surface 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.

5 participants