Repository navigation
feat(telemetry): export per-server startup spans and metrics - #4354
Merged
Merged
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. |
ananthsub
requested review from
hemildesai,
iguehring-nvidia and
oyilmaz-nvidia
October 9, 2026 21:28
ananthsub
marked this pull request as ready for review
October 9, 2026 21:31
Contributor
Contributor
There was a problem hiding this comment.
Thanks Ananth!
- A timeout or failure leaves the supervisor spans unended, so nothing is exported for the failed run (inline on
finish()). uvicorn_startupis reported before the app's lifespan runs, so lifespan work is in no stage (inline onreport_when_serving).
- nit:
nemo_gym/global_config.py:1606still says "orchestrator" (not part of the diff, so no inline comment). Please change it to "supervisor": "...so without this the supervisor would export spans and every server process would silently have no telemetry at all".
Attribute server startup latency by stage through nemo-lens. The supervisor opens gym.startup with one gym.startup.server span per server (spawn to first healthy probe); each server parents a gym.server.startup span, with one child per stage, to its supervisor span through a traceparent in its environment. Each Uvicorn worker of a multi-worker server reports a gym.server.startup.worker span the same way, starting from the main process's hand-off to Uvicorn. Adds the startup span group (in the default preset), the gym.server.startup_duration_ms and gym.server.startup_stage_duration_ms histograms, a launch-shell stamp separating venv setup from interpreter start, and a uvicorn_startup stage closed at the app's startup. Renames the orchestrator telemetry identity to supervisor. Signed-off-by: Ananth Subramaniam <[email protected]>
gym.server.startup_duration_ms only added health-poll noise on top of the stage histogram, which already covers each process from start to accepting connections. The per-server total stays visible as the gym.startup.server span in the startup trace. Signed-off-by: Ananth Subramaniam <[email protected]>
Write comments and docstrings one sentence per line, explain the startup stages without shorthand, and correct the stage histogram's description, which still said stages end at the call to uvicorn.run. Signed-off-by: Ananth Subramaniam <[email protected]>
…tup telemetry A startup that timed out or failed never ended its gym.startup span or the spans of servers that were not ready, so OpenTelemetry exported nothing for it, and spans those servers had already reported pointed at a parent that was never exported. The supervisor now ends every open startup span on failure with an error status and nemo.gym.startup.outcome set to timeout, failed, or interrupted, and records the stage it was in as unfinished. Completed startups report outcome=ready. A spin-up timeout raises ServerSpinupTimeoutError, a RuntimeError subclass, so the outcome can tell a timeout from other failures. The uvicorn_startup stage closed before the app's own lifespan startup ran, so work a server did there fell into no stage. It now closes after it. Also build SupervisorStartup once, in _start, and call the process 'supervisor' in the remaining global_config comment. Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub
force-pushed
the
ananthsub/server-startup-telemetry
branch
from
October 12, 2026 14:00
4cbe2ed to
3acb4b2
Compare
Contributor
Author
|
The |
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38281785858 |
oyilmaz-nvidia
pushed a commit
to osoblanco/Gym
that referenced
this pull request
Oct 19, 2026
…VIDIA-NeMo#3903) ## What changed and why Checkpoints emitted nothing. That left three failure modes invisible: - a prepare that stalled on one server; - a lease that expired and silently aborted a checkpoint; - a restore that took minutes. This PR adds spans and metrics through the existing nemo-lens telemetry, on the same pattern as the sandbox metrics. - **Spans** are in a new `checkpoint` span group. It is opt-in with `default,checkpoint`, because the `default` preset is deliberately coarse. It sits next to `main`'s per-server `startup` span group (NVIDIA-NeMo#4354), which is in the `default` preset and stays on by default; the two groups are independent. - **On every participant:** `gym.checkpoint.<operation>` for `prepare`, `commit`, `restore`, `resume`, `retire` and `forget`, and `lease_reopen` for each attempt to reopen after a lease expires. Each carries the checkpoint ID, participant kind, server instance, outcome and record count. - **Children for the steps that grow with the live set:** `wait_ready`, `export`, `write`, `read`, `install`, and the policy model's `generation_cut` round, which also records each cut's disposition. - **In the controller:** `gym.checkpoint.coordinate.<operation>`, with one child per prepare stage. Rollout collection's own spans come with NVIDIA-NeMo#3893, which is no longer below this PR. - **One trace per checkpoint:** control calls go through Gym's traced HTTP client, so a checkpoint is one trace across every Gym process. - **Metrics** are recorded whenever telemetry exports, independent of span groups: - `gym.checkpoint.operation_duration_ms`, by operation, participant kind and outcome; - `gym.checkpoint.records_total` and `gym.checkpoint.bytes_total` (unit `By`), for commit and restore, counted once per write that finishes and per restore whose install succeeds, so a retry never counts the same volume twice; - `gym.checkpoint.control_errors_total`, by error code: every failed control call, counted once in the control routes; - `gym.checkpoint.events_total`, which counts: - `lease_expired`: once per checkpoint whose lease expired, which aborts that checkpoint; each attempt to reopen afterwards is a `lease_reopen` operation with its own outcome; - `prepare_not_ready`: a prepare reached its deadline with blockers, with the full blocker count; - `generation_cut`: each cut, by disposition. - **No file system calls on the event loop.** The store's writer and reader threads return the size of the records file, so commit and restore measure their volume without a `stat` on the event loop while the control lock is held. - **Docs.** `span-groups.mdx` lists the `checkpoint` group and how to enable it, and `metrics.mdx` lists every `gym.checkpoint.*` instrument with its unit and attributes. - **Cost when telemetry is off:** none. Every span sits behind the span-group check, and every metric recorder is a no-op. - **Attribute names avoid `key` and `token`,** which the span helpers redact. The spans were used to profile commit and restore at 16,000 rollouts. The fixes that profile led to are in the core, policy model, environment, resources, and agent PRs below (cheaper record payloads and ledger imports). ## How it works ### Where this PR sits in the overall flow The highlighted part is what this PR adds. ```mermaid flowchart LR C["Controller<br/>NeMo RL, or rollout collection"] CO["Coordination<br/>prepare, commit, restore, resume,<br/>retire, forget"] K["Control plane on every server<br/>phases, lease, storage,<br/>retire: refuse, stop, free;<br/>forget"] subgraph G["One participant per Gym server"] E["Environment server<br/>episode steps"] M["Policy model<br/>held responses, generation cuts"] A["Agent<br/>sessions parked at boundaries"] R["Resources server<br/>session state"] end W["Inference worker<br/>stages cut prefixes"] D[("Checkpoint directory<br/>records, then manifest")] L[("Capture ledger<br/>retire and delete from NVIDIA-NeMo#3938, NVIDIA-NeMo#3939")] C --> CO --> K K --> E & M & A & R M --> W M --> L G --> D classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937 class CO,K this ``` One checkpoint, a crash, and the restore, end to end: ```mermaid sequenceDiagram participant C as Controller participant G as Gym participants participant D as Checkpoint directory C->>G: prepare, in order environment, model, agent, resources Note over G: admission closes, in-flight work parks at a boundary,<br/>undelivered model responses are held G-->>C: prepared, or blockers at the deadline C->>G: commit with the episodes the controller continues G->>D: each participant writes its records, then its manifest Note over G: restored state the commit's scope leaves out is deleted C->>C: publish the checkpoint with the controller's own state C->>G: resume, in order resources, agent, model, environment Note over C,G: crash - every Gym process dies C->>G: restore the checkpoint in fresh processes, all or nothing D-->>G: records installed under attempt N+1, attempt N's capture ledger retired C->>G: resume C->>G: /run as attempt N+1 continues each episode from its boundary Note over C,G: retiring an episode, only while no checkpoint is open C->>G: retire - environment, then agent, then model and resources Note over G: each server marks the attempt, stops its work, waits, frees its state, then replies C->>G: forget, once the rollout is done for good - same order Note over G: the mark refusing the retired attempt goes away ``` ### This PR The spans of one checkpoint. Control calls carry the trace context, so the controller's spans and every participant's spans form one trace across Gym's processes. ```mermaid flowchart LR P["coordinate.prepare"] --> PS["one span per stage<br/>environment, model, agent, resources"] PS --> SP["prepare on each participant"] --> WR["wait_ready"] SP --> GC["generation_cut<br/>policy model only"] C["coordinate.commit"] --> SC["commit on each participant"] --> EX["export"] SC --> WRT["write"] R["coordinate.restore"] --> SR["restore on each participant"] --> RD["read"] SR --> IN["install"] ``` ## Where this sits in the stack This is one PR in a stack of draft PRs for partial-rollout checkpointing. Each PR is one commit, and its base is the branch of the PR before it, so each diff shows only that PR's change. The stack builds on the token-capture cleanup PRs NVIDIA-NeMo#3938 (capture ledger `retire` and `delete`) and NVIDIA-NeMo#3939 (complete-record `retire` and `delete`), which have merged. NVIDIA-NeMo#3882 to NVIDIA-NeMo#3889 have merged too, so NVIDIA-NeMo#3903's base is `main`. The checkpoint stack uses those operations to free the ledgers of retired attempts and to clear a dead execution's capture files before a restore. The capture-ledger cache bound (NVIDIA-NeMo#4268) and the striped lock files (NVIDIA-NeMo#3937) are independent of the stack. 1. NVIDIA-NeMo#3882 (`ananthsub/partial-ckpt-core`): feat(checkpoint): add the participant control plane, episode steps, and coordination (merged) 2. NVIDIA-NeMo#3883 (`ananthsub/partial-ckpt-policy-model`): feat(checkpoint): make policy model servers checkpoint participants with generation cuts (merged) 3. NVIDIA-NeMo#3884 (`ananthsub/partial-ckpt-model-worker-cuts`): feat(token-capture): add worker staging helpers for generation cuts (merged) 4. NVIDIA-NeMo#3885 (`ananthsub/partial-ckpt-environment`): feat(checkpoint): continue environment server episodes from their boundaries (merged) 5. NVIDIA-NeMo#3886 (`ananthsub/partial-ckpt-resources`): feat(checkpoint): add the resources server participant with asynchronous session hooks (merged) 6. NVIDIA-NeMo#3887 (`ananthsub/partial-ckpt-verifier-declarations`): feat(checkpoint): declare twenty training verifiers stateless with replayable verification (merged) 7. NVIDIA-NeMo#3888 (`ananthsub/partial-ckpt-agent`): feat(checkpoint): add the agent session participant and Simple Agent continuation (merged) 8. NVIDIA-NeMo#3889 (`ananthsub/partial-ckpt-e2e`): test(checkpoint): add a process-level end-to-end suite driven by coordination (merged) 9. NVIDIA-NeMo#3903 (`ananthsub/partial-ckpt-telemetry`): feat(checkpoint): spans and metrics for partial-rollout checkpoints **(this PR)** 10. NVIDIA-NeMo#3909 (`ananthsub/partial-ckpt-multi-worker`): feat(checkpoint): resources, agent, and environment servers with several workers 11. NVIDIA-NeMo#4197 (`ananthsub/partial-ckpt-fault-tests`): test(checkpoint): check checkpoint invariants over random sequences of operations NVIDIA-NeMo#3893 (`ananthsub/partial-ckpt-rollout-collection`, checkpoint evaluation runs from rollout collection) is independent of this chain and targets `main`. Its two spans, `gym.checkpoint.collection.checkpoint` and `gym.checkpoint.collection.restore`, are added to it once NVIDIA-NeMo#3903 merges, or in a small follow-up if NVIDIA-NeMo#3893 merges first. Server ports that build on the stack: NVIDIA-NeMo#3894 (Workplace Assistant), NVIDIA-NeMo#3895 (Gymnasium), NVIDIA-NeMo#3896 (Blackjack), NVIDIA-NeMo#3897 (indirect prompt injection), NVIDIA-NeMo#3898 (proof refinement). Session routing for several workers is NVIDIA-NeMo#3905, against main. ## Issue No tracking issue exists. Observability was a planned follow-up for the stack. ## Validation Run on this branch, on the current `main`: - `RAY_TMPDIR=/tmp .venv/bin/python -m pytest -q -p no:cacheprovider tests/unit_tests/telemetry tests/unit_tests/test_checkpoint_*.py`: passed. - `tests/unit_tests/telemetry/test_checkpoint_telemetry.py` drives a real resources participant through its control routes and asserts against a real in-memory span exporter and metric reader: - every operation span, with export and write nested under commit and read and install under restore; - durations, records and bytes; - each failed control call counted once by its error code, with building the error reply recording nothing, and a failed operation recorded with `outcome=error`, including a resume that fails on a participant; - a lease expiry counted once while several reopen attempts fail, each attempt recorded with its outcome; - commit and restore volume counted once when a retry reuses a finished write or follows a failed install, measured without a `stat` on the event loop; - a prepare span carrying the full blocker count when more blockers exist than the report lists; - one coordination span per prepare stage. - The span-group tests now include `checkpoint` next to `main`'s `startup`; the `default` preset is unchanged, with `startup` in it and `checkpoint` out of it. - The full core unit suite (`tests/unit_tests`, eight processes, without `test_opensandbox_compose.py`, which needs the optional `opensandbox` package): passed except a sandbox retry test, which fails the same way on `main` in this development environment. - `pre-commit run --files <files changed by this PR>`: all hooks passed, and no hook modified a file. - Every commit carries a `Signed-off-by` line. ## Rollout evidence The 16,000-rollout scale test was profiled with the console exporter. The per-participant breakdown is in the next PR. Real-model runs are in NVIDIA-NeMo#3889, NVIDIA-NeMo#3893 and NVIDIA-NeMo#3909. ## Compatibility - **New span group:** `checkpoint`, opt-in. Existing presets are unchanged, so `main`'s `startup` group stays on by default. - **New metric instruments** under `gym.checkpoint.*`, listed in `metrics.mdx`. - Control errors are counted by `gym.checkpoint.control_errors_total` with the `nemo.gym.checkpoint.error_code` attribute; there is no `refused` event, and refusals of data-plane requests are not counted. - `write_participant_state` and `read_participant_state` in the private `nemo_gym/_checkpoint/store.py` also return the byte count; the on-disk format is unchanged. - Nothing changes when telemetry is off. Signed-off-by: Ananth Subramaniam <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Server startup time is now exported through nemo-lens, broken down per server and per stage. When a
gym eval runorgym env startis slow to become ready, the startup trace shows which server was slow and which part of its startup took the time.Startup is split between two kinds of process, and neither can see all of it. The supervisor, which is the process running
gym env startorgym eval run, knows when it spawned each server and when that server first answered a health probe. Each server knows what it did after its interpreter started, but it cannot see the venv setup that ran before the process existed.The supervisor opens a
gym.startupspan, with one child span per stage of its own work and onegym.startup.serverspan per server. Eachgym.startup.serverspan runs from spawning the server to the server's first answered health probe. The supervisor passes atraceparentfor that span to the server in its environment, and the server parents its owngym.server.startupspan to it, with one child span per stage. One startup is therefore one trace across every process.Each server reports these stages, which are contiguous and add up to the time from spawn until the server accepts connections:
venv_setup: venv creation and dependency installation in the launch shell.interpreter_start: the interpreter starting and importing the server module and its dependencies.load_config,init_ray,init_server,init_telemetry,setup_webserver,expose_tools_over_mcp,configure_app: the steps ofrun_webserver.init_rayandexpose_tools_over_mcponly appear for servers that use them.uvicorn_startup: from the end of app configuration until the app's own lifespan startup finishes and Uvicorn begins accepting connections. Work a server does in its lifespan, such as loading data, is part of this stage.The launch command now records the time venv setup finished, which is what separates
venv_setupfrominterpreter_start. A server sends its spans when the app's lifespan startup finishes, with explicit timestamps, because telemetry is only initialised partway through startup.Every startup span carries
nemo.gym.startup.outcome. A startup that completes reportsready. A startup that times out, fails, or is interrupted still exports its trace: the supervisor endsgym.startupand the span of every server that was not ready yet withtimeout,failed, orinterruptedand an error status, and records the stage it was in asunfinished. The spans that servers already reported therefore keep an exported parent.Each Uvicorn worker of a multi-worker server runs
run_webserveragain and reports agym.server.startup.workerspan the same way. A worker's first stage isworker_start, which runs from the main process handing off to Uvicorn to the worker enteringrun_webserver. The main process of that server reports its stages up to the hand-off.The same stages are recorded in one histogram,
gym.server.startup_stage_duration_ms. Its points carrynemo.gym.server.name,nemo.gym.server.type,nemo.gym.startup.stage, andnemo.gym.server.worker. There is no supervisor-side total, because the supervisor only learns that a server is ready from a health poll every few seconds. The total for each server is thegym.startup.serverspan.Every telemetry step is guarded, so a telemetry failure cannot stop a server from starting. With telemetry off, no spans or metrics are created.
Why
Starting a fleet of servers is often the largest fixed cost of a short evaluation, and none of it was attributed.
gym eval runprinted a count of ready servers every 30 seconds, andgym.jobonly opens after startup has finished.Issue
Related to #3155, which defines the shared telemetry contract for Gym processes. Startup attribution is not in that issue's scope, so this PR does not close it, and no other open issue covers startup attribution.
Compatibility
orchestratortosupervisor, in bothservice.nameandnemo.gym.server.type. "Orchestrator" collides with the orchestration part of Gym. Dashboards that filter on the old name need to be updated.startupspan group is in thedefaultpreset. It is not inper_rollout, because startup happens once per run rather than once per rollout.gym.job, and both carry the samerun_id. A server started withgym env starthas no job, so startup has to stand on its own.gym.startup.serverspan therefore ends before every worker is up, and the worker spans show when the rest finished.gym.startup.serverspan with the startup's outcome and an error status.ServerSpinupTimeoutError, a subclass ofRuntimeError, so callers that catchRuntimeErrorare unaffected.NEMO_GYM_STARTUP_SPAWN_NS,NEMO_GYM_STARTUP_SETUP_DONE_NS,NEMO_GYM_STARTUP_SERVE_NS, andNEMO_GYM_STARTUP_TRACEPARENT.Validation
pre-commit run --all-filespytest tests/unit_tests -n 16with thetelemetryextra installed. The tests intest_opensandbox_compose.py,test_sandbox_stop_retry.py,test_reward_profile.py,test_dataset_orchestrator.py, andtest_exporters.pyneed optional packages (opensandbox,tenacity,wandb,mlflow) that were not installed, and fail on import.tests/unit_tests/telemetry/test_startup.pycovers span nesting across the supervisor, server, and worker spans; one histogram point per stage; the worker attribute; the span-group gate; that a telemetry failure never reaches the server; and that a server reports only once Uvicorn runs the app's startup, with the app's own lifespan still running.tests/unit_tests/test_cli_server_launch.pyruns the launch shell's setup-finished timestamp in a real shell.gym env start --resources-server example_single_tool_call --model-type vllm_modelwithNEMO_GYM_OTEL_ENABLED=1 NEMO_GYM_OTEL_EXPORTER=console, against a model URL that does not answer and with model endpoint readiness checks off. The console output contains one trace across all five processes, with each server's span nested under the supervisor's span for it, and the stage histogram is flushed at shutdown.+server_spinup_timeout_seconds=3, which times out before the servers are ready. The console output contains one trace with no orphaned spans:gym.startupand everygym.startup.serverspan end withnemo.gym.startup.outcome=timeoutand an error status, and the stages includeunfinished.num_workers=3on the resources server. Each worker reports its owngym.server.startup.workerspan under the supervisor's span.example_single_tool_calldoes not support multiple workers, so this run used a local entrypoint change that is not part of this PR.Rollout evidence
N/A. This change adds observability of server startup and does not change agent, model, or verifier behavior, so a model rollout would not exercise it. The startup path was exercised by the
gym env startruns above.