Skip to content

feat(telemetry): export per-server startup spans and metrics - #4354

Merged
ananthsub merged 4 commits into
mainfrom
ananthsub/server-startup-telemetry
Oct 12, 2026
Merged

ananthsub merged 4 commits into
mainfrom
ananthsub/server-startup-telemetry

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Server startup time is now exported through nemo-lens, broken down per server and per stage. When a gym eval run or gym env start is 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 start or gym 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.startup span, with one child span per stage of its own work and one gym.startup.server span per server. Each gym.startup.server span runs from spawning the server to the server's first answered health probe. The supervisor passes a traceparent for that span to the server in its environment, and the server parents its own gym.server.startup span 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 of run_webserver. init_ray and expose_tools_over_mcp only 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_setup from interpreter_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 reports ready. A startup that times out, fails, or is interrupted still exports its trace: the supervisor ends gym.startup and the span of every server that was not ready yet with timeout, failed, or interrupted and an error status, and records the stage it was in as unfinished. The spans that servers already reported therefore keep an exported parent.

Each Uvicorn worker of a multi-worker server runs run_webserver again and reports a gym.server.startup.worker span the same way. A worker's first stage is worker_start, which runs from the main process handing off to Uvicorn to the worker entering run_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 carry nemo.gym.server.name, nemo.gym.server.type, nemo.gym.startup.stage, and nemo.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 the gym.startup.server span.

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 run printed a count of ready servers every 30 seconds, and gym.job only 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

  • The supervisor's telemetry identity changes from orchestrator to supervisor, in both service.name and nemo.gym.server.type. "Orchestrator" collides with the orchestration part of Gym. Dashboards that filter on the old name need to be updated.
  • The new startup span group is in the default preset. It is not in per_rollout, because startup happens once per run rather than once per rollout.
  • Startup is a separate trace from gym.job, and both carry the same run_id. A server started with gym env start has no job, so startup has to stand on its own.
  • For a multi-worker server, the supervisor marks the server ready when the first worker answers. The gym.startup.server span therefore ends before every worker is up, and the worker spans show when the rest finished.
  • A server process that crashes before its app's lifespan startup finishes does not report its own stages. The supervisor still ends that server's gym.startup.server span with the startup's outcome and an error status.
  • A spin-up timeout now raises ServerSpinupTimeoutError, a subclass of RuntimeError, so callers that catch RuntimeError are unaffected.
  • The supervisor and servers exchange four new environment variables: NEMO_GYM_STARTUP_SPAWN_NS, NEMO_GYM_STARTUP_SETUP_DONE_NS, NEMO_GYM_STARTUP_SERVE_NS, and NEMO_GYM_STARTUP_TRACEPARENT.

Validation

  • pre-commit run --all-files
  • pytest tests/unit_tests -n 16 with the telemetry extra installed. The tests in test_opensandbox_compose.py, test_sandbox_stop_retry.py, test_reward_profile.py, test_dataset_orchestrator.py, and test_exporters.py need optional packages (opensandbox, tenacity, wandb, mlflow) that were not installed, and fail on import.
  • tests/unit_tests/telemetry/test_startup.py covers 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.py runs the launch shell's setup-finished timestamp in a real shell.
  • gym env start --resources-server example_single_tool_call --model-type vllm_model with NEMO_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.
  • The same run with +server_spinup_timeout_seconds=3, which times out before the servers are ready. The console output contains one trace with no orphaned spans: gym.startup and every gym.startup.server span end with nemo.gym.startup.outcome=timeout and an error status, and the stages include unfinished.
  • The same run with num_workers=3 on the resources server. Each worker reports its own gym.server.startup.worker span under the supervisor's span. example_single_tool_call does 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 start runs above.

@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:core Shared APIs, servers, telemetry, health, and registries labels Oct 9, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33 yaoyu-33 added complexity:high Cross-component or shared-contract change with a large review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 9, 2026

@iguehring-nvidia iguehring-nvidia left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ananth!

  1. A timeout or failure leaves the supervisor spans unended, so nothing is exported for the failed run (inline on finish()).
  2. uvicorn_startup is reported before the app's lifespan runs, so lifespan work is in no stage (inline on report_when_serving).
  • nit: nemo_gym/global_config.py:1606 still 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".

Comment thread nemo_gym/telemetry/startup.py Resolved
Comment thread nemo_gym/telemetry/startup.py Resolved
Comment thread nemo_gym/cli/env.py Resolved
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

Copy link
Copy Markdown
Contributor Author

The global_config.py comment now says "supervisor", in 3acb4b2.

@iguehring-nvidia iguehring-nvidia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ananth!

@ananthsub
ananthsub added this pull request to the merge queue Oct 12, 2026
@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/38281785858

Merged via the queue into main with commit 2ba988d Oct 12, 2026
51 checks passed
@ananthsub
ananthsub deleted the ananthsub/server-startup-telemetry branch October 12, 2026 17:20
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

1 inactive deployment
public — 3acb4b25 Deployed Oct 12, 2026 by copy-pr-bot[bot] via release / finalize / notify #5029
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants