Skip to content

feat(bird_interact): grade BIRD-Interact's management tasks by their test cases - #5534

Merged
ffrujeri merged 13 commits into
mainfrom
ffrujeri/bird-interact-management-tasks
Nov 23, 2026
Merged

ffrujeri merged 13 commits into
mainfrom
ffrujeri/bird-interact-management-tasks

Conversation

@ffrujeri

@ffrujeri ffrujeri commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #5478 (ADK parity), in the BIRD-Interact stack: #5465 → #5409 → #5473 → #5475 → #5478 → this PR. The diff against #5478 is the bird_interact Environment Server (grading.py, app.py, task_data.py, README, tests) and the recipe's prepare.py, README and tests.

What changed

BIRD-Interact's management tasks now run: 105 of Lite's 300 tasks and 190 of Full's 600. Until now, the server refused them at seed and prepare.py left them out, so Gym ran only the query tasks, as auto-ontology-eval does. The benchmark is the whole task set, so the decision is to run them, in both modes.

The BIRD-Interact ADK (revision 451fe2c) grades a management phase by its test cases: Python functions from the ground truth, test_case(pred_sqls, sol_sqls, db_name, conn), that inspect the database after the submission ran and raise when it is wrong. grading.py now does the same, implemented independently:

  • The phase runs on a copy of the episode's database (CREATE DATABASE … TEMPLATE), which grading.py drops afterwards. The submission runs first and its writes stay on the copy, so the test cases see them; a failed submission leaves the episode's database as it was. A passing phase 1 is then applied to the episode's database, as for a query phase, so phase 2 starts from its state and a fresh sandbox replays it.
  • The test cases run in the episode's sandbox, never on the Gym host, with the ADK's six globals: execute_queries (each query committed under the statement timeout; returns rows, error, timed out), ex_base (the default test case's comparison), remove_comments, remove_distinct and remove_round on lists of SQL, and pred_query_result. As in the ADK, they run in order, the first that raises anything fails the phase, and the code runs with those six names as its globals and its own locals, so its functions do not see its top-level imports. What a test case prints goes to standard error, so the command's JSON result stays alone on standard output.
  • The server sends a management phase's test cases with its grade request (custom_test_cases), and gives the sandbox command time for the submission and ten queries for each test case. A query phase is graded by its result, as before, even when it has test cases. With SQLite (Mini-Interact, which has no management tasks), a task with such a phase is still refused at seed.
  • The recipe keeps every task with its ground truth: Lite 300 and Full 600 in each mode. Its README says that auto-ontology-eval's scores compare with the query tasks alone.

A broken solution SQL (one that fails even on the episode's own database) no longer fails the episode. The ADK's ex_base returns 0 for it: the submission is wrong, the agent gets its debug turn, and earlier phases keep their reward. The server now does the same and lists each such error in the rollout's solution_errors. Before, the rollout lost phase 1's reward when phase 2's solution was the broken one. The benchmark README lists the 24 Lite tasks this affects, by cause: the ADK's DISTINCT removal, which Gym copies, turns DISTINCT ON into ON and IS DISTINCT FROM into IS FROM (11); invalid solution SQL (5); phase 2 solutions that need what phase 1's solution creates (8). It also says how to run Claude Haiku 5.5 as the simulator.

a-Interact's knowledge tools (get_all_knowledge_definitions, get_knowledge_definition) returned each knowledge-base entry whole, with its type and its children's ids, which the ADK's /knowledge endpoint leaves out (KNOWLEDGE_VISIBLE_FIELDS). They now show each entry's id, name, description and definition, as a JSON array or object as the ADK writes it, as the c-Interact instruction already did.

The real-PostgreSQL test fixture failed to start: since psycopg2 2.9, with connection: opens a transaction even in autocommit, where CREATE DATABASE cannot run. It is fixed here, because the new tests need it; the four tests it serves ran for the first time.

No public issue: the PRs of the BIRD-Interact stack track the work. A follow-up checks the grading against the ADK with the real management test cases, which come with the ground truth.

Validation

Check Result
pytest environment_servers/bird_interact/tests (server venv, host) 72 passed, 7 skipped: the real-PostgreSQL class, which needs initdb
The same tests in a container with PostgreSQL 14 (the server's venv, psycopg2-binary) 79 passed, the 7 real-PostgreSQL tests among them
pytest benchmarks/bird_interact/tests 7 passed
After the broken-solution change: pytest environment_servers/bird_interact/tests (server venv, host) and pytest benchmarks/bird_interact/tests 84 passed, 9 skipped; 11 passed. The broken-solution tests check both modes and that a broken phase 2 keeps phase 1's 0.7
After the knowledge-fields change, rebased on main 555bc053d6: pytest environment_servers/bird_interact/tests (server venv), pytest benchmarks/bird_interact/tests, pytest responses_api_agents/simple_agent/tests (its venv), pre-commit run --files on the stack's files 85 passed, 9 skipped; 11 passed; 183 passed; passed. test_the_knowledge_tools_show_the_fields_the_adk_shows_and_not_the_hidden_entry fails without the change
Management-grading parity, in the Lite image: the ADK's submit flow (db_environment/server.py) and helpers (shared/db_utils.py) against grading.py's command Same verdict in 306 of 306 comparisons: 17 scenarios on each of the 18 Lite databases (writes, views, PL/pgSQL functions, execution errors, failing and erroring test cases, top-level and inner imports, ex_base, pred_query_result, execute_queries without a connection, the rewrites, several test cases, code without test_case, and one task across both phases). After each grade, the episode's database was unchanged and the copy was gone.
Mutation checks Running test-case code with one dictionary for its globals and locals fails test_a_top_level_import_is_not_visible_to_the_test_case; grading on the episode's database instead of a copy fails test_test_cases_see_the_submission_s_writes_on_a_copy_that_is_dropped
pre-commit run --files on the changed files Passed

Not validated yet: the real management test cases. The ADK's original evaluation (evaluation/src) gives a test case more names than the ADK does, such as check_sql_function_usage; Gym gives the ADK's six, so a real test case that calls another would fail in both. That follow-up will show whether any does.

Rollout evidence

On Docker sandboxes, with simple_agent; policy azure/openai/eccn-gpt-6.1-sol, simulator openai/openai/eccn-gpt-6-luna; Lite through the recipe and its image. The real ground truth is not in hand, so two management tasks got a stand-in, written from their questions, the knowledge base and the schema; its reference SQL passes both phases' test cases in the image, and a wrong submission fails. Its rewards are not results.

Task Kind c-Interact a-Interact
alien_M_2: a PL/pgSQL function, then the same function with an optional threshold parameter Management, both phases 1.0: two questions, both phases passed on the first submission 1.0: 9.5 coins, both phases passed
alien_M_3: a view of computed factors, then a filtered view over it Management, both phases 1.0: three questions, both phases passed 1.0: 11 coins, both phases passed
crypto_2 (stand-in from #5478) Query 0.0: failed phase 1 and its debug turn, as in #5478's run 0.0: two failed submissions, budget spent

Phase 2 of each management task built on phase 1's applied state: alien_M_2 dropped phase 1's function by its signature, and alien_M_3's second view selects from the first. No rollout was masked, and the failures file is empty. One a-Interact simulator reply was the action itself (labeled("some recent executions")), the quirk that #5478 notes; the ADK reads it the same way.

Compatibility

Within the unmerged stack: the recipe's task counts change from 195 to 300 (Lite) and 410 to 600 (Full), so a run's mean reward now covers management tasks too; compare auto-ontology-eval's numbers with the query tasks alone. No config change; no new dependency.

Team review fixes (2026-11-19)

From a team review of the stack, placed here, where the runner is final (76b3a6d97a, 82023bb):

  • Agent SQL no longer runs as the superuser. It could turn on statement logging, read the server's log or files, or run programs, and so read the solution SQL. The image has bird_agent (BIRD_INTERACT_AGENT_ROLE), not a superuser, which owns each template's objects (agent_role.sql); grading.py runs the task's setup, the agent's SQL and grading as it, and only makes the copies as the superuser. Grading every task's own solution as its submission, before and after, gives the same result for all 300 Lite and 600 Full tasks but three management tasks whose solution needs a superuser (session_replication_role in Lite's gaming_M_4 and virtual_M_4, CREATE ROLE in Full's virtual_idol_M_2), which the README lists (and archeology_scan_M_1, whose statistics check is timing-dependent either way).
  • SQL that breaks the driver (a date past year 9999, a huge interval, a NUL, pg_terminate_backend) is the query's error, not a failed command that masked the sample.
  • A management phase's query has one deadline, as default grading's; its command budget counts up to ten queries per test case; a passing phase that fails to apply fails the command, as default grading's does.
  • A solution run again alone after the submission broke it runs on a copy, so a COMMIT in it cannot reach the episode's database (Full virtual_idol_M_3).
  • SQLite reads at most the ADK's 10,000 rows of the last statement only; a preview cuts each value at 100 characters, as the ADK does.
  • A sandbox replacement no longer holds a server-wide query slot; start_postgres says why the server did not start; the real-PostgreSQL fixture always stops its server; the example config sets no image.
  • Docs: insider_M_4/insider_M_6 fail only phase 2; solution_errors covers query phases; management phases, not tasks, are graded by test cases.

Validation at 82023bb: server tests 92 passed, 14 skipped on the host; 106 passed in the Lite image, the real-PostgreSQL tests among them; prepare and validation tests 135 passed; pre-commit passed; each lower branch's tests pass on its own.

Not changed (follow-ups): per-category metrics in aggregate_metrics; psycopg2 holds a whole PostgreSQL result in memory before the 10,000-row cut; a PL/pgSQL block that catches query_canceled outlasts the deadline.

Review fixes (2026-11-19, second round)

The second review of #5473 listed lines that no running test caught. Those whose code is final here have tests in 971dbae: a task setup that fails fails the runner command; an episode with no configured image starts the SQLite image; a-Interact's instructions name PostgreSQL on PostgreSQL. Each fails with its change reverted. #5473 (9509a7b) and #5475 (169374b) carry the other fixes, rebased into this branch.

Validation at 971dbae: server tests 96 passed, 14 skipped on the host; 110 passed in a Debian container with PostgreSQL 15 and the server's venv, the real-PostgreSQL tests among them; prepare tests passed; pre-commit passed; #5475's and #5478's heads pass their server and prepare tests.

Review fixes (2026-11-20)

From the reviews of #5409 and #5478, fixed here where the code is final:

Validation at 34d0e06: bird_interact 107 passed, 14 skipped on the host, 121 passed with PostgreSQL 15; core suite 26,017 passed at ecf859f; pre-commit passed.

a5db377 moves ambiguity_count, needs_custom_test_cases and custom_test_cases from task_input.py to app.py, the only module that uses them, so task_input.py holds only the row schema. bird_interact tests: 107 passed, 14 skipped on the host; 121 passed with real PostgreSQL.

Review fixes, third round (2026-11-21)

bbc14f7 applies ananthsub's third round:

  • Shared-state channels to the solution SQL (blocker): the superuser owns every template and copy, and bird_agent gets only CREATE and TEMPORARY. The superuser resets bird_agent's role settings before each copy and before each write to the episode's database. New real-PostgreSQL tests cover the comment, application_name and search_path channels. The rebuilt Lite image was checked as well.
  • Scoring:
    • A deadline cancellation scores the phase as failed and no longer masks the sample.
    • Only SandboxCommandError from submit_sql ends the turn as not graded.
  • Test cases:
    • Test cases run with PGUSER=bird_agent.
    • A raising test case's error goes to the rollout (test_case_errors), never to the agent.
  • Performance: c-Interact makes no working copy (explore).
  • Metrics and config: new solution_errors metric and mask_solution_errors switch.
  • Smaller fixes:
    • Previews are cut from the value's text, not its repr.
    • Renames: fresh_copy, episode_database, _command_query_budget, failed_test_case.
    • "The solution SQL failed".
    • Two more ADK differences in the README.

663f2b2 names task_input.py in the config and schemas.py. bird_interact tests: 113 passed, 21 skipped on the host; 134 passed with real PostgreSQL. Core suite: coverage 95.09%.

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

@ffrujeri
ffrujeri added this pull request to stack #5470 November 3, 2026 20:05
@ffrujeri

ffrujeri commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8af4574

@ffrujeri

ffrujeri commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test badefcb

@ffrujeri

ffrujeri commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 183156e

@ffrujeri

ffrujeri commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7d5fd8d

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 971dbae

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 63b6bb3

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test ecf859f

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 34d0e06

Comment thread benchmarks/bird_interact/Dockerfile Resolved
Comment thread benchmarks/bird_interact/README.md Resolved
@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test a5db377

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 663f2b2

@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test c7a2c52

ffrujeri and others added 13 commits November 22, 2026 22:54
…test cases

The bird_interact Environment Server refused the management tasks at seed
(105 of Lite's 300, 190 of Full's 600), and the recipe left them out. The
benchmark is the whole task set, so they now run, in both modes
(GYMINT-681).

grading.py grades a management phase as the BIRD-Interact ADK does, in an
independent implementation: on a copy of the episode's database, the
submission runs and its writes stay, then each test case runs with the
ADK's six globals (execute_queries, ex_base, the three rewrites,
pred_query_result), in order, until one raises. The copy is dropped, so a
failed submission leaves the database as it was; a passing phase 1 is
applied for phase 2, as before. Test cases run in the episode's sandbox,
never on the Gym host, on PostgreSQL only (GYMINT-683, GYMINT-684).

The server sends a management phase's test cases with its grade request
and gives the command time for them. prepare.py keeps every task with its
ground truth. The real-PostgreSQL test fixture failed to start with
psycopg2 2.9 (`with connection:` opens a transaction even in autocommit);
it is fixed, because the new tests need it.

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

From the review of the BIRD-Interact stack:

- PostgreSQL: agent SQL runs only on copies of the episode's database, as the
  ADK resets its task database before each submission: exploratory queries on
  a working copy, each submission on a fresh copy. A COMMIT in agent SQL no
  longer changes later grades or phase 2.
- PostgreSQL: one deadline for a whole query, enforced by cancelling it, so a
  script of many statements, or one with a COMMIT, cannot outlast it.
- SQLite: agent SQL cannot ATTACH the episode's own file.
- A solution that fails after the submission runs again on the episode's
  database: a submission that broke its state is wrong, as in the ADK, and
  only a solution that fails there too is bad task data.
- A passing phase 1 that cannot be applied fails the command (default test
  case) or the phase (test cases), instead of passing without its changes.
- A numeric too large to round is a failed comparison, as in the ADK, not a
  crash of the runner.
- A sandbox command has time for every script the grader may run.
- A tool call cut off by its deadline masks the sample, in both modes.
- The SQLite wording changes the ADK's texts only, not the task they hold.

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

When a task's solution SQL fails even on the episode's own database, the
server failed the whole episode, and the rollout lost the reward of the
phases already passed. The ADK's ex_base returns 0 for such a solution:
the submission is wrong, the agent gets its debug turn, and earlier phases
keep their reward. The server now does the same, and lists each such
error in the rollout's solution_errors.

The benchmark README lists the 24 Lite tasks whose solution SQL fails at
grading (the ADK's DISTINCT removal, invalid SQL, and phase 2 solutions
that need what phase 1's solution creates), and how to run Claude Haiku
5.5 as the simulator.

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

get_all_knowledge_definitions and get_knowledge_definition returned each
knowledge-base entry whole, with its type and its children's ids, which the
ADK's /knowledge endpoint leaves out (KNOWLEDGE_VISIBLE_FIELDS). They now show
the entry's id, name, description and definition, as a JSON array or object
as the ADK writes it, as the c-Interact instruction already did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…and close the review's grading gaps

From the team review of the stack:

- Agent SQL ran as PostgreSQL's superuser, which could turn on statement
  logging, read the server's log or files, or run programs, and so read the
  solution SQL that grading runs. The image now has bird_agent
  (BIRD_INTERACT_AGENT_ROLE), not a superuser, which owns each template's
  objects (agent_role.sql). grading.py runs the task's setup, the agent's SQL
  and grading as it; only the copies are made by the superuser. Grading each
  task's own solution as its submission gives the same result as before for
  every Lite and Full task but three management tasks whose solution needs a
  superuser (session_replication_role, CREATE ROLE), which the README lists.
- SQL that breaks the driver (a date past year 9999, a huge interval, a NUL,
  pg_terminate_backend) made the command fail, which masked the sample. It is
  now the query's error, as in the ADK.
- A management phase's queries had only a per-statement timeout: they now have
  one deadline each, as default grading has. Its command budget counts up to
  ten queries per test case, and a passing phase that fails to apply fails
  the command, as default grading's does.
- A solution run again alone after the submission broke it ran on the
  episode's database, where a COMMIT in it stayed: it runs on a copy.
- SQLite reads only the last statement's rows, at most the ADK's 10,000, and
  a preview cuts each value at 100 characters, as the ADK does.
- A sandbox replacement no longer holds a server-wide query slot.
- start_postgres says why the server did not start. The real-PostgreSQL
  fixture always stops its server. The example config sets no image, so an
  unset PostgreSQL image is refused at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…est cases in the environment list

#5475's row says the recipe grades query tasks by result comparison; this PR
also grades management phases, by their test cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…ck and a-Interact's PostgreSQL instructions

Each of these passed with the behavior reverted: a task setup that fails now fails the runner command, an episode
with no configured image starts the SQLite image, and a-Interact's instructions name PostgreSQL on PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…d; report a capped result's count

- A `submit_sql` that an infrastructure failure keeps from being graded returns an error that ends the activation,
  as a graded submission does, so the policy is not called again. The sample is masked, as before.
- `execute` reports a result over the 10,000-row cap as `10000+ rows`, a lower bound, from a `truncated` flag on the
  runner's result.
- Tests for rules that had none: a failing submission is not applied; phase 2 sees phase 1's changes on the same
  sandbox; comments are removed before the ROUND rewrite; a submission over the SQL timeout gets the ADK's timeout
  message; the row cap's count. Each fails with its rule removed.
- The README drops an internal tracker key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (#6447 → #6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…s error, not a runner crash

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
ambiguity_count, needs_custom_test_cases and custom_test_cases decide the episode's budget and grading, and only
app.py uses them, so they move there. task_input.py keeps the models that rows validate against.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…QL, and apply the review's other fixes

From the review of the management tasks:

- Agent SQL could read the solution SQL, or break later grades, through state that every copy of the episode's
  database shares: a database's comment and settings, which the agent role could change as the owner of
  <db>_template and of each copy, and the role's own settings (ALTER ROLE ... SET). The superuser now owns the
  databases and grants the role CREATE and TEMPORARY on them, and resets the role's settings before it makes each copy
  and before it writes the episode's database. A connection that a test case opens itself is the agent role's.
- A command cut off by the tool call's deadline or the interaction deadline is no longer a sandbox failure: the call
  fails, and a submission cut off so is a failed attempt. Only a SandboxCommandError gets the not-graded reply.
- The rollout keeps a failing test case's exception (test_case_errors), which the agent does not see.
- c-Interact, which has no execute tool, makes no working copy.
- The aggregate metrics count the samples with a solution error, and mask_solution_errors masks them.
- A long preview value is cut from its text, not its repr. "The solution SQL failed". Renames: fresh_copy,
  episode_database, _command_query_budget. README: ten queries for each test case, and two more ADK differences.
- Tests: the re-run of a broken solution is reached (DROP TABLE IF EXISTS); a test case's own connection sees the
  submission's writes; a management submission can create a schema in its copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…ig and schemas.py

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 8bba79c

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

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