Skip to content

fix(telemetry): attribute client cancellations by route and response phase - #4028

Merged
ananthsub merged 4 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/log-every-generating-499
Oct 15, 2026
Merged

ananthsub merged 4 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/log-every-generating-499

Conversation

@linj-glitch

@linj-glitch linj-glitch commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Client cancellations now extend #4474's existing gym.server.requests.cancelled_total counter with bounded route templates and response-start phases.
Route attribution follows each server's prefix rules, including resource routes containing training-token-capture, and cumulative labeled buckets count each cancellation once.
Headers-only responses and SSE keepalives count as response_started; stdout remains sampled once per 100 cancellations, with elapsed time and phase available through the existing request-debug override.
The metrics documentation explains aggregation across route/phase series and the distinction between per-server cancellations and unique rollouts.
Validation passed: 332 native targeted tests and full pre-commit, plus the earlier 23 documentation link tests and Fern checks; Fern's authenticated redirect check was unavailable.
Model rollouts are N/A for this diagnostics-only change, and no separate issue is needed for this focused review revision.

@copy-pr-bot

copy-pr-bot Bot commented Oct 4, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33 yaoyu-33 added area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 5, 2026
@linj-glitch
linj-glitch marked this pull request as draft October 5, 2026 06:11
@linj-glitch
linj-glitch force-pushed the linj/log-every-generating-499 branch from 9a63e2d to 6468ccd Compare October 8, 2026 00:15
…ming

ClientDisconnectCancellationMiddleware counts client disconnects (499) but
prints only one line per 100 and no timing. In an async RL run about 3,900
such cancels masked 35% of one training job's rollouts, and the sampled lines could
not tell whether the client gave up while waiting for the first byte
(queueing, prefill, a client-side request timeout), abandoned a response
that was already streaming (an idle-stream timeout), or was a harness
cancelling speculative calls.

Disconnects on routes where a cancel discards a generation or a rollout
(/v1/messages, /v1/chat/completions, /v1/completions, /v1/responses, /run)
are now logged every time, with the elapsed seconds and "before first byte"
or "mid-stream" plus the response body bytes already sent. Other routes
keep the sampled line, which gains the same detail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
@linj-glitch
linj-glitch force-pushed the linj/log-every-generating-499 branch from 6468ccd to cf3988a Compare October 8, 2026 00:20
@linj-glitch
linj-glitch marked this pull request as ready for review October 13, 2026 23:08

@ananthsub ananthsub 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.

Most of what this PR needs, though, already exists on main. the PR should build on it rather than add a parallel log path.

Rebase needed. This branch conflicts with main in nemo_gym/server_utils.py. #4474 split the middleware into __call__ and _handle(scope, receive, send, counts) and added counts.cancelled += 1 in the same block this PR rewrites (server_utils.py).

What main already records for a disconnect:

  • gym.server.requests.cancelled_total counts every disconnect in this middleware (telemetry/observer.py). It has no route, phase, or duration yet.
  • When model-call capture is on, each cancelled model call is written with error_category set to cancelled, latency_ms, and ttft_ms, keyed by rollout and model call (base_responses_api_model.py). ttft_ms is empty when no token was sent, which is the before/after-first-token signal this PR is after.

The diagram shows one rollout cancel and what each server records for it:

flowchart TD
    T["Trainer cancels a rollout"] -->|"closes connection"| A["Agent server: POST /run"]
    A -->|"cancels its in-flight model call"| M["Model server: POST /v1/chat/completions"]
    A -->|"this PR"| L1["print: 499 CLIENT DISCONNECTED"]
    M -->|"this PR"| L2["print: 499 CLIENT DISCONNECTED"]
    A -->|"main today"| C["gym.server.requests.cancelled_total"]
    M -->|"main today"| C
    M -->|"main today, capture on"| R["model-call record: error_category cancelled, latency_ms, ttft_ms"]
Loading

Suggested direction. Extend the existing counter rather than printing:

  • Add attributes to gym.server.requests.cancelled_total: the route template (not the raw path, which contains the rollout id under /ng-rollout/<id>/ and would make the attribute unbounded) and a phase attribute such as nemo.gym.request.phase with values before_response_start and response_started.
  • Optionally add a gym.server.requests.cancelled_duration_ms histogram with the same attributes, for the elapsed-time part.
  • Keep the stdout line sampled as it is today. Add the timing and phase fields to it only when request debug logging is enabled.

This removes the route list, labels keepalive streams correctly, and stays quiet during mass cancels. The inline comments cover the details.

Comment thread nemo_gym/server_utils.py Resolved
Comment thread nemo_gym/server_utils.py Resolved
Comment thread nemo_gym/server_utils.py Resolved
Comment thread tests/unit_tests/test_server_utils.py Resolved
Share the path selected by each prefix middleware through ASGI request state. Resolve cancellation labels against registered templates without stripping prefixes that the server did not accept.

Cover unsupported and invalid rollout prefixes plus resource routes containing training-token-capture. Preserve bounded cumulative counters and response-start phases.

Signed-off-by: Lin Jia <[email protected]>
@linj-glitch linj-glitch changed the title fix(server): log every client disconnect on generating routes with timing fix(telemetry): attribute client cancellations by route and response phase Oct 15, 2026

@ananthsub ananthsub 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.

LGTM, thanks for the contribution!

@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test 3e7a27f

@github-actions

Copy link
Copy Markdown
Contributor

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

Merged via the queue into NVIDIA-NeMo:main with commit 6f47998 Oct 15, 2026
48 of 53 checks passed

This branch was previously deployed

1 inactive deployment
public — 3e7a27f1 Deployed Oct 15, 2026 by copy-pr-bot[bot] via release / finalize / notify #5467
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 bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface 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