Skip to content

feat(osworld): add sink-window history policy - #3139

Merged
Glorf merged 5 commits into
NVIDIA-NeMo:mainfrom
JeffPengCoder:feature/osworld-history-policy-sink-window
Sep 28, 2026
Merged

Glorf merged 5 commits into
NVIDIA-NeMo:mainfrom
JeffPengCoder:feature/osworld-history-policy-sink-window

Conversation

@JeffPengCoder

@JeffPengCoder JeffPengCoder commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add an opt-in sink_window history policy to the OSWorld Nemotron adapter: retain the earliest screenshots alongside a recent-image window, with intervening turns represented as text in chronological order.

This branch includes upstream main at d4c0f86c7 through a normal merge, including the NumPy metadata fix #3649, CI preflight update #3658, and sandbox lifecycle telemetry #3633. The OSWorld foundation from #2554/#3140 was consolidated and merged through #3592, so this PR no longer carries the old exact-trace/Core stack or depends on #2554. It does not require #3591. No separate issue is needed for this follow-up policy extension.

Changes

  • Add configurable sink, low-water and high-water counts. Both watermarks include the sink; equal watermarks slide, while unequal watermarks provide hysteresis.
  • Represent non-contiguous image selections with intervals and render folded text in chronological order.
  • Distinguish context overflow, transport failure, truncated output, empty output and unparseable output; retain agent_outcome_family=model_response_invalid for compatibility.
  • On context overflow, reduce the recent-image window within the existing retry budget, preserve the sink/current observation, record actual shrink events, and stop when further reduction is impossible.
  • Preserve main's immediate model-timeout propagation. Report the terminal attempt's completion fact so an earlier malformed sample cannot hide a subsequent transport failure.

The latest synchronization also annotates six deterministic SHA-256 prompt goldens that the previous secrets-detector run falsely identified as credentials. Only those literal lines are annotated; the digest values, assertions, repository scanner configuration, and baseline are unchanged.

Design and compatibility

History policy selects image/text turns; the adapter owns model protocol rendering and parsing. The runner owns horizon and runtime failure handling, the evaluator owns reward, and runtime admission owns masking. This PR does not change those ownership boundaries or add a training/evaluation switch.

Fixed-window and hysteresis policy IDs and normal-path rendered prompts remain covered by deterministic golden tests, including fixed-3 and 3-10-3. Sink-window is opt-in, not a new default or a claim of improved benchmark score. Context-overflow recovery and more precise failure outcomes are intentional behavioral changes and may affect failed-run outcomes. The legacy scalar image_window_start accessor rejects non-contiguous plans; consumers should use image_intervals or per-turn decisions.

Scope relative to current main remains limited to responses_api_agents/osworld_agent/: two implementation files, documentation, and tests. No Gym Core, dependency, deployment, sandbox-provider or model-server changes are included in the PR diff.

Validation

Re-run on the final main-synchronized tree:

  • 440 passed, zero skipped across OSWorld agent, resource-server and benchmark tests; one non-failing Starlette deprecation warning.
  • pre-commit run --all-files: passed.
  • uv lock --check --offline: passed.
  • git diff --check: passed.
  • The same detect-secrets==1.5.0 hook and checked-in baseline used by CI passed on all nine PR-scoped files after the inline false-positive annotations.
  • Existing model-timeout propagation, runner admission, prompt-parity, sink selection, overflow recovery and policy-identity regressions passed. The unchanged-overflow retry and mixed parse/transport completion bugs had been reproduced before their earlier fixes.

Test invocation, using an existing compatible development environment from this checkout:

export PYTHONPATH="$PWD"
export NEMO_GYM_EXTRA_ROOTS="$PWD"
python -m pytest \
  responses_api_agents/osworld_agent/tests \
  resources_servers/osworld/tests \
  benchmarks/osworld/tests \
  --import-mode=importlib -o addopts='' -o log_cli=false -q
pre-commit run --all-files

The explicit source root prevents an older editable checkout from shadowing the branch under test; importlib mode avoids the shared osworld test-package name collision. These checks are local evidence, not a claim that the upstream CI run has completed.

Score reproduction

OSWorld 361 tasks, Nemotron-3-Nano-Omni v3 (24e67ea0), fixed-3 history, 100 steps, one A/B run per arm. Control = main d4c0f86c7 + #3591 (needed for the E2B endpoint() on AgentEnv); treatment = control + this PR. Raw SR 44.61% → 46.62% (Δ +2.01 pp, paired 95% CI [−2.12, +6.07] pp); binary 154 → 159 of 361 (McNemar p = 0.59); 0 masked and 0 missing in both arms; identical history-policy and agent-contract IDs. No degradation. The context-overflow shrink path was not triggered in either run.

@copy-pr-bot

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

Two defects surfaced while attributing the b9 (3-10-3) benchmark regression.

`model_response_invalid` was a catch-all. One `except Exception` caught a
rejected request, a transport error, a truncated sample and a malformed one,
and reported all four under a name that describes only the last. Three
existing tests -- an unterminated string literal, a `finish_reason='length'`
truncation, and a `ConnectionError` -- all asserted the same string, which is
the defect stated as a test. Failures are now classified and reported as
`model_response_unparseable` / `model_output_truncated` / `model_call_failed`
/ `model_response_empty` / `model_context_overflow`, with the old name kept as
`agent_outcome_family` so aggregating consumers do not break.

Retrying a context overflow could not work. vLLM rejected four b9 prompts at
64296-64782 tokens against a 64000 limit, and each was resent unchanged five
times -- exactly `parse_retries` -- for twenty guaranteed 400s. Parse feedback
would have made the prompt longer still. The loop now shrinks the live-image
set and replans from the entry policy state instead, so a retry can succeed
and the trajectory stays replayable.

`plan_history` also gains an optional `max_images` clamp: it stays a pure
function and knows nothing about tokenizers, but a caller that can measure the
rendered prompt can now converge onto a budget rather than emit a request the
server will reject.

The new `sink_window` policy keeps the earliest turns live alongside a recent
window, which the previous scalar `image_window_start` could not express
because it assumed one contiguous suffix. `HistoryPlan.image_intervals` is now
the authority; the scalar is a property that raises when the image set is not
contiguous, so a stale consumer crashes on the first step rather than building
a wrong prompt for a whole benchmark. `low_water`/`high_water` count total
live images including the sink, matching what they already mean elsewhere.

Rendering now walks the plan in turn order and flushes a text block whenever a
folded run ends. For one leading text run -- every policy shipped so far --
this is byte-identical; with a sink it is the only ordering that puts the
summary after the turns it describes.

`supports_append_stable_intervals` now follows `high_water > low_water` rather
than the policy name: only a hysteretic window appends between compactions.
The value is unchanged for `fixed` and `hysteresis`.

Verified: 4800 algorithm-level comparison points across 12 parameterisations
and 400 steps, plus 230 end-to-end rendered prompts across 8 configurations,
are byte-identical to a4471b5. `policy_id`, `to_config` and `to_contract` are
unchanged for the shipped policies, so no published run record moves.

Signed-off-by: Jeff Peng <[email protected]>
(cherry picked from commit 780c1e4)
The strongest checks so far only existed as throwaway scripts: nothing in the
repo would notice if a later change moved a rendered prompt or a policy_id,
and that kind of drift does not fail anything -- the benchmark still produces
a plausible number, it just stops being comparable to b1..b11p.

test_history_policy_published_parity.py freezes both, using goldens computed
from a4471b5, the commit that ran b8/b9/b10p/b11p: six policy_id strings and
six sha256 digests over every prompt a deterministic trajectory renders. It
also pins the property that made this change additive -- both shipped policies
select one contiguous suffix, so the scalar accessor stays defined for them --
and asserts the shipped telemetry keys survive with their old meanings.

Mutation-checked rather than assumed: an off-by-one in the fixed window fails
3 cases, one changed character in the history header fails 14, and an extra
key in the policy_id input fails 12.

test_model_failure_classification.py drives the classifier from sixteen error
strings taken verbatim from b7..b10p logs -- four vLLM 400 bodies, five LB 502
transport errors, and the parse failures -- rather than invented ones, so a
future matcher change is measured against what the stack really emits. It also
asserts an unknown error falls back to the retryable bucket and never to the
one that shrinks the prompt.

Writing the recovered-step test found a real gap: prompt_shrink_events only
reached the terminal parse_failure block, so a step that recovered after a
rejection left no trace -- the same shape of blind spot that let twenty HTTP
400s disappear from a whole release. Both evidence fields are now emitted on
successful steps too, and only when non-empty so the clean path keeps its byte
shape, which the parity goldens confirm.

Also adds boundary and interaction coverage: shrinking bottoms out at one
image instead of spinning, a sink survives budget pressure, a sink_window
agent exposes its policy through agent_contract with the right append-stability
flag, interval telemetry reaches the model-call records, and a seeded 300-case
sweep over random policies and budgets checks the selection invariants that a
fixed table cannot reach.

Baseline a4471b5 reports 260 passed and one pre-existing test_app.py import
error from the editable install; this branch reports 339 passed and the same
single error.

Signed-off-by: Jeff Peng <[email protected]>
(cherry picked from commit 2a03083)
Preserve main's model-timeout propagation. Stop context-overflow retries when the sink and current image cannot be reduced further, and report terminal-attempt completion independently of earlier malformed samples. Keep evaluator reward and runner admission unchanged. Document the opt-in policy and verify existing prompt/identity parity.

Signed-off-by: Jeff Peng <[email protected]>
@JeffPengCoder
JeffPengCoder force-pushed the feature/osworld-history-policy-sink-window branch from 2a03083 to 9aef853 Compare September 23, 2026 04:16
Glorf
Glorf previously approved these changes Sep 23, 2026
@Glorf

Glorf commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Overall lgtm
Conditional approval, subject to scores repro to make sure there is no degradation

@Glorf

Glorf commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

SHIP — no reliability concerns.

On-call read of the OSWorld adapter change (sink-window history policy + context-overflow prompt shrinking + failure-kind classification). This is exactly the kind of change that can silently corrupt an eval release, so I focused on scorer-adjacent correctness, replayability, and telemetry integrity. It holds up.

What I checked and why it's safe:

  • Published-score parity. image_window_start now fails closed (raises) for a non-contiguous image set instead of silently returning a wrong start under a sink policy — the right failure mode, since a plausible-but-wrong prompt run to completion is the worst outcome. test_history_policy_published_parity.py freezes both the policy_ids and byte-for-byte prompt digests for the six shipped fixed/hysteresis configs, and asserts the legacy-arg and explicit-config surfaces render identically. The single-leading-text-run rendering is reproduced exactly (_flush_text on the first live image), so already-published runs stay comparable.

  • Replayability under overflow retries. Re-planning on context overflow restarts from entry_policy_state, so the window and compaction_epoch advance at most once per step regardless of retry count (test_overflow_retries_do_not_advance_the_history_policy_state). Shrinking bottoms out at sink + 1 and never resends an unchanged deterministically-rejected prompt (test_overflow_shrinking_terminates..., test_overflow_stops_at_sink_plus_current_image...). The current observation and sink are always preserved.

  • Masking semantics. model_call_completed now reports the terminal attempt's fact rather than completed_model_calls > 0. This is a genuine fix: an earlier malformed-but-completed sample no longer masks a later transport failure from runtime admission (test_terminal_call_fact_does_not_hide_transport_failure_after_invalid_sample, both orderings). The for...else → model_calls[-1] rewrite is safe because parse_retries is clamped to ≥1 and every non-timeout exit appends a record before breaking; the timeout path re-raises out of predict.

  • Outcome compatibility. agent_outcome is now specialized (model_context_overflow/model_call_failed/model_output_truncated/model_response_empty/model_response_unparseable) while agent_outcome_family: model_response_invalid is retained for aggregating consumers, and the specialized value is plumbed through the client to termination_reason. Unknown errors fall back to the retryable unparseable/transport_error buckets, never into the overflow bucket that shrinks the prompt — the conservative default (test_an_unknown_error_falls_back_to_unparseable_not_to_overflow).

  • Telemetry is additive. snapshot_* keys are preserved and new keys (snapshot_image_intervals, snapshot_sink_size, snapshot_image_budget_clamped) are added; shrink evidence is emitted on recovered steps too (closing the "twenty 400s left no trace" gap) and only when non-empty, so the clean path keeps its byte shape.

  • Coverage. Failure classification is keyed to real production error strings; a seeded randomized sweep exercises the selection invariants across the parameter space. sink validation rejects low_water <= sink and stray params, and forbids a sink on the non-sink policies.

Reminder for the author per repo policy: this is behavior-changing agent work, so confirm the PR records a representative real smoke rollout (not just green unit tests) before marking ready.

@JeffPengCoder

Copy link
Copy Markdown
Collaborator Author

/ok to test d083e5d

@yaoyu-33 yaoyu-33 added area:agent Agent harnesses and Responses API agent behavior complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work waiting-on-customer Waiting on the original author to respond labels Sep 23, 2026
@JeffPengCoder

Copy link
Copy Markdown
Collaborator Author

@Glorf, the score reproduction for the conditional approval: no degradation.

Setup. A/B with one run per arm on the OSWorld 361-task set (the 369-task suite
without the 8 Google Drive tasks). Model: Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16
(HF revision 24e67ea0), served by vLLM 0.23.0 with TP8 on 8×H100. Settings:
fixed-3 image history (the benchmark default), 100 steps, temperature 0.6,
top_p 0.95, 16,384 max output tokens. Desktops ran on an AgentEnv (E2B-compatible)
deployment, 128 tasks at a time.

Arm Gym source Raw SR Binary SR
control main d4c0f86c7 + #3591 44.61% 154/361 (42.66%)
this PR control + #3139 d083e5de 46.62% 159/361 (44.04%)
  • Difference. Δ raw is +2.01 pp, with a paired 95% bootstrap interval of
    [−2.12, +6.07] pp. For binary SR, 30 tasks succeeded only with this PR and 25
    only in the control (McNemar exact p = 0.59). This is within run-to-run noise;
    repeated identical runs have differed by 1.2–2.8 pp.
  • Coverage. All 361 tasks were scored in both arms: none masked, none missing.
  • Same policy and contract. Both arms have the identical history_policy_id
    (osworld-history-policy-d171b7730c73e7c384ab2b25) and agent_contract_id
    (osworld-agent-contract-cb1698f34a75d3dbf5fd5063), and at most 3 images per prompt.
  • Terminal model failures. The control had 5 × model_response_invalid. This
    PR had 5 × model_response_unparseable + 1 × model_output_truncated, the new
    specialized kinds that split the control's single bucket.
  • Not exercised here. Neither arm hit a context overflow, so this run did not
    exercise the shrink path. The opt-in sink-window policy was not run.

Why #3591 is in both arms: main's E2B provider has no endpoint(), and the
OSWorld sandbox bridge needs it to reach desktop ports on AgentEnv. Both merges
were conflict-free, and the diff between the two arms is byte-identical to this
PR's diff against main.

For reference, the pre-split AgentEnv source (360b0df1) scored 46.92% raw and
159/361 binary on the same model and task set in an earlier run.

@Glorf

Glorf commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

/ok to test 8b41c6a

@Glorf
Glorf merged commit 415ec29 into NVIDIA-NeMo:main Sep 28, 2026
45 of 47 checks passed

This branch was previously deployed

1 inactive deployment
public — 8b41c6a3 Deployed Sep 28, 2026 by copy-pr-bot[bot] via release / finalize / notify #3666
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 complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants