Skip to content

fix(browsecomp): a provider content refusal fails one call, not the server - #6171

Merged
yaoyu-33 merged 3 commits into
mainfrom
ananthsub/browsecomp-refusal-fails-call
Nov 14, 2026
Merged

yaoyu-33 merged 3 commits into
mainfrom
ananthsub/browsecomp-refusal-fails-call

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The BrowseComp advanced harness treated every HTTP 401 or 403 from the search provider as a rejected API key and called os._exit(1). Exa also answers some queries with a 403 whose body is a content-safety refusal ("Sorry, we've detected unsafe content and can't ..."). One refused query therefore killed the search resources server mid-training. Every later search in the job then failed to connect, and those rollouts timed out.

This change separates the two cases in the Tavily and Exa clients:

  • A 403 whose body matches a content-safety refusal (unsafe content, content policy, content filter or content moderation) raises SearchProviderRefusal for that request, with no retry. The Exa search, Exa extract and Tavily extract handlers already turn exceptions into Search failed: ... or Failed to extract content: ... for the agent. The two Tavily search helpers (inline and disk mode) caught only BadRequestError, so they now also return Search failed: ... for a refusal. For both providers the rollout continues and is graded normally.
  • Every other 401 or 403 still aborts the server as a bad key, as before.

Issue

No linked issue. Training recipes need a single provider refusal to fail one tool call, not take down the search server for the whole job.

Validation

The tests check that:

  • an Exa 403 with a content-safety refusal body raises the refusal for that call, makes one request, and does not exit the process;
  • a refused Exa search reaches the agent as a failed search result and does not exit the process;
  • a Tavily 403 refusal, driven through the real Tavily client and /search, reaches the agent as a failed search in both inline and disk mode, with one request and no process exit;
  • the existing bad-key cases (Exa 401, Tavily 403 with a non-refusal body) still exit.

Each new test fails on main without the change to app.py. The disk-mode Tavily case also fails when only the disk-mode handler is removed.

Commands run, from the repository root with a server venv built by uv sync in resources_servers/browsecomp_advanced_harness:

PYTHONPATH=$PWD resources_servers/browsecomp_advanced_harness/.venv/bin/python -m pytest resources_servers/browsecomp_advanced_harness/tests -q
pre-commit run --files resources_servers/browsecomp_advanced_harness/app.py resources_servers/browsecomp_advanced_harness/tests/test_exa_provider.py

Rollout evidence

N/A: no smoke rollout was run. The workstation has no Exa or Tavily API key and the shared vLLM server was down, so the author decided to skip the rollout. The refusal path cannot be triggered on demand against a live provider, so it is covered by unit tests that drive the real Tavily client through /search with a mocked 403 refusal body, and that check the Exa client raises the refusal and that /search returns it to the agent as a failed search. The normal search path is unchanged.

Compatibility

No config or API changes. Runs that previously crashed on a provider content refusal now continue, with that one tool call reported as failed.

…erver

Exa answers some queries with HTTP 403 and "Sorry, we've detected unsafe
content and can't ...". The harness treated every 401/403 as a rejected
API key and called os._exit, so one refused query killed the search
resources server. Every later search in the job then failed to connect
and its rollouts timed out.

A 403 whose body is a content-safety refusal now raises
SearchProviderRefusal for that request, with no retry. The existing
per-call handlers return "Search failed: ..." or "Failed to extract
content: ..." to the agent, and the rollout continues and is graded
normally. Every other 401/403 still aborts as a bad key.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

The Tavily search helpers caught only BadRequestError, so a content
refusal from Tavily escaped to the /search endpoint as a 500 instead of
reaching the agent as a failed search. Both the inline and disk-mode
helpers now return "Search failed: ..." for SearchProviderRefusal.

Also correct the _abort_on_invalid_api_key docstring, which still said
every 403 means a bad key.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub marked this pull request as ready for review November 13, 2026 23:41
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 13, 2026 23:41

@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

RISK — Add the required real smoke-rollout evidence

The PR explicitly reports that no model smoke rollout ran. This changes environment behavior from terminating the resources server to returning a tool failure and continuing the rollout. Trusted AGENTS.md requires representative real smoke rollouts for behavior-changing environment work; mocked unit tests alone don't satisfy that requirement. Missing provider credentials explains the gap, but the complete agent → tools → final answer → verifier path remains unvalidated. This is a validation gap, not a demonstrated runtime defect.

Correction and acceptance: Could an author or maintainer with credentials run representative real model rollouts covering the affected Exa and Tavily configurations, including a per_session case for the changed disk helper? Record the head SHA, model, configs, commands, artifact locations, and inspected outcomes in the PR. The traces should show successful search/browse results reaching the model, continued agent execution, and completed verification without an unexpected tool exception or timeout. There's no need to force an unpredictable live refusal; keep deterministic tests for that branch. No source patch or reward-profile comparison is requested for this evidence gap.

Preservation checks: Retain the refusal and bad-key tests: a refusal must make one provider request without process exit and reach the agent as Search failed: ..., including both Tavily workspace modes; Exa 401 and non-refusal Tavily 403 must still exit with code 1. Normal search formatting, browse content, and clean disk-page writes must remain intact, as asserted by the provider success cases and disk-search coverage.

I found no additional qualifying code defect after inspecting both changed files and tracing the affected transport, batching, browse, metrics, agent-consumer, and verification paths. I couldn't execute tests or rollouts in this read-only review.

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

@yaoyu-33 yaoyu-33 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. One refused query taking down the search server for a whole job is a real problem, and this is a small, well-placed fix.

What the change does (as reviewed at 603ef8c0bb): a 403 whose body reads as a content-safety refusal now raises SearchProviderRefusal for that one request, with no retry. Every search and browse handler turns it into Search failed: <provider> refused this request: <body[:200]> or Failed to extract content: .... Other 401/403s still abort as a bad key.

What we checked and found fine:

  • Scope: the refusal stays with one call. Each query in a /search batch catches it in its own helper, browse catches it too, and later calls and the server process keep going. tavily-python 0.7.21 passes the exception through unchanged: it catches only httpx.TimeoutException around the transport post.
  • Classification: 403 is checked before RETRY_ERROR_CODES and is in neither retry list, so a refusal is never retried or counted as a rate limit. 429/5xx handling is unchanged.
  • Reward: no reward or masking change. Scoring the rollout normally is right, because the model's own query caused the refusal and it can rephrase.
  • Tests: the server suite passes at this head (271 tests). The new Tavily tests fail without the app.py change, including the disk-mode one.

The asks are inline:

  • classify Exa refusals by their documented tag;
  • a real-model run with an injected refusal, in place of the N/A;
  • tighten the Exa end-to-end test;
  • a refusal counter;
  • two README sentences.

On the automated review: we agree real-model evidence is needed. A success-path run doesn't touch the 401/403 branch this PR changes, though, so the inline ask is for a run with an injected refusal instead.

Not part of this PR, possible follow-ups (all were here before):

  • Exa 400/402 (for example NO_MORE_CREDITS) come back from _post as data and are recorded as a successful empty search.
  • Tavily non-refusal errors (432/433 ForbiddenError, exhausted retries) still escape _search_one / _search_one_to_disk as a 500.
  • TavilySearchAIOHTTPClientResponse has no raise_for_status, so tavily-python's 422/434 branch raises AttributeError.
  • The 401/403 body uses a strict .decode().

Minor:

  • Tavily documents no 403 content refusal, so the Tavily branch is defensive hardening; a word in the description would help.
  • The PR has no labels yet.

This PR merges cleanly with #6088, which touches the same server, and refusals return before that PR's cache write, so a refusal is never cached.

Comment on lines +1587 to +1590
except SearchProviderRefusal as e:
self._record_call(metrics, "search", "tavily", "error", call_start)
print(f"[browsecomp][tool_fail][tavily_search] query={query[:200]!r} error={e}", flush=True)
return f"Search failed: {e}"

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.

app.py:1587-1590

A refusal is recorded as "error", the same as a timeout or a bad request, and verify surfaces only num_provider_429s / num_provider_other_retries. A run where many queries are refused shows up only in the server log. Before this PR, the same condition crashed loudly. That includes a misclassified account-level 403 from the comment above. The metrics status is a free str (app.py:293), so could refused calls record "refused" here and in the Exa search and both browse handlers, with a num_provider_refusals count beside num_provider_429s? Small nit while here: each refusal is logged twice, [<provider>_refused] at app.py:483 plus the handler's own tool_fail line.

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.

Leaving this as a follow-up; it doesn't block the merge. In the smoke, refused calls showed up as search:error in session metrics, so a distinct status or counter would still help.

Comment on lines +489 to +490
"""A 401, or a 403 that is not a content refusal, means the API key is bad: every search in
the run would silently degrade, so kill the benchmark instead of producing a garbage score."""

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.

app.py:489-490

The README's "Provider call limits" section (README.md:30-36) is where operators read how a provider call ends. It doesn't mention the bad-key abort or the new split. Could you add two sentences there: a 401, or a 403 that isn't a content refusal, stops the server; a content refusal fails only that call, as Search failed: ... or Failed to extract content: ...?

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.

Not blocking. These two README sentences can go in with the refusal-counter follow-up.

Exa marks every error body with a machine-readable tag. PROHIBITED_CONTENT and
CONTENT_FILTER_ERROR refuse one request; TEAM_BLOCKED and FEATURE_DISABLED reject
the account. Matching message text missed a CONTENT_FILTER_ERROR worded without
the listed phrases, which still aborted the server, and matched account-level
wording such as "content policy violation", which would have turned an account
rejection into a run of silently failed searches.

A 403 now counts as a refusal when its tag is one of the two per-request tags.
A body without a tag counts only with Exa's refusal wording ("unsafe content").
Tests cover both refusal tags, account-level tags that still abort, a 401 with
a refusal body, and an untagged policy-sounding 403. The Exa /search test now
drives the real client through a mocked 403.

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

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

Copy link
Copy Markdown
Contributor

/ok to test dbd44dc

@yaoyu-33 yaoyu-33 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.

Approving at dbd44dc.

What held from the first round: a provider refusal fails only its own call. Other queries in the batch, later calls and the server process keep working. A refusal is never retried or counted as a rate limit, and the rollout is scored normally, which is right because the model's own query caused it.

What dbd44dc changes: a 403 now counts as a refusal by Exa's documented tag (PROHIBITED_CONTENT or CONTENT_FILTER_ERROR). Account-level tags and any 401 still abort the run, and a body without a tag needs Exa's refusal wording. The Exa /search test now drives the real client.

Validation:

  • The server suite passes (277 tests). The new tag tests fail on 603ef8c.
  • Scoped pre-commit is clean.
  • A real-model smoke with injected refusals covered Exa per_session, Tavily per_session and Tavily inline, 2 rows each. All 6 rollouts kept working after a refusal, reached a judged final answer unmasked, and the server never restarted. Details are in the reply on the rollout-evidence thread.

Not run:

  • A live provider refusal; the bodies were injected.
  • A live Exa key; Exa's other calls got canned results.

Left as follow-ups, not blocking:

  • A refused status and counter in the metrics.
  • The two README sentences.
  • The pre-existing Exa 400/402 and Tavily 432/433 handling listed in the first review.

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 14, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 14, 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/43569627383

Merged via the queue into main with commit ce6e9bb Nov 14, 2026
61 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/browsecomp-refusal-fails-call branch November 14, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants