Skip to content

feat(tavily_search): serve the typed resources sessions API - #5487

Open
yaoyu-33 wants to merge 33 commits into
mainfrom
yuya/gymint-227-tavily-search-sessions
Open

yaoyu-33 wants to merge 33 commits into
mainfrom
yuya/gymint-227-tavily-search-sessions

Conversation

@yaoyu-33

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

Copy link
Copy Markdown
Contributor

Serve typed Tavily search sessions and use the shared lifecycle from #5709 for identity, verification cleanup, close, and retirement. Live metrics are always removed on release. With dump_session_id_to_metrics_on_exit: true, a separate export archive preserves shutdown metrics without making a released session appear live.

The shared lifecycle in #5709 and MCP support in #5708 are merged into main. This PR contains only the Tavily migration and related tests/documentation. No separate issue is needed for this focused migration of an existing resources server.

  • Hold the session lock through the asynchronous judge and release. Retain a deep metrics snapshot in a finally, including after judge failure; retries recompute the verdict from the request and use that independent snapshot.
  • Keep optional export records separate from live state. Calls already in flight can finish updating the archived metrics object, while verification retries remain isolated. Shutdown exports both archived and still-active sessions. Use unique session IDs: reusing an ID replaces its exported record.
  • Preserve permissive cookie tool-service inputs and full typed task validation, including MCP-wrapped seeds. Close/verification fences prevent late tools from recreating a finished session during the retry window. Once the receipt expires, the archive no longer blocks an explicit typed reseed.
  • HLE/HLE Diamond tool-only configurations do not call Tavily verify/close, so their metrics remain until shutdown unless retirement releases them. The global page cache is unchanged. README and Fern documentation describe the live/archive distinction.

Validation

Final Tavily source at 4ae9f0647, on workstation ws, Python 3.13.14, with the validation checkout first on PYTHONPATH and NEMO_GYM_EXTRA_ROOTS:

  • python -m pytest -o addopts='' -o log_cli=false --import-mode=importlib --tb=short -q resources_servers/tavily_search/tests: 143 passed. The base session contract checker failed on the preceding implementation with export enabled (close left state for resources-session) and passes after the fix. Regressions cover both export settings, close during a search, shutdown output, snapshot retries, and reseeding after receipt expiry.
  • pre-commit run --all-files: passed in the combined validation checkout, including Ruff, formatting, guardwords, configuration checks, README generation, and import layering. git diff --check passed. New commits include DCO sign-off.
  • From fern/, npm run check -- --warnings: 0 errors; redirect checking was skipped because Fern authentication was unavailable.
  • Real-model HTTP smoke with nvidia/nemotron-3.5-lightning-30b-a3b and a live Tavily search, with exit export enabled: the model answered Paris and the regex verifier scored 1.0, unmasked. Live metrics/identity were released, retry metrics matched, close succeeded, and shutdown exported the one search record. All four changed files matched the committed source hashes before and after the run. This bounded lifecycle diagnostic used an empty exclusion policy and the regex verifier; it does not establish benchmark parity, exclusion-policy effectiveness, or live judge behavior.
  • Historical smoke at 739ce5764e034461a4d9cebb57915321a64381c7 used live Tavily and the actual model judge; four searches and six model calls completed, and the judge correctly rejected the model's incorrect answer with reward 0.0 unmasked. Cookie MCP behavior is covered by unit tests.

The branch includes main at acb67734c. The earlier combined refresh passed all nine environment suites (904 tests) and shared lifecycle/MCP/process-supervisor checks (213 tests); those counts describe that earlier validation, not the latest focused run. These checks do not replace the current repository CI matrix or review approval.

tavily_search keeps one piece of per-session state: the Tavily call
metrics that /verify returns. It used the base class's default typed
seed, so nothing was fenced or released: the cookie-keyed defaultdict
grew for every session, and a late tool call recreated an entry.

- seed_session handles the typed body: the session is keyed by
  resources_session_id, a repeated seed returns it, a seed bound to
  another episode or a closed session gets 409, and task_data without
  question or ground_truth gets 422.
- close_resources_session releases the metrics by resources_session_id
  (no cookie needed), is idempotent, and fences late seeds with
  ResourcesSessionFence. A tool call for a session closed within the
  window gets 404 instead of recreating its record.
- verify keeps a typed session's metrics for its close and releases
  any other session's, so the /run and MCP paths stop growing the map.
- With dump_session_id_to_metrics_on_exit on, released metrics stay
  until shutdown so the dump still lists every session.

The tools and the score read no session state, so an unseeded caller
keeps working and a verify for a session the server no longer holds
still scores the response (with empty metrics) rather than masking it.

Refs GYMINT-227.

Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yaoyu-33 yaoyu-33 added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Nov 3, 2026
@copy-pr-bot

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

Copy link
Copy Markdown
Contributor Author

/ok to test 421c084

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

yaoyu-33 and others added 2 commits November 2, 2026 22:39
Every server under the resources session contract answers a verify
for a closed session with lost_session_verification, including those
whose reward reads only the response, so a closed session is handled
the same way everywhere. single_agent_turn verifies before it closes,
so the mask only catches an out-of-order verify.

TavilySearchVerifyResponse now inherits BaseVerifyResponse so it can
carry mask_sample and failure_kind. A session nobody seeded, such as
an MCP client's or an Agent's /run, holds no state and is scored as
before.

Refs GYMINT-227.

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

Describe the typed seed as the path new configs use, and name the configs
whose agents still call the tools from their own /run, which the server keeps
serving until they switch to an Environment Server.

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

yaoyu-33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0d1b50b

@yaoyu-33
yaoyu-33 marked this pull request as ready for review November 3, 2026 18:33
@yaoyu-33 yaoyu-33 added the needs-review PR is ready for code review and waiting on a reviewer label Nov 3, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 3, 2026 20:00
…he session docs

Adds a test that closes a session while web_search awaits Tavily and checks the late search does not recreate its metrics, the property the PR relies on and that a refactor re-indexing the defaultdict after the await would break. Adds a test for a seed that names another task for the same episode (409), and renames the 422 test, which ends with a corrected seed succeeding.

Docs: langchain_deepagents_agent calls Tavily with its own client and uses only /seed_session and /verify, so it never reaches the tools and its metrics are always empty. The 409 seed, 404 tool call and masked verify after a close hold for session_close_retry_window_seconds, not forever. The conformance import moves to nemo_gym.server_runtime.testing.

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

yaoyu-33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 02d74cc

Comment thread resources_servers/tavily_search/app.py Resolved
Comment thread resources_servers/tavily_search/app.py Resolved
yaoyu-33 and others added 2 commits November 4, 2026 12:49
The /run seed guard refused any body sharing a key with ResourcesSeedSessionRequest, so a dataset row with a scalar task_id (HLE rows, gdpval, arc_agi, ...) got 422 on every seed. Treat a body as a malformed typed seed only when it names resources_session_id or carries typed episode_id and task_id objects, the rule #5480 settled on.

Also import check_resources_session_contract from nemo_gym.server_runtime, which main's public-API test requires, and correct the docs: when Tavily is only a tool server (HLE opencode_search / pi_search), its /verify and /close_session never reach those sessions, so their metrics stay until shutdown, as on main.

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

yaoyu-33 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d102e44

yaoyu-33 and others added 4 commits November 5, 2026 23:07
Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	nemo_gym/server_runtime/base_resources_server.py
…ment the hook contract

- A cancellation that arrives while a failed initialization is being cleaned up now propagates instead of
  being swallowed by the cleanup guard.
- A cookie reseed that released the preceding run moves its finished receipt into the retry window, so a
  failed replacement no longer leaves a pending-cleanup record with nothing to release.
- Document that a disconnect leaves a verification release pending, that the release hook runs under the
  session lock, that state is per worker with session routing keeping a session on its owner, and the
  override rules for servers that keep their own seed and close.
- Rename the example server's private episode table so it no longer shares a name with the base's.
- Add regressions for the receipt deadline guard, worker ownership wiring, cookie seed races and fences,
  typed seed takeover, restore refusals and a cancelled close waiting on verification.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…he exit-dump archive

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

yaoyu-33 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 51703ca

The docs now describe only the typed Environment Server path. The cookie
seed still works unchanged; the PR description records that compatibility.

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

yaoyu-33 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c68eee3

@kajalj22
kajalj22 removed request for a team November 6, 2026 22:50
Base automatically changed from yuya/shared-resources-lifecycle to main November 8, 2026 06:36
@yaoyu-33

yaoyu-33 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1304e5b

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 4ae9f06

This branch was previously deployed

1 inactive deployment
public — 4ae9f064 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11295
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants