Repository navigation
Conversation
|
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. |
8dd6a1a to
897a942
Compare
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
I found one RISK in cross-root import validation and one non-blocking NOTE about the dependency-rule test. The inspected environment aliases and moved SWE-Together schemas keep their existing request fields and validation rules.
I reviewed all 16 changed files and their affected data/request paths. This was a static review; I did not execute tests.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| """ | ||
| root = module_path.resolve().parents[2] | ||
| for value in vars(module).values(): | ||
| name = value.__name__ if isinstance(value, ModuleType) else getattr(value, "__module__", None) |
There was a problem hiding this comment.
RISK: Dotted imports bypass the cross-root check.
Load a temporary environment_servers/other_root/task_input.py containing:
import resources_servers.nemo_user_sim.task_data
from pydantic import BaseModel
class TaskInput(BaseModel):
task_data: resources_servers.nemo_user_sim.task_data.TaskDataWhen the resource schema resolves to this checkout rather than the temporary root, this check does not reject it. The dotted import binds the resources_servers namespace, which has no source file. The wrapper class belongs to nemo_gym_task_input.other_root, so it is skipped too. The foreign leaf module's origin is never checked. Data tooling can therefore validate against another root's schema despite the loader's fail-closed contract.
Could you track and validate the component leaf modules imported by this load, including already-cached imports, instead of relying only on module-global objects and their __module__ values? The invariant is that import spelling cannot bypass same-root validation. The exact safe implementation needs care: scanning all of sys.modules would incorrectly include unrelated components.
Proposed acceptance checks: the example must raise TaskInputModuleError for a foreign-root schema and load for a same-root schema. Keep the direct-class rejection in the existing cross-root test, acceptance of same-root TaskData as TaskInput, and the dependency-free relay contract. An unrelated foreign component already in sys.modules must not reject a valid load. These are source-reasoned checks, not executed results.
There was a problem hiding this comment.
Fixed in 4dd7f30.
The check now follows the types TaskInput validates with, instead of the module's globals: the class, its bases, and every class its fields name, through generics and nested models.
Each resources_servers or environment_servers type among them must come from a file under the module's own root, so the dotted spelling is refused.
A foreign module that is imported but not used by TaskInput no longer matters, and nothing scans sys.modules.
Tests cover the dotted wrapper (refused) and an unused foreign import (allowed); the shipped nemo_user_sim module covers the same-root TaskData as TaskInput case.
| or any(module == layer or module.startswith(f"{layer}.") for layer in allowed_nemo_gym) | ||
| # A package facade such as nemo_gym.server_runtime, whose layers are listed per submodule. | ||
| # Its exports are lazy, so importing a name loads only that name's module. | ||
| or any(layer.startswith(f"{module}.") for layer in allowed_nemo_gym) |
There was a problem hiding this comment.
NOTE, suggestion: Check each imported name's target before allowing an ancestor facade.
This branch accepts from nemo_gym import environment because allowed layers start with nemo_gym., although nemo_gym.environment is above data in the layer contract. It also accepts from nemo_gym.server_runtime import supervisor, bypassing the explicit supervisor exclusion. The advertised dependency guard therefore misses imports it rejects when spelled directly. No shipped task-input module currently uses these examples.
Could you resolve each ImportFrom alias to its submodule or lazy public-export target before applying the allowed-layer predicate? Using a facade should not admit a target that a direct import rejects. Keep legitimate facade exports such as SingleAgentTurnTaskInput, whose target is allowed. Resolution must handle both real submodules and lazy exports, so a blanket rejection of ancestor packages would break valid imports.
Proposed acceptance checks: reject the two snippets above; continue accepting from nemo_gym.server_runtime import SingleAgentTurnTaskInput, from nemo_gym.core import NeMoGymResponseCreateParamsNonStreaming, and resources-server task_data imports. I did not execute these checks.
There was a problem hiding this comment.
Done in 4dd7f30: the test resolves each from-import to the submodule, or to the module that the package's _PUBLIC_API maps the name to, before applying the layer rule, and the ancestor-facade exception is gone. A test checks that from nemo_gym import environment and from nemo_gym.server_runtime import supervisor resolve to disallowed modules, and that SingleAgentTurnTaskInput resolves to server_runtime.single_agent_turn_types.
4954c57 to
a1c0e0a
Compare
4dd7f30 to
5caad12
Compare
a1c0e0a to
78b0d96
Compare
1ef8502 to
4e5b287
Compare
Each environment server now ships task_input.py, exporting the TaskInput its episode request is parameterized by, so the server and data tooling share one definition. A relay (legacy_agent, misalignment_monitored) sets TaskInput = None. single_agent_turn_legacy sets ACCEPTS_FLAT_ROWS, because its /run also materializes flat rows. swe_together's TaskData and SOURCE_REVISION move into its module, and task.py re-exports them. nemo_gym/data/task_input.py loads these modules by file path, without the server's dependencies, and refuses one that imports a component from another root. Tests require every in-repo environment server to ship the module, enforce the import rule from pyproject's layers, and check that each server's request_model uses its module's TaskInput. Signed-off-by: Ananth Subramaniam <[email protected]>
569a391 to
972fa94
Compare
4e5b287 to
279a980
Compare
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]>
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]>
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]>
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]>
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]>
…test cases (NVIDIA-NeMo#5534) * feat(bird_interact): grade BIRD-Interact's management tasks by their 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]> * fix(bird_interact): isolate agent SQL on PostgreSQL and attribute grading 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]> * fix(bird_interact): grade a submission against a broken solution as the 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]> * fix(bird_interact): show a-Interact agents only the knowledge fields 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]> * fix(bird_interact): run agent SQL as a role that is not a superuser, 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]> * docs(bird_interact): say that management phases are graded by their test cases in the environment list NVIDIA-NeMo#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]> * test(bird_interact): cover the setup failure, the SQLite image fallback 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]> * fix(bird_interact): end the turn at a submission that cannot be graded; 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]> * feat(bird_interact): ship the episode's task input as task_input.py 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 (NVIDIA-NeMo#6447 → NVIDIA-NeMo#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]> * test(bird_interact): SQL with a NUL or a lone surrogate is the query's error, not a runner crash Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]> * refactor(bird_interact): keep task_input.py to the row schema 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]> * fix(bird_interact): close the shared-state channels to the solution SQL, 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]> * docs(bird_interact): name task_input.py as the row schema in the config and schemas.py Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]> --------- Signed-off-by: Felipe Vieira Frujeri <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Before and after
Before: each environment server defines its episode
TaskInputwherever itsapp.pyneeds it: in corenemo_gymforsingle_agent_turnand Harbor, in a resources server'stask_data.pyfornemo_user_sim, and inschemas.pyforswe_together. Data tooling cannot find a server's model without importing itsapp.py, which needs the server's dependencies.After: every environment server ships
task_input.pynext toapp.py, exporting the oneTaskInputits request model uses. Data tooling loads it by path, without the server's dependencies. Nothing uses the modules yet:gym env validatedoes in #6448, and collation in #6449.flowchart LR TI["environment_servers/X/task_input.py exports TaskInput"] TI --> APP["app.py: request_model = BaseEpisodeRequest[TaskInput]"] TI --> VAL["gym env validate, in a later PR"] TI --> COL["gym dataset collate, in a later PR"]What changed and why
task_input.pyexportssingle_agent_turnSingleAgentTurnTaskInputsingle_agent_turn_legacySingleAgentTurnTaskInput, andACCEPTS_FLAT_ROWS = True, because its/runmaterializes a flat row and validates it asTaskInputharborHarborTaskInputnemo_user_simTaskDataswe_togetherTaskInput;TaskDataandSOURCE_REVISIONmove here, andtask.pyre-exports themlegacy_agent,misalignment_monitoredTaskInput = None: a relay, which passes flat rows to an agent's/runand takes no task rowsnemo_gym/data/task_input.pyloads a module by file path, astask_data.pymodules are loaded, so servers under extra search roots load too. It returns the contract, or None when the server ships no module. It refuses a module that does not import, exports noTaskInput, setsACCEPTS_FLAT_ROWSon a relay, or whoseTaskInputvalidates with aresources_serversorenvironment_serverstype from another root than its own (a checkout validating against an installed copy's model). The loader finds those types by followingTaskInput, its bases and its field types, so the spelling of the import does not matter.find_task_input_contractfinds the module under the component search roots and caches each load by resolved folder.A module may import only the standard library, pydantic, resources servers'
task_data.pymodules, andnemo_gympackages at or belownemo_gym.datain the import-linter layers.Issue
None filed. A preparatory change for #6448 and #6449.
Validation
single_agent_turn_legacyaccepts flat rows, and only the two relays setTaskInput = None.nemo_gympackages frompyproject.toml's layers.TaskInputdoes not use, and a missing folder or module. The import-rule test resolves each from-import to the module that defines the name, so a package facade cannot admit a module a direct import would not.request_modelusesMaterializedTask[TaskInput]from its module.Rollout evidence
N/A. No server behavior changes: each server's request model uses the same type as before.
Compatibility
SWETTaskInputis replaced byswe_together'stask_input.TaskInput. Nothing in Gym or NeMo RL main imported it.swe_together'stask.pystill exportsTaskDataandSOURCE_REVISION.