Skip to content

feat(browsecomp): port RL caching, stop reasons, and lifecycle logs - #6088

Merged
yaoyu-33 merged 9 commits into
mainfrom
codex/browsecomp-rl-cache-stop-reason
Nov 16, 2026
Merged

yaoyu-33 merged 9 commits into
mainfrom
codex/browsecomp-rl-cache-stop-reason

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Port the BrowseComp behavior used by RL runs onto main's Environment Server session path: shared search/browse caching, response stop reasons for mask rules, and sandbox lifecycle diagnostics.

Source commits

  • Cherry-pick a09a4f621: persistent flat-file values, optional FTS5/RapidFuzz search matching, read-only mode, offline index builder, cache statistics and tests.
  • Cherry-pick f0de18096: response.stop_reason values answered, max_steps, context_full, and timeout (this PR adds max_output_tokens; see Compatibility).
  • Adapt 45ec48af7: start/stop diagnostics for main's separate agent and resources sandboxes. Records include provider, sandbox/session IDs, startup time, lifetime and status; the resources sandbox also reports shell-call/page counts. Borrowed agent sandboxes log disconnects.

The two cherry-picks retain the original author, source SHA and sign-off. The adaptation preserves the session locking, fencing, sandbox ownership and retryable cleanup introduced by #5484 and #5489. Cache phase totals survive repeated episode verification and are released on close, including when verification is skipped. Request-local rollout context is restored after each call.

Dependencies use the managed component pyproject.toml/uv.lock (rapidfuzz==3.14.1), imports use the current public APIs, and new diagnostics use module loggers.

Compatibility and configuration

Set these fields under resources_servers.browsecomp_advanced_harness:

  • search_cache_dir: unset/empty disables caching; a relative path resolves against the resources-server directory.
  • search_cache_fuzzy_threshold: unset means exact search matching; an explicit threshold enables fuzzy search. Browse matching stays exact.
  • search_cache_read_only: serve existing entries without writing.
  • verbose_phase_log: opt into per-call cache get/put logs; verification summaries remain available without it.

Cache keys and provider preference follow the source branch: values are shared across providers, with existing Exa entries preferred over Tavily writes. Enabling or reusing a cache can change retrieved results; this PR does not establish benchmark score parity.

stop_reason differs from the source branch. There, context_full covered every length-cut response. Here a response cut after using the whole output budget the model server reports (the request's max_output_tokens, or a smaller training-framework cap sent through _ng_model_sampling) is max_output_tokens (the model's own failure), and context_full is left for a cut before that budget, which is how the model server reports a context overflow. A training filter that masked context_full to drop context overflows now keeps output-budget cuts scored; one that also meant to mask those must add max_output_tokens.

The resources server keys its per-rollout rid= lines by the resources session id. The source branch's X-Rollout-Id header, which no Gym component sends, is not ported.

No separate issue is needed for this focused port of the existing BrowseComp integration.

Validation

All execution ran on the workstation with Python 3.13.14 and uv 0.13.4; no heavy verification ran on the Mac.

  • gym env test +entrypoint=resources_servers/browsecomp_advanced_harness +should_validate_data=true +skip_venv_if_present=true: 441 passed, example data validated.

  • gym env test +entrypoint=responses_api_agents/browsecomp_agent +should_validate_data=true: 152 passed.

  • pytest tests/unit_tests/test_session_contract_repo.py tests/unit_tests/test_public_api_facades.py tests/unit_tests/tooling/test_component_dependencies.py -q: 976 passed.

  • pre-commit run --all-files: passed, including guardwords and import layering.

  • uv lock --project resources_servers/browsecomp_advanced_harness --check: passed.

  • Regression probes: consuming cache totals during verify and dropping the runner's stop reason each make the corresponding test fail; both tests pass after restoring the committed source.

  • Diff whitespace and DCO sign-offs checked.

  • Review fixes (231c301): the review fixes add 40 resources-server tests and 5 agent tests. Workstation runs: resources server 403 passed, agent 157 passed. The new cache tests fail at 08318b5 (24 of 25; the tie-order test passes by chance there), and pre-commit run --files on the changed files passes.

Rollout evidence, round 1 (real-model smoke at 231c301): this used the shipped pairing (single_agent_turn_legacy + browsecomp_agent + browsecomp_advanced_harness) with a hosted Nemotron 3.5 Super model as policy and judge, live Tavily, and Docker sandboxes. It ran on example rows 0–1 with the cache on (search_cache_fuzzy_threshold: 0.9), concurrency 1, and max_steps 8.

  • Passes 1–2 used workspace: per_session; pass 3 used the shipped workspace: none after a server restart, on the warm cache. Every pass finished with 2 rows measured, 0 masked and 0 failed. Row 0 scored 1.0 in all three passes and row 1 scored 0.0 (the model gave a wrong company). Every response has stop_reason=answered and status=completed.

  • Cache: pass 1 search 0/25, browse 0/2, pass 2 search 1/34 [1 fuzzy], browse 1/4, pass 3 search 8/24 [7 fuzzy]. Pass-2 misses were queries the model had not asked before. No [cache][put_error] lines and no tracebacks.

  • Sandbox lines: 6 agent and 4 resources sandbox_stop lines, all status=ok, and every container was removed afterwards.

  • The smoke showed that the INFO diagnostics were dropped under a default gym env start because no handler was configured. 231c301 configures the servers' loggers at entry, INFO by default, overridable with NEMO_GYM_LOG_LEVEL. That commit is unit-tested; the smoke itself enabled INFO logging externally.

  • Round 2 (ba85aea, main merged in): resources server 423 passed, agent 160 passed on the workstation; pre-commit run --files on the changed files passes. The new max_output_tokens and create-only write tests fail on 231c301.

Rollout evidence, round 2 (real-model smoke at ba85aea): same pairing, model, Tavily, Docker sandboxes, cache with search_cache_fuzzy_threshold: 0.9, workspace: per_session, max_steps 8, concurrency 1, and no external logging setup.

  • Passes 1 and 2 on example rows 0–1: 2/2 measured, 0 masked, 0 failed each; all four rows scored 1.0 with stop_reason=answered.
  • A third pass ran row 0 with max_output_tokens: 64 on the request. The model call was cut at 64 output tokens; the response has stop_reason=max_output_tokens, status=incomplete, and was measured with reward 0.0, not masked.
  • The [cache], [browsecomp][phases] and sandbox lines appear at INFO under a default gym env start. Each phases line carries rid=resources-session-…. Cache totals: pass 1 search 0/12, browse 0/1; after pass 2 search 9/38 [7 fuzzy], browse 1/3. No [cache][put_error] lines.
  • 7 agent and 7 resources sandbox_stop lines, all status=ok; no containers were left. (A first pass-1 attempt failed both rows at agent-session start because the workstation disk was full while the agent runtime installed; that is a host issue, and the retry above is the recorded pass 1.)

This port does not add Training qualification or establish end-to-end RL parity.

Review fixes

  • Cache writes are best-effort: a failed write is logged and counted, and the tool call still returns the provider result.

  • A malformed or foreign cache entry reads as a miss.

  • Cached search hits apply the current run's excluded domains and max_results. Exa entries keep the deep-search synthesis, and a hit must match the stored search type and page text.

  • Exa browse pages record the character cap they were cut at, and a page cut under a smaller budget is refetched.

  • Settings are checked at startup: the fuzzy threshold must be in (0, 1], the cache-only settings require search_cache_dir, and an unwritable or missing root is refused.

  • Fuzzy candidate selection is deterministic across worker processes. The index builder always uses the tokenizer the server queries with.

  • The READMEs document the cache settings, the change in what the agent retrieves, the index builder, the diagnostics and the stop_reason values.

  • stop_reason splits the output-budget cut (max_output_tokens) from context_full, and the agent README lists each value.

  • The rollout id is the resources session id; the unused X-Rollout-Id header and the per-session rollout-id map are removed.

  • A Tavily write that finds no entry publishes create-only (a hard link), so an Exa entry written meanwhile stays. Filesystems without hard links fall back to replace. A Tavily write that replaces an older entry can still race an Exa write of the same key; both are valid entries.

  • Not changed here: this is the third flat-file cache beside agentic_mme_agent and opencode_search. Sharing one module means moving it into nemo_gym/ and changing those servers, which belongs in its own PR.

  • Review fixes, round 3 (fcdd487, after merging main): the stop reason reads the model server's echoed output budget; a Tavily run no longer shows a cached Exa [Deep Answer], and with workspace: per_session skips an Exa entry without page text; browse hits must be as long as this run's live call keeps; an Exa page cached without its budget counts as cut at its own length; README notes for [cache][fuzzy] and the index builder's venv. Workstation runs: resources server 441 passed, agent 162 passed. Six of the new tests fail on ba85aea. pre-commit run --files on the changed files passes. No new real-model smoke: the changes are in cache hit selection and the stop-reason label, covered by mocked-provider tests.

🤖 Generated with Claude Code

ritugala and others added 3 commits November 12, 2026 14:22
…nternal reference harness

Ported: search_cache.py (flat-file value store, prefer-exa write rule, fuzzy and
read-only modes), sqlite_fuzzy_index.py (FTS5 candidate index), rollout_context.py,
build_cache_index.py, config fields search_cache_dir, search_cache_fuzzy_threshold,
search_cache_read_only and verbose_phase_log, and the cache hooks in search, browse
and verify. Cache hits are formatted per the stored provider. The exa formatting
moved into _format_exa_search and the tavily disk formatting into
_format_tavily_search_disk so a hit and a miss share one code path. Add rapidfuzz
to requirements.txt. The cache stays off when search_cache_dir is unset.

Tests: six source test files ported; the provider-line and search_live/search_hit
tests in test_rollout_id_flows.py are dropped because this branch has no such telemetry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ritu Gala <[email protected]>
(cherry picked from commit a09a4f6)
Signed-off-by: yaoyu-33 <[email protected]>
…ason

stop_reason is one of answered / max_steps / context_full / timeout, so RL
mask rules can drop rollouts that did not end on a policy decision.
context_full also covers a context overflow, which the model server answers
with an empty length-cut response.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ritu Gala <[email protected]>
(cherry picked from commit f0de180)
Signed-off-by: yaoyu-33 <[email protected]>
Adapt the sandbox lifecycle logging from Ritu Gala's
45ec48a to main's separate agent and
resources sandboxes, retaining close failures for retry.

Move cache dependencies to the managed component lock, use current public
imports and module loggers, and preserve cache telemetry until an episode
session closes. Restore request-local rollout context after calls. Cover
repeated verification, aborted-session cleanup, and stop_reason across the
sandbox runner and HTTP response boundaries.

Co-authored-by: Ritu Gala <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

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

@yaoyu-33 yaoyu-33 added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work labels Nov 12, 2026
@yaoyu-33
yaoyu-33 marked this pull request as ready for review November 13, 2026 19:45

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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

I found six RISK issues in the shared-cache implementation and integration, detailed inline. I inspected all 19 changed files and traced the affected session, runner, formatting, and verification paths. This was a static review; I didn't execute tests. Suggested patches and regression checks below need verification before adoption.

RISK — Record a representative live pairing rollout

The PR explicitly says no real model + search + sandbox pairing ran for this port. The protected repository guidance requires that evidence for behavior-changing environment or agent work. Stubbed runner/HTTP tests don't validate the live provider payloads and sandbox pairing.

Could you run the final head through the shipped Environment Server pairing with a real model, search provider, judge, and workspace: per_session, then record the redacted config and rollout artifacts? Inspect a task that uses search, browse, and the shell, and repeat against the warmed cache. Acceptance is usable agent output with the expected response.stop_reason, a verifier result consistent with the inspected answer, readable saved pages, and successful cleanup of both owned sandboxes. This asks for smoke evidence, not benchmark score parity or Training qualification; retain those existing scope limits.

NOTE — Document the new operational controls

The new cache controls and stop-reason contract aren't described in the current resources README or agent README. The PR description alone won't remain an operational reference.

Suggestion: add BrowseComp-specific usage to those guides and link it from the benchmark guide. Include the nested YAML configuration, relative-path resolution, offline index-builder command, and the four stop reasons. Static acceptance: the example maps to the actual config fields; it says caching defaults off, read-only misses still call the provider, cache reuse can change results, and context_full also covers max_output_tokens. Preserve the current Evaluation-only capability and lack of score-parity claims.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

yaoyu-33 and others added 2 commits November 13, 2026 12:21
…quest

Review fixes for the ported search cache and its diagnostics:

- A failed cache write is logged and counted; search and browse still return
  the provider result instead of a 500.
- A malformed or foreign cache entry (invalid UTF-8, not a dict, no results or
  content) reads as a miss, never as an empty hit.
- Cached search hits drop domains the current run excludes and keep at most
  max_results. Exa entries keep the deep-search synthesis and record the search
  type and page text they were fetched with; a mismatched entry is a miss.
- Exa browse pages record the character cap they were cut at; a page cut under
  a smaller budget is refetched, and a fuller Tavily page may replace it.
- search_cache_fuzzy_threshold must be in (0, 1]; fuzzy and read-only settings
  need search_cache_dir; startup refuses an unwritable or missing root.
- Fuzzy candidate terms tie-break alphabetically, and a failing FTS5 stage
  falls through to the next one. rapidfuzz is imported directly.
- The index builder always uses the tokenizer the server queries with.
- Sandbox stop lines report an unknown lifetime instead of -1.
- READMEs document the cache settings, the retrieval change, the index
  builder and the stop_reason values; stale docstrings are corrected.
- Tests cover cache hits through the contamination and domain filters, failure
  paths, request fit, settings, rollout-context resets and sandbox stop lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ault

Both servers log their lifecycle, cache and per-rollout phase lines at INFO,
but no handler was installed, so Python dropped them unless the run was
verbose. A real-model smoke showed none of them under a default
`gym env start`. Configure the servers' own loggers at entry, as
finance_sec_search does: INFO by default, NEMO_GYM_LOG_LEVEL to override, root
kept at WARNING.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 231c301

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 13, 2026 20:52
yaoyu-33 and others added 2 commits November 13, 2026 15:17
… session, keep exa entries under races

- stop_reason: a length cut that used the request's whole max_output_tokens is now
  `max_output_tokens` (the model's own failure); `context_full` is left for a cut
  before that budget, which is how the model server reports a context overflow.
- Drop the X-Rollout-Id header that no Gym component sends. The resources session
  id is the rollout id, so the per-session rollout-id map goes too.
- A tavily cache write that finds no entry publishes create-only (hard link), so an
  exa entry written meanwhile stays; filesystems without hard links fall back to
  replace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test ba85aea

@yaoyu-33
yaoyu-33 requested a review from marta-sd November 14, 2026 00:05
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 16, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 16, 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. One issue can change training rewards: on a shared cache, a Tavily run can show the model Exa's [Deep Answer] (app.py:1581). The other comments are smaller notes on the cache, one stop-reason label, the READMEs and running other harnesses.

Thank you for a careful port onto main's session path. The PR body has two real-model smoke runs, and the review fixes close most of the earlier cache points. With the cache off (the default), search and browse output is identical to main. Two separate comparisons on mocked providers (24 and 108 cases) found no difference. Each compared the merge base with this head, and main with main plus this PR. The #6171 refusal handling holds on main plus this PR: a refusal fails one call and is never cached. The lifecycle lines hold no keys and no page text.

Three comments (app.py:1754, search_cache.py:485-487, app.py:1891-1894) cover parts of the earlier review's cache points. These parts are still open for Tavily runs and for cache roots written before this PR.

Process: the PR merges cleanly with current main, so it needs no rebase. DCO passes. The required CI jobs pass at ba85aea. "Environment Server compliance (non-blocking) / Publish check" fails on two findings that main also has: browsecomp_agent defines run() and overrides aggregate_metrics. This PR adds neither.

Generated by Claude Code

yaoyu-33 and others added 2 commits November 16, 2026 12:30
…cache hits to what a live call returns

- browsecomp_agent: the stop_reason split reads the output budget that the model server echoes (a training
  framework's `_ng_model_sampling` cap), falling back to the request's budget.
- A Tavily run no longer shows a cached Exa deep-search `[Deep Answer]`.
- A Tavily run with `workspace: per_session` skips an Exa search entry without page text.
- Browse hits must be as long as this run's live call keeps: the per-URL budget for Exa, `max_page_bytes`
  for a Tavily workspace, one character past the per-URL budget for inline Tavily.
- An Exa page cached without its budget counts as cut at its own length.
- READMEs: the `[cache][fuzzy]` INFO line, the index builder runs in the server venv, the new hit rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test fcdd487

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 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/43968667153

Merged via the queue into main with commit d04b6bb Nov 16, 2026
62 of 64 checks passed
@yaoyu-33
yaoyu-33 deleted the codex/browsecomp-rl-cache-stop-reason branch November 16, 2026 22:30
yaoyu-33 added a commit that referenced this pull request Nov 18, 2026
…he merged ladder

After merging #5870, finish_response clears error on every graded response,
so the Hermes, Stirrup and BrowseComp context-overflow tests now assert that
an incomplete context-limit response has no error (Hermes keeps its own text
in metadata["hermes_error"]).

BrowseComp's session loop built its evidence from the reply's status alone,
so the stop reasons #6088 records were lost: a context_full length cut was an
output limit, and a run that hit max_steps without an answer was completed.
The evidence now reads the loop's stop_reason: context_full is a context
limit, max_output_tokens an output limit, and max_steps a turn limit, or, when
the run still has an answer, a result marked harness_step_limit_reached. A
failed response's error is a ResponseError instead of a plain dict.

Also cover Stirrup's missing-output guard, both Hermes truncation errors and
NOOA's limit rows (agent_limit vs output_limit).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
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 feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants