Repository navigation
feat(bird_interact): match the BIRD-Interact ADK's c-Interact, simulator and grading - #5478
Conversation
|
/ok to test cb77043 |
cb77043 to
478d3bc
Compare
|
/ok to test 478d3bc |
478d3bc to
33211b2
Compare
|
/ok to test 33211b2 |
33211b2 to
8ef4431
Compare
|
/ok to test 3cec9bf |
|
/ok to test 91c3b35 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
I found five correctness and reliability risks, plus a validation gap. The inline findings cover phase-state application, failure attribution, timeout handling and prompt preservation.
RISK: Provide the benchmark reward-profile comparison required for this verifier change. The recipe is a fixed evaluation benchmark, but its results section still has no Lite or Full results. The reported 863-submission ADK comparison checks grading parity, and the synthetic rollouts provide smoke evidence. Neither shows how the combined grading and simulator changes affect the benchmark's reward distribution relative to the base implementation. Could you provide before/after reward profiles on the same official query tasks, with the policy and simulator settings recorded, including mean reward, reward distribution and explanations for intentional shifts? Keep the existing grading-parity and real smoke evidence. Acceptance is a reproducible comparison that accounts for changed rewards, not unchanged scores where the protocol deliberately changed. I have not run that comparison.
I inspected every changed file and traced the affected tool/session and grading/retry contracts. This was a static review; I did not execute tests or independently reproduce the reported parity run. The file reader truncated long rollout lines, so I could inspect their visible inputs and rewards but not every trajectory item. I inspected grading and simulator/data integration directly because two delegated reports were unavailable.
Inline comments (escaped v1):
-
environment_servers/bird_interact/grading.pyline 342: RISK: Check that phase 1 was applied before reporting a pass.If comparison succeeds but the subsequent
commit=Truecall returns a failedQueryResult, this branch discards the failure and returnspassed=True. For example, injectQueryResult(rows=None, error="database is locked")for that application call after successful comparison. The caller then awards phase 1 and opens phase 2 even though the live database lacks its changes. Sandbox replacement may later replay those changes, so grading can also depend on whether a retry occurred.Could you make failed application a command failure, so the existing fresh-sandbox retry and masking paths handle the inconclusive state? Replace this call with:
(applied,) = database.run([predicted_sql], timeout_seconds=timeout_seconds, commit=True) if not applied.ok: raise RuntimeError(f"Applying phase 1 SQL failed: {applied.error}")
The invariant is that a returned phase-1 pass with a follow-up means its SQL was successfully applied. Keep ordinary comparison failures as agent outcomes, and keep grading without
apply_if_passednon-persistent.Proposed acceptance: inject an application error after a passing comparison and assert that no passing grade is returned; through the server, expect fresh-sandbox retry or
SANDBOX_FAILEDmasking after retries are exhausted. Retain the persistence test's assertions that ordinary grading creates nonotetable and successful application does. Retain the phase-2 replay test's total reward of 1.0. These checks are proposed, not executed. -
environment_servers/bird_interact/grading.pyline 330: RISK: Distinguish a broken solution from a submission that broke its database state.The solution now runs after both versions of the submission on the same state. On the example SQLite database, submit
DROP TABLE IF EXISTS authors; SELECT 1againstCORRECT_1. Both submission executions succeed, then the solution fails becauseauthorswas dropped. This branch reports broken ground truth, and the episode permanently fails verification, instead of grading the destructive submission as wrong and allowing its debug turn. The base implementation ran the solution on an independent copy, so this attribution error is introduced by the shared-state change.Could you confirm the solution fails on clean episode state before classifying it as bad task data? At this branch, the first
database.runhas already rolled back or discarded its scratch copy, so a small correction is:if not results[-1].ok: baseline = database.run(solution, timeout_seconds=timeout_seconds) if not baseline[-1].ok: raise SolutionFailedError(f"The ground-truth SQL failed: {baseline[-1].error}") return Grade(passed=False)
Keep the intended raw-submission, normalized-submission and solution order for normal grading. Do not move every solution execution onto separate state, which would undo the stated parity behavior.
Proposed acceptance: the destructive submission above returns a failed grade without
SolutionFailedError, leaves the original database intact, and gets a c-Interact debug turn. A genuinely invalid solution such asSELECT missing_column FROM salesmust still produce the terminal verification failure asserted by the existing regression. Keep the existing once-only versus idempotent-write comparison cases. This patch is source reasoning, not an executed result. -
environment_servers/bird_interact/app.pyline 967: RISK: The sandbox deadline still budgets only two query executions.Grading now runs the raw submission, normalized submission and solution, then runs the submission again when applying a passing phase 1. This unchanged deadline is still
2 * sql_timeout_seconds + 60. With the default 60-second SQL limit, a phase-1 submission and matching solution consisting ofSELECT pg_sleep(50), 1need about 200 seconds across those four executions, although each statement is within its allowed limit. The command is killed at 180 seconds, retried, then masked as a sandbox failure instead of completing grading.Could you align the command deadline with the work the grader permits? Account for the application execution and multiple solution scripts as well as the comparison stages. Multiplying by four alone is insufficient because a PostgreSQL script can contain several separately timed statements. The exact implementation needs an explicit total-grading budget or a reliable bound derived from the permitted work; whichever approach you choose, valid per-statement execution must not unexpectedly become an infrastructure failure.
Proposed acceptance: use a controlled database/command fixture where all four stages finish below their individual SQL limits but exceed the old aggregate deadline, and assert grading completes without sandbox replacement or masking. Cover multiple solution scripts too. Keep the real-PostgreSQL assertion that a statement exceeding
sql_timeout_secondsis reported astimed_out, and retain bounded command-failure retries. I did not execute these timing checks. -
environment_servers/bird_interact/app.pyline 408: RISK: A per-tool timeout can become an unmasked c-Interact failure.Set
tool_call_timeout_secondsbelow the duration ofask_userorsubmit_sql. The shared runner cancels this await and returns HTTP 504. Cancellation bypasses this toolset'sexcept Exceptionandexcept SandboxCommandErrorhandlers, sofailure_kindstays unset. If the agent returns normally after the 504,_next_messageopens a debug turn and can finish with an unmasked zero reward even though simulation or verification never completed. For submission,submitted_this_turnalso stays true, so another call getsSQL submitted. Awaiting result.despite grading being interrupted.Could you propagate the per-tool deadline outcome into the episode's failure state before it becomes a 504? An interrupted simulator call should reach
USER_SIMULATOR_FAILED; interrupted grading should reachSANDBOX_FAILED, so the existing stop/mask path applies. The timeout owner is in the shared runner, so the implementation must distinguish its deadline from caller or episode cancellation. Do not blanket-swallow cancellation or change the outer turn-timeout policy.Proposed acceptance: configure a short per-tool timeout, delay
simulate, and have the scripted agent return normally after the 504. Expectmask_sample=true,stop_reason=USER_SIMULATOR_FAILEDand no debug activation. Repeat with delayed grading and expectSANDBOX_FAILED. Retain ordinary wrong-SQL debug behavior, successful submission'sX-NeMo-Gym-End-Activation: true, and the retryable agent-stage failure for exceedingturn_timeout_seconds. These are proposed tests, not executed results. -
environment_servers/bird_interact/app.pyline 744: RISK: Translate the fixed instructions before inserting task data.in_dialectreplaces everyPostgreSQLoccurrence, but here it receives the fully rendered instruction and question. A valid SQLite task asking to find rows whose stored value is'PostgreSQL'is shown to the agent as asking for'SQLite', while its solution still filters for'PostgreSQL'. Schema identifiers and knowledge definitions containing that text are changed too. The follow-up branch has the same problem.Could you apply dialect substitution only to the fixed templates? In
_first_request, formatself.in_dialect(C_INTERACT_INSTRUCTION)andself.in_dialect(PHASE_1_MESSAGE), then remove the post-format substitution at this line. In_next_message, use:return self.in_dialect(FOLLOW_UP_MESSAGE).format(follow_up_query=episode.task.follow_up.query)
This keeps the intended SQLite wording in the instructions and tool descriptions without rewriting the task, schema or knowledge. PostgreSQL mode must remain unchanged.
Proposed acceptance: create a SQLite table containing distinct
'PostgreSQL'and'SQLite'values, with both phase questions explicitly requesting'PostgreSQL'. Assert both rendered questions retain that literal and their correct submissions pass; include a schema identifier or knowledge definition containingPostgreSQLand assert it stays intact. Retain the existing first-request assertions forgreat SQLite writing abilityandfinal SQLite query, plus PostgreSQL-mode wording. I have not executed these checks.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
/ok to test ce77ac7 |
|
Answers to the review's findings.
|
|
/ok to test de55777 |
|
/ok to test 0fe108b |
|
/ok to test 26c5042 |
|
/ok to test b6713a9 |
|
/ok to test 01cdd59 |
|
/ok to test 3706899 |
|
This PR should land together with #5534. At this head, the five risks from the earlier automated review still apply:
Their fixes are in #5534 (63b6bb3), so merging this PR on its own ships all five. The flaky interaction-deadline test in the inline comments is not fixed there. Two corrections to the description:
|
|
/ok to test c68cc29 |
|
Agreed: this PR lands together with #5534. The stack merges from the top, so this branch holds #5534's server, with the five fixes, before it reaches The flaky interaction-deadline test is fixed here, in c68cc29f, with your suggestion. The other inline points are answered in their threads. Description corrections:
|
|
/ok to test 683f1ce |
|
/ok to test 05d3c87 |
…tor and grading auto-ontology-eval runs BIRD-Interact Lite and Full query tasks on the ADK's orchestrator, user simulator and grader. Bring the Environment Server to parity with what it uses, at ADK revision 451fe2c3518ee1cf908d8139e2913483bd519381: - c-Interact is the ADK's protocol: the agent gets ask_user and submit_sql, the ADK's instruction and tool descriptions, and each turn is opened with the orchestrator's phase-1, debug or follow-up message. A turn ends at its submission; each phase has two turns; rewards follow the phase's submissions. - The user simulator is the ADK's two-stage pipeline with its v2 prompts, sampled at temperature 0, and its clause split of the solution (sqlglot). Its placeholders are filled in one pass, so a question cannot pull the solution SQL into the prompt as the ADK's sequential fill would. - Grading is the ADK's default test case, edge cases included, run in its order on one database state; PostgreSQL scripts are sent whole; phase 1's passing SQL is applied for phase 2, and replayed on a fresh sandbox. - Query phases are graded by their result even when they have test cases; only a non-query phase with test cases is refused (server) or left out (prepare.py), as the ADK decides by category. The ADK's texts are copied verbatim into adk_prompts.py, with its MIT notice and revision, and recorded in ATTRIBUTIONS.md. Validation: server tests 64 passed, 4 skipped (real PostgreSQL, run in the Lite image instead); prepare tests 7 passed; the ADK's own grading against grading.py on six Lite databases agreed on 863 of 863 submissions; the example tasks with real models on Docker, 10 of 10 (mean reward 0.82); Lite on PostgreSQL through the recipe, with a stand-in ground truth for three tasks, in both modes on Docker. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…another model call The ADK's before-model callback ends the agent's run after submit_sql, so its turn makes no model call after the submission. Gym's agent made one more, which the ADK does not: token counts and trajectories differed from the ADK's, though rewards did not. submit_sql's reply, and the ADK's replies after a submission, now end the agent's activation (ToolResult.ends_activation). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
The grading tests checked the helper functions apart, so removing a rule from grade itself passed the suite: running the submission as written first, the ROUND and DISTINCT rewrites, or the 10,000-row cap. Each new test fails when grade drops one of them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
… not run, unlike in the ADK The README and CInteractTools said a call after submit_sql in the same model response gets the ADK agent's reply. The ADK runs every call of a response (its c-Interact callback stops only the next model call), so a second submit_sql is graded there too. Gym runs none after the submission. The README now lists this as a second deliberate difference. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…to sample the policy for comparable scores - The ADK parity section lists what differs, beyond the two deliberate choices: a failed simulator or grader masks the sample; the agent's request (the ADK's identity line, the tools' descriptions and `strict`); tool results as text; the history after a submission; an empty submission's message. - For scores comparable with the ADK's, run the policy at temperature 0 with at most 4096 output tokens, set on the policy's Model Server (`sampling_overrides`), since the server writes the agent's requests. - auto-ontology-eval is linked where the READMEs first name it. - The episode's budget fields say which mode owns each. - The interaction-deadline test's first turn is a text reply, so no grade runs inside its 0.5-second deadline. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
|
/ok to test 99fba90 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45125297479 |
Stacked on #5475 (the Lite and Full recipe), in the BIRD-Interact stack: #5465 → #5409 → #5473 → #5475 → this PR. The diff against #5475 is the
bird_interactEnvironment Server, the recipe'sprepare.pyand README, andATTRIBUTIONS.md.What changed
auto-ontology-eval runs BIRD-Interact's Lite and Full query tasks in c-Interact on the BIRD-Interact ADK: its orchestrator, its user simulator and its grader. This PR brings the
bird_interactEnvironment Server to parity with what it uses, at ADK revision451fe2c3518ee1cf908d8139e2913483bd519381.orchestrator/cinteract.py:max_turn, the phase-1, debug and follow-up messages, two runs for each phaseapp.py:_first_request,_next_messagesystem_agent/agent.py,tools.py,callbacks_cinteract.py: the instruction,ask_userandsubmit_sql, one submission for each runapp.py:CInteractToolsdb_environment/server.py: the grader's messages, rewards by submission count, the phase-1 snapshot, the knowledge the agent seesapp.py:submit;grading.pyshared/db_utils.py:test_case_defaultand its rewritesgrading.pyuser_simulator/: the two stages, thev2prompts, the clause split (sqlglot)simulator.pydirect_httpormcp. The server sends the ADK's instruction and phase-1 message, then opens each later turn as the orchestrator does: the debug message after a failed phase (with the SQL error when the submission did not run), the follow-up question after phase 1 passes. A turn ends at its submission, with no further model call, as the ADK'sbefore_model_callbackends its run:submit_sql's reply ends the agent's activation (ToolResult.ends_activation, from feat(simple_agent): continue an agent session across activations #5465), and another call in the same model response is not run: it gets the text the ADK's callback puts in place of the model's next reply. The ADK runs every call of a response, so this is a second deliberate difference, listed in the README. Rewards follow the phase's submissions, as in the ADK. This replaces feat(bird_interact): run BIRD-Interact in its Environment Server, with no Resources Server #5409's conversational c-Interact, where the agent's reply text was parsed for SQL.max_turnsis gone: the protocol fixes the turns.v2prompts, the action parser and the response generator at temperature 0 with its output limits, the ambiguity JSON as the row writes it, the solution split into clauses withsqlglot, and phase 2's prompts. The one deliberate difference: the ADK fills its placeholders one after another, so an agent's question containing[[GT_SQL]]would get the solution SQL written into the simulator's prompt; Gym fills them in one pass.DISTINCTandROUNDrewrites, in that order on one database state, rolled back; each query keeps its last statement's rows, at most 10,000. Edge cases are kept for parity, such as an array of decimals failing because it cannot be written as JSON. A PostgreSQL query is sent whole, so dollar-quoted bodies work. Phase 1's passing SQL is applied for phase 2, and replayed when a sandbox is replaced.sql_timeout_secondsdefaults to the ADK's 60.prepare.pyleaves it out. Every query task's follow-up is a query, so all 195 Lite and 410 Full query tasks run.user_model(user_model_nameinenv.yaml). The READMEs say that the ADK default, which auto-ontology-eval uses, isanthropic/claude-haiku-4-5-20251001.Why
auto-ontology-eval's BIRD-Interact results come from the ADK. With the same protocol, simulator and grading, its runs can move to Gym without a change in what is measured. No public issue: the PRs of the BIRD-Interact stack track the work.
Code provenance
environment_servers/bird_interact/adk_prompts.pyholds texts copied verbatim from the BIRD-Interact ADK, revision451fe2c3518ee1cf908d8139e2913483bd519381, under the MIT license (Copyright (c) 2025 BIRD-Interact Authors), whose notice the file's header reproduces:adk_prompts.pyBIRD-Interact-ADK/user_simulator/prompts.pyv2_action_parser,v2_response_generatorBIRD-Interact-ADK/user_simulator/server.pyBIRD-Interact-ADK/system_agent/agent.pyCINTERACT_INSTRUCTIONBIRD-Interact-ADK/system_agent/tools.pyask_userandsubmit_sqldocstrings, the submission reply's linesBIRD-Interact-ADK/system_agent/callbacks_cinteract.pyBIRD-Interact-ADK/orchestrator/cinteract.pyBIRD-Interact-ADK/db_environment/server.pyThe texts are byte-for-byte; the ADK's f-strings are
str.formattemplates.ATTRIBUTIONS.mdrecords the component. The code that uses them (protocol, simulator pipeline, grading) is an independent implementation.Validation
pytest environment_servers/bird_interact/tests(server venv)initdbon the host (run in the image instead, below)pytest tests/unit_tests/benchmarks/test_bird_interact_prepare.pytest_case_defaultand submit flow againstgrading.py, in the Lite imageDISTINCTandROUNDrewrites, comments, ordering, decimals, dates, JSON, numeric and date arrays, multi-statement and writing submissionsgrading.pyin the Lite imagetest_phase_2_sees_what_phase_1_changed_even_on_a_fresh_sandboxtests/unit_tests(benchmark, manifest, import, sandbox and Environment Server selections)test_opensandbox_compose.py,test_sandbox_transfer.py,test_sandbox_stop_retry.py,test_harbor_validation.pyandtest_benchmarks.py, the same with and without this PR's changes on this machinepytest environment_servers/bird_interact/tests(after ending the turn at the submission)submit_sql's replies carryX-NeMo-Gym-End-Activation: trueand a question's does not. It fails without the changepre-commit run --fileson the changed filesNot validated in this PR alone: runs with the real ground truth, the Full image and a Full run. They ran at the top of the stack, with the Auto Ontology agent (#6489).
Rollout evidence
All on Docker sandboxes, with
simple_agent; policyazure/openai/eccn-gpt-6.1-sol, simulatoropenai/openai/eccn-gpt-6-luna:main): before, every c-Interact turn made one model call aftersubmit_sql, 8 over 8 turns, which the ADK does not make. After, none: model calls per turn went from [3], [7, 2], [4, 2], [6, 2], [5] to [2], [5], [3, 1], [5, 1], [4]. 10 of 10 completed; c-Interact mean 0.82 and a-Interact 0.68, a-Interact being unaffected by the change (5 tasks, run-to-run variation). This run replacesdata/example_rollouts.jsonl.solar_10passed both phases (1.0);solar_3passed phase 1, failed phase 2 and its debug turn (0.7);crypto_2failed phase 1 and its debug turn (0.0). A secondsubmit_sqlin one turn got the ADK's "SQL submitted. Awaiting result." a-Interact: 3 of 3 completed, mean 0.9.One simulator reply in the example run was the action itself (
unlabeled("JOIN")): the simulator model continued the ADK's prompt, which ends in an open<s>, with the action. The ADK reads it the same way.Compatibility
Within the unmerged stack: c-Interact's protocol, stop reasons and grading change, so c-Interact scores from #5409's server are not comparable with these.
max_turnsis removed from the server's config. c-Interact now needs a harness that resumes its session and takes tool grants:simple_agentdoes, and OpenCode can overmcp, in its own sandbox. a-Interact keeps its tools and budget, but its grading changes too: the submission runs as written first, results are capped at 10,000 rows, a passing phase 1 is applied before phase 2, andsubmitreplies with the grader's messages. So a-Interact scores from #5409's server are not comparable with these either. New dependency for the server:sqlglot==30.20.0.Team review fixes (2026-11-19)
From a team review: 485e642bf8 adds
tests/test_grading.py, whose tests fail whengradedrops one of the ADK's rules (running the submission as written first, the ROUND and DISTINCT rewrites, the 10,000-row cap); b6713a9 says, in the README andCInteractTools, that a call aftersubmit_sqlin the same response is not run, unlike in the ADK. The review recommends landing this PR with #5534, which fixes the Codex risks on this code.Review fixes (2026-11-20)
From the second review, in c68cc29:
strict), tool results as text, the history after a submission, an empty submission's message.sampling_overrides), since the server writes the agent's requests.Fixed where the code is final, in #5534 (ecf859f): a
submit_sqlthat cannot be graded ends the activation;executereports a capped result as10000+ rows; tests for the rules that had none.pytest environment_servers/bird_interact/testsat this PR's fix commit: 73 passed, 4 skipped.