Repository navigation
feat(telemetry): stamp the rollout id on sandbox spans - #4752
Conversation
`gym.sandbox.start`, `gym.sandbox.exec` and `gym.sandbox.stop` now carry `nemo.gym.rollout.id` when they run inside a rollout context, the same correlation attribute Gym's endpoint and model-call spans carry. A rollout's sandbox time becomes filterable by attribute, not only through the parent chain. Outside a rollout the attribute is absent, as before. Signed-off-by: Ingo Guehring <[email protected]>
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
HOLD — 1 BLOCKER and 1 RISK.
The new import creates an import-order-dependent startup failure on normal CLI/server paths. Separately, failed sandbox starts and execs miss the rollout attribute because it is attached only after the awaited operation succeeds.
Reviewed both changed files and their directly affected import, correlation, and telemetry contracts. Findings are source-validated; tests could not be executed in this read-only review.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex
| from pathlib import Path | ||
| from typing import Any, TypeVar | ||
|
|
||
| from nemo_gym.rollout_correlation import current_rollout_id |
There was a problem hiding this comment.
BLOCKER — Defer the correlation import to avoid breaking startup
Failure / blast radius: In a fresh interpreter, import nemo_gym.global_config now encounters a circular import. global_config imports the sandbox registry, which initializes the sandbox package and its API. This new import then loads rollout_correlation, which imports constants from the still-initializing global_config; those constants are not defined until lines 263–272. The result is ImportError, not a usable module. Normal gym env start reaches this path through cli.env → setup_command → global_config, even with telemetry disabled. Importing the sandbox first can mask the problem in a shared test process.
Correction: Remove the module-level import and resolve it inside _rollout_attributes, below the existing telemetry gates. Suggested replacement at the helper, retaining its docstring:
def _rollout_attributes() -> dict[str, str]:
from nemo_gym.rollout_correlation import current_rollout_id
rollout_id = current_rollout_id()
return {"nemo.gym.rollout.id": rollout_id} if rollout_id else {}This restores the invariant that importing the sandbox API does not require rollout correlation while global configuration is initializing. Verify this suggestion before adopting it.
Preservation / proposed acceptance (not run): Add separate fresh-interpreter subprocess checks for import nemo_gym.global_config, import nemo_gym.rollout_correlation, import nemo_gym.server_utils, and import nemo_gym.sandbox.api; each must exit 0. Retain the correlation assertions: all three lifecycle spans carry 7-0 inside that context and omit the key outside it. Retain the disabled-group assertion: exec returns 0 and no spans are emitted. The local import must remain reachable only on enabled instrumentation paths.
There was a problem hiding this comment.
Confirmed with a fresh interpreter: import nemo_gym.global_config failed on the branch and worked on main. Fixed in a15da3e: the import moved inside _rollout_attributes, with a comment on why. A fresh-interpreter import check guards the entry point that broke.
| "nemo.gym.sandbox.id": _sandbox_id(self._handle), | ||
| "nemo.gym.sandbox.return_code": result.return_code, | ||
| "nemo.gym.sandbox.error_type": result.error_type, | ||
| **_rollout_attributes(), |
There was a problem hiding this comment.
RISK — Attach rollout correlation before awaiting start/exec
Failure / blast radius: With sandbox tracing enabled and rollout_context("7-0"), let a stub provider's create() or exec() raise RuntimeError("boom"). The lifecycle span records the failure, but lacks nemo.gym.rollout.id: both start and exec attach it only after the await succeeds. Consequently, the new per-rollout attribute filter excludes precisely these failed operations and their time. Expected: correlation is present independently of provider success, as it already is for stop. This affects diagnostics, not sandbox execution results.
Correction: In AsyncSandbox.start() and AsyncSandbox.exec(), replace the initial managed_span attribute argument with:
**{"nemo.gym.sandbox.provider": provider_name, **_rollout_attributes()},Remove _rollout_attributes() from their success-only attribute updates. Keep the sandbox ID after successful creation, and keep return-code/error-type attributes after an exec result exists. The invariant is that call-context correlation is attached before fallible work, while result-dependent metadata is attached only when available. This also works with the deferred helper import proposed above; verify the suggestion before adopting it.
Preservation / proposed acceptance (not run): Add failing-create and failing-exec stub cases under rollout_context("7-0"); assert the corresponding finished span has ERROR status and rollout ID 7-0, and the original RuntimeError still propagates. Retain the current successful all-three-spans correlation case, plus the nonzero-exit case: returning code 3 remains a normal result and records code 3. Exercise start, exec and stop outside a rollout and assert the key is absent. Retain disabled-group behavior and command confidentiality: no spans when disabled, and no SECRET_FLAG in exec attributes.
There was a problem hiding this comment.
Fixed in a15da3e. The rollout id is now passed to managed_span for gym.sandbox.start and gym.sandbox.exec, so it is on the span before the awaited provider call; the sandbox id stays attached after a successful create, return code and error type after an exec result. Tests: a provider that raises in create and one that raises in exec, each under rollout_context("7-0"), assert ERROR status, rollout id 7-0 and the propagated RuntimeError; start, exec and stop outside a rollout assert the key is absent.
…and stamp the id before the awaited work Importing it at module level created an import cycle: global_config imports the sandbox registry while initialising, and rollout_correlation imports constants from global_config, so a fresh `import nemo_gym.global_config` failed. The import now lives inside the helper. The rollout id is attached when the start and exec spans open, not after the provider call returns, so a failed start or exec keeps its correlation. Fresh-interpreter import checks and failing-provider cases are added to the tests. Signed-off-by: Ingo Guehring <[email protected]>
|
/review |
…box API cycle Signed-off-by: Ingo Guehring <[email protected]>
Signed-off-by: Ingo Guehring <[email protected]>
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP — LGTM — no reliability concerns within the eligible follow-up scope.
Compared all four changed files with the previously reviewed head. The historical fixes remain intact: rollout lookup is deferred in telemetry setup, rather than imported during sandbox initialization, and start/exec attributes are still attached before awaiting provider work. The failure regressions retain assertions for propagated exceptions, ERROR status, and rollout correlation.
Reviewed the new registration path, disabled-instrumentation gates, attribute precedence, and directly affected import contracts. No unresolved prior findings or introduced regressions eligible above the historical high-impact ceiling remain.
Validation was source-only; tests and fresh-interpreter import checks were not executed.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex
| ) | ||
|
|
||
|
|
||
| #: Extra attributes for every sandbox span, supplied by whoever runs the sandbox. The sandbox |
There was a problem hiding this comment.
this approach looks good. Can you just move this to nemo_gym/sandbox/observability.py?
There was a problem hiding this comment.
Moved to nemo_gym/sandbox/observability.py in b029bcf; api.py only consumes it.
…ox/observability.py The seam the embedding application registers its extra span attributes through now lives in its own module, as asked in review; the sandbox API only consumes it. Signed-off-by: Ingo Guehring <[email protected]>
|
/ok to test 4dbfc8b |
| from pathlib import Path | ||
| from typing import Any, TypeVar | ||
|
|
||
| from nemo_gym.sandbox.observability import span_attributes as _span_attributes |
There was a problem hiding this comment.
can you rename this to from nemo_gym.sandbox.observability import span_attributes as default_span_attributes
There was a problem hiding this comment.
Renamed in 9c542be: from nemo_gym.sandbox.observability import span_attributes as default_span_attributes, used at the three call sites.
Signed-off-by: Ingo Guehring <[email protected]>
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39492762972 |
What does this PR do?
Adds
nemo.gym.rollout.idto the three sandbox lifecycle spans (gym.sandbox.start,gym.sandbox.exec,gym.sandbox.stop) when they run inside a rollout, the same attribute the endpoint wrappers put ongym.rollout,gym.verifyand the model-call spans.Why: sandbox spans were only correlated to their rollout through the parent chain. With the id on the span, "all sandbox execs of rollout 3-0" is an attribute filter in a trace backend, and a rollout's sandbox time can be summed without walking the tree. Outside a rollout nothing is added, so standalone sandbox use is unchanged. The command text stays off the span, as before.
How, after review (2ee6bc3, moved to its own module in the follow-up commit): the sandbox package does not learn about rollouts.
nemo_gym/sandbox/observability.pyexposesset_span_attribute_provider(callable), whose attributes are added to everygym.sandbox.*span when it opens, andAsyncSandbox.start()andexec()take an optionalspan_attributesargument that wins over the provider key by key. Gym's telemetry setup registers the rollout-id provider once, next to the span-group registration. Every existing call site (about twenty resources servers and agents callAsyncSandboxdirectly) is covered without changes, andnemo_gym.sandboximports nothing fromrollout_correlationorglobal_config, which also removes the import-order hazard the first version had.No issue; small follow-on to the sandbox instrumentation (#3633).
Validation
pytest tests/unit_tests/telemetry/test_call_sites.py tests/unit_tests/telemetry/test_setup.py: 61 passed (plus the pre-existing macOS-only gauge failure). Tests: all three spans carry the id inside a rollout through the registered provider; none outside; a failingcreateorexeckeeps the id; no provider means no extra attributes even inside a rollout; explicitspan_attributeswin over the provider;init_telemetryregisters the provider.Previous validation of the earlier shape:
pytest tests/unit_tests/telemetry/test_call_sites.py tests/unit_tests/test_enroot_sandbox_facade.py tests/unit_tests/test_opensandbox_cleanup.py tests/unit_tests/test_opensandbox_compose.py: 48 passed; the one failure is the pre-existing macOS-onlytest_supervisor_is_the_only_writer_of_the_active_servers_gauge, identical onmain.New tests: inside
rollout_context("7-0")all three spans carry the id; outside a rollout none of them does.pre-commit run --files <changed files>: passed.Rollout evidence
N/A: attribute-only change on existing spans; sandbox behaviour is untouched.
Review follow-up
The automated review caught a real import cycle:
global_configimports the sandbox registry while initialising, and the new module-level import ofrollout_correlationread constants from the half-initialisedglobal_config, so a freshimport nemo_gym.global_configfailed. The import now lives inside the helper, with a comment on why; verified by importingglobal_configin a fresh interpreter (no dedicated test, by maintainer preference). The rollout id is also attached when the start and exec spans open rather than after the provider call returns, so a failed start or exec keeps its correlation; tests cover a provider that raises increateand inexec.pytest tests/unit_tests/telemetry/test_call_sites.py: 25 passed plus the known macOS-only failure.Sandboxed end-to-end run (added after opening)
Terminal-bench 4 miniswe on OpenSandbox sandboxes, 8 tasks, from a branch merging this PR with #4749, #4750 and #4751 on
main, with capture (observability_enabled) on. Sandboxes are driven by the resources server (/seed_session), not the agent. All 363 sandbox spans (25 start, 313 exec, 25 stop) carrynemo.gym.rollout.id, and for every one the id matches thegym.rolloutfound through its parent chain. A first attempt withobservability_enabled: falseshowed none, which is expected: that setting switches rollout correlation off entirely, so there is no id for any span to carry.Sandboxed end-to-end run of the provider-based shape (2ee6bc3)
Same terminal-bench 4 miniswe setup, 8 tasks, OpenSandbox, capture on, with the provider registered by telemetry setup and no sandbox-side lookup: all 354 sandbox spans (25 start, 304 exec, 25 stop), from both the resources server and the agent, carry
nemo.gym.rollout.id, and no span carries an id that disagrees with its rollout. Collector log clean, no token in the job directory.