Skip to content

feat(bird_interact): run BIRD-Interact in its Environment Server, with no Resources Server - #5409

Merged
ffrujeri merged 6 commits into
ffrujeri/simple-agent-session-continuationfrom
ffrujeri/bird-interact-environment-server
Nov 23, 2026
Merged

ffrujeri merged 6 commits into
ffrujeri/simple-agent-session-continuationfrom
ffrujeri/bird-interact-environment-server

Conversation

@ffrujeri

@ffrujeri ffrujeri commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Merges only together with #5534. At this head the grader still has problems that #5478 and #5534 fix (COUNT(DISTINCT …), SQL with a NUL, ATTACH). Once #5534 is approved, the stack merges from the top: #5534 into #5478's branch, then each PR into its base, so this branch holds #5534's server before it reaches main.

Stacked on #5465 (simple_agent continuation), which is on main: the BaseEnvironmentServerWithTools stack (#5346 → #5347 → #5348 → #5349 → #5350 → #5917) has merged. This PR's diff against #5465 is environment_servers/bird_interact only.

What changed

BIRD-Interact runs in one Environment Server for each mode, with no Resources Server. This is approach A of the BIRD-Interact RFC; #5202 is the prototype of approach B, which splits each episode between an Environment Server and a Resources Server.

environment_servers/bird_interact subclasses BaseEnvironmentServerWithTools (#5347) directly, with no user-simulation base class. Its run starts the database sandbox, serves the a-Interact tools, seeds the agent session (agent_session.py), runs the turns and grades them. The server owns the database sandbox, the two-stage user simulator, the grader, the phase and BIRD-COIN rules and the turns. It takes sandbox_provider from the base class and starts every database sandbox, a fresh one for a retry included, with start_episode_sandbox (#5917), so the episode's cleanup stops each one.

#5202 (approach B) This PR (approach A)
Servers in an episode Environment Server + Resources Server Environment Server
c-Interact ask and submit Calls to /c_interact/ routes In-process
a-Interact tools Resources Server routes, MCP auto-exposure A TypedToolset of the episode, over direct HTTP, MCP or both
Agent's credential The Environment Server's Resources Server cookie, which reaches every route A signed episode token, for the tool routes of one episode
Who knows the mode Both servers The Environment Server
Several workers Resources Server session routing Routing on the episode token (#5350)
  • Agent session. Seeded with the episode's grants; above one turn it must resume across turns, so each turn sends only the user's new message. A turn over activation_timeout_seconds fails the episode for a retry, the optional interaction_timeout_seconds stops the turns and still grades, and the agent is closed before grading. A failure keeps the completed turns, the tool calls and the agent's evidence.
  • Sandbox. Each episode starts its sandbox and registers its stop, so it stops on every path, including shutdown (feat(environment): finish every Environment Server's running cleanups at shutdown #5348). A command that fails for infrastructure reasons runs again on a fresh sandbox; then c-Interact fails the episode for a retry and a-Interact masks the sample (bird_interact:sandbox_failed), as does a simulator failure in an a-Interact ask (bird_interact:user_simulator_failed).
  • Tools. Over direct_http the first request declares the nine tools as strict function tools; over mcp alone it declares none, because the agent lists them from the server, and some harnesses refuse a request that also declares tools.
  • Data. The example datasets are declared on the agent, one taskset for each mode, and validated by the server's task_data.py, the Harbor layout. grading.py, simulator.py, task_data.py and the example data come from feat(environment): add a user-simulation base class and BIRD-Interact on it #5202 unchanged apart from module paths and wording. data/example_rollouts.jsonl is regenerated from the smoke run below.

No public issue: the PRs of the BIRD-Interact stack track the work.

Validation

At this head (2340aac, rebased onto main 5678f14):

Command Result
pytest environment_servers/bird_interact/tests (test_app.py and test_agent_session.py, the server's venv) 53 passed
pytest tests/unit_tests -n 16 (the CI extras) 25,994 passed, 36 skipped
pytest responses_api_agents/simple_agent/tests 186 passed
uv lock --check in environment_servers/bird_interact The lock is current
pre-commit run --files on the changed files Passed

The scripted-agent episode tests run with real database sandboxes on the host (local provider). New since the review: no sandbox is left after a replacement; an ending episode starts no replacement sandbox, which fails without the guard; the two-episode test waits on a barrier.

Rollout evidence

The table's runs are from before the move of the turns into this server, and they were not rerun on this PR's own head. The session-driven path ran again on 2026-11-17, on the head of the stack, where #5478 has replaced this PR's c-Interact turn loop with the ADK's: the five example tasks in both modes, 10 episodes, 10 completed and none masked (c-Interact mean 0.78, a-Interact 0.82), and no sandbox left running (comment). Docker database sandboxes, num_workers: 4 on each BIRD Environment Server, the five example tasks, two repeats. Policy azure/openai/eccn-gpt-6.1-sol; simulator openai/openai/eccn-gpt-6-luna.

Run Rollouts Failed Masked Mean reward #5202's run
c-Interact, simple_agent 10 0 0 0.71 0.40
a-Interact, simple_agent over direct HTTP 10 0 0 0.82 0.82
a-Interact, Codex over MCP (tool_transports: [mcp]) 10 0 0 0.82 0.80 (3 tasks)

What I checked in the rollouts:

  • No tool call returned an error, and no tool output other than ask contained a task's hidden knowledge entry.
  • The one failed c-Interact episode (bookshop_2) is the known simulator issue the RFC records: the simulator calls a fraction a percentage, so the agent's ×100 answer fails.
  • Codex's own observations show only BIRD's tools; it never used its shell.
  • No BIRD sandbox container was left after the runs.
  • The servers log no per-worker access lines, so the runs show four workers and no routing errors, not which worker served each call; feat(environment): route BaseEnvironmentServerWithTools tool calls to the worker that runs the episode #5350's e2e test covers that.

Compatibility

New server; existing servers do not change. #5202, the approach B prototype, is closed.

Not supported yet:

Team review fixes (2026-11-19)

A team review found three risks; this PR fixes the one in its own code, 6864560: a TimeoutError before a turn's deadline (an aiohttp socket or connection timeout) was re-raised unmapped and became a terminal unhandled failure that lost the turns; it is now the agent's failure, retried (new tests/test_agent_session.py). The SQLite runner's row and preview bounds, and the sandbox replacement holding a query slot, are fixed where that code is final, in #5534; land this PR with the rest of the stack.

Review fixes (2026-11-20)

From the second review, in aa2db18 (and 2340aac, which relocks after the rebase onto main):

  • A sandbox that a tool call would replace during the episode's cleanup was never stopped. run now marks the episode as ending before the base class runs the cleanup, and _replace_sandbox refuses once it is set.
  • turn_timeout_seconds is now activation_timeout_seconds, the name swe_together uses for the same bound.
  • The example c-Interact config sets interaction_timeout_seconds: 3000, so a slow agent's turns stop and are graded before the episode deadline.
  • The agent timeout uses AGENT_TIMEOUT_METADATA_KEY from nemo_gym.agents.
  • README: OpenCode, Kilo and OpenClaw accept required MCP grants in their own sandbox; grading.py needs Python 3.10; a client error from the user model fails the episode for good; the MCP rule is stated for any harness; no internal tracker key.
  • Tests: no sandbox is left after a replacement; the two-episode test waits on a barrier, not a fixed sleep.

@copy-pr-bot

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

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test cef7fc5

@ffrujeri
ffrujeri added this pull request to stack #5352 October 31, 2026 13:59
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Nov 1, 2026
@ffrujeri
ffrujeri force-pushed the ffrujeri/bird-interact-environment-server branch from cef7fc5 to 1ba7db8 Compare November 2, 2026 22:21
@ffrujeri

ffrujeri commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1ba7db8

@ffrujeri
ffrujeri force-pushed the ffrujeri/bird-interact-environment-server branch from 1ba7db8 to 8ae6ea8 Compare November 2, 2026 23:01
@ffrujeri
ffrujeri removed this pull request from stack #5352 November 2, 2026 23:03
@ffrujeri
ffrujeri changed the base branch from ffrujeri/self-contained-session-routing to ffrujeri/agent-session-client November 2, 2026 23:03
@ffrujeri
ffrujeri added this pull request to stack #5468 November 2, 2026 23:03
@ffrujeri

ffrujeri commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8ae6ea8

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test ae31d95

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 1fe3440

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 2c86204

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 7369f39

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

HOLD

I found grading defects that can change scores, plus protocol and lifecycle failures. This was static review; I did not execute tests or rollouts. I inspected all 20 changed files and their affected runtime and data contracts. One delegated report was unavailable, so I inspected its grading and sandbox topic directly.

RISK: Refresh the real smoke evidence after moving the turn loop. The PR description says the real model runs predate the move of turns into this server. The current episode implementation now seeds, activates and closes agent sessions itself, so the earlier runs do not validate that integration. Could you run and inspect representative current-behavior c-Interact and a-Interact rollouts, including a clarification and a two-phase task? Provide rewards, failed/masked counts, continuation behavior and cleanup observations. Keep the earlier runs identified as historical and retain the scripted regression coverage. Acceptance is real rollout evidence for the current session-driven path, as required by the trusted AGENTS.md quality bar, rather than another scripted-agent test.

NOTE, suggestion: Publish a discoverable benchmark guide. This user-facing benchmark has a server README, but no Fern documentation change. Could you add a focused page and link it from the Environment Server guide? Cover mode selection, a runnable configuration, the ground-truth requirement and the SQLite/custom-test limitations. Keep the README's implementation detail and distinguish the single-phase reward configuration from the default two-phase schedule. Acceptance is a linked page whose commands match the shipped YAML and whose links pass documentation validation.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 306fc99

@ffrujeri

Copy link
Copy Markdown
Contributor Author

Answers to the two points in the review summary:

Current smoke evidence. The session-driven path ran again after the review fixes:

All runs on Docker sandboxes, with simple_agent, policy azure/openai/eccn-gpt-6.1-sol and simulator openai/openai/eccn-gpt-6-luna, on the current head of the stack (2026-11-17):

  • The server's five example tasks (SQLite), both modes, 10 episodes: 10 completed, none masked. c-Interact mean 0.78 (5 of 5 solved, including two two-phase tasks and a debug turn), a-Interact mean 0.82. No model call after any submission. No sandbox left running.
  • Lite through the recipe (PostgreSQL, the benchmarks/bird_interact:lite image), 3 tasks in both modes, 6 episodes: two management tasks (alien_M_2, alien_M_3) and a query task with a follow-up (crypto_2), on a stand-in ground truth written from their clear questions, because the real ground truth is not in hand. 6 completed, none masked, no failures; every phase passed on its first attempt, and simulator questions and BIRD-COIN charges are in the results. No sandbox left running. These rewards check the image, the protocol and the grading; they are not benchmark results.

Fern page. The recipe now has a row in the Fern environment list (8ca347d6, #5475). A longer page is left for when Lite and Full have real-ground-truth results; until then the server and recipe READMEs hold the runbook.

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 11d8f53

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 4e0f217

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 16d306d

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 3b84adc

@ananthsub

Copy link
Copy Markdown
Contributor

This PR should land together with #5478 and #5534, not on its own. Nothing stops it from merging without them today, and at this head three problems that those PRs fix still affect every score:

If this PR needs to land first, those three fixes are small enough to move here. Separately, the replacement sandbox that is never stopped during cleanup is not fixed anywhere in the stack yet (see the comment on _replace_sandbox), so it needs a fix in this stack either way.

The description also needs a few updates:

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 2340aac

@ffrujeri

Copy link
Copy Markdown
Contributor Author

Agreed: this PR lands together with #5478 and #5534. As on #5473, the stack merges from the top: once #5534 is approved, it merges into #5478's branch, then each PR into its base, so this branch holds #5534's server before it reaches main. The description now says so at the top. The three grading fixes stay where the grader is final:

The replacement sandbox started during cleanup is fixed here, in aa2db189, as you propose. It carries through #5478 and #5534.

Description updates:

ananthsub
ananthsub previously approved these changes Nov 20, 2026
@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 3735799

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test c0deb63

ffrujeri and others added 6 commits November 23, 2026 03:28
…h no Resources Server

BIRD-Interact moves into one Environment Server for each mode, as
approach A of the BIRD-Interact RFC proposes. The server subclasses
BaseEnvironmentServerWithTools directly: its run_episode starts the
database sandbox, serves the a-Interact tools, seeds the agent session,
runs the turns and grades them. The #5202 prototype splits each episode
between an Environment Server and a Resources Server; here the
Environment Server owns the database sandbox, the user simulator, the
grader, the phase and BIRD-COIN rules and the turns.

- The agent session (agent_session.py) is seeded with the episode's
  grants, resumes across c-Interact turns, and is closed before grading.
  A turn over turn_timeout_seconds fails the episode for a retry, the
  optional interaction deadline stops the turns and still grades, and a
  failure keeps the completed turns, the tool calls and the agent's
  evidence.
- c-Interact: a question or a submission in each agent reply becomes
  an in-process call. No routes between two servers, and no session
  cookie that reaches every route.
- a-Interact: the nine tools are a TypedToolset of the episode, served
  over direct HTTP, MCP or both (tool_transports), with the signed
  episode token, on any of several workers. The first request declares
  them as strict function tools over direct HTTP, and none over MCP
  alone.
- Each episode starts its database sandbox and registers its stop, so
  the sandbox stops on every path, including shutdown. A command that
  fails for infrastructure reasons runs again on a fresh sandbox; then
  c-Interact fails the episode for a retry and a-Interact masks the
  sample, as does a simulator failure in an a-Interact ask.
- A task without sol_sql, with custom test cases or without its
  database fails at seed, for good.
- The example datasets are declared on the agent, one taskset for each
  mode, and validated by the Environment Server's task_data.py (the
  Harbor layout). gym env test's data and catalog checks still cover
  only Resources Servers (GYMINT-643).

grading.py, simulator.py, task_data.py and the example data come from
#5202 unchanged, apart from module paths and wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…e_sandbox

BaseEnvironmentServerWithTools now requires sandbox_provider and starts
an episode's sandboxes with start_episode_sandbox, so BIRD-Interact
inherits the field and uses the helper. Each sandbox, including a fresh
one for a retried command, has its stop registered in the episode's
cleanup before it starts. Before, the one cleanup was registered after
the first sandbox started, and a stale sandbox whose stop failed was
left to the provider's ttl_s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…ow-up after a budget-spending pass

- A request with skip_token_capture keeps its agent turns off the training
  capture route, as the episode request contract says.
- In a-Interact, a passing submission that spends the last coin no longer
  ends the task: only a submission that did not pass does, so the follow-up
  stays reachable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
… call times out

A TimeoutError before the turn's deadline was re-raised as it was, on the
premise that an outer deadline also raises one there. An outer deadline
reaches the await as a cancellation, so that error is the call's own, such as
aiohttp's socket or connection timeout. Unmapped, it became a terminal
unhandled failure that lost the turns and the agent's evidence. It is now the
agent's failure, which the episode retries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…turn bound activation_timeout_seconds

- `run` marks the episode as ending before the base class runs its cleanup, and `_replace_sandbox` then refuses. A
  replacement started during the cleanup would never be stopped, because the cleanup runs its entries in reverse.
- `turn_timeout_seconds` becomes `activation_timeout_seconds`, the name `swe_together` uses for the same bound.
- The c-Interact example config sets `interaction_timeout_seconds: 3000`, so a slow agent's turns stop and are graded
  before the episode deadline fails the episode.
- The agent timeout goes in `AGENT_TIMEOUT_METADATA_KEY` from `nemo_gym.agents`, not a copy of its string.
- Tests: no sandbox is left after a replacement; an ending episode starts no replacement; the two-episode test waits
  on a barrier, not a fixed sleep.
- README: OpenCode, Kilo and OpenClaw accept required MCP grants in their own sandbox; `grading.py` needs Python 3.10;
  a client error from the user model fails the episode for good; the MCP rule is stated for any harness; no internal
  tracker key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 470b7d0

@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/45125292268

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 risk:high Autobot PR risk: high 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