Repository navigation
fix(telemetry): attribute client cancellations by route and response phase - #4028
Conversation
9a63e2d to
6468ccd
Compare
…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]>
6468ccd to
cf3988a
Compare
There was a problem hiding this comment.
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_totalcounts 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_categoryset tocancelled,latency_ms, andttft_ms, keyed by rollout and model call (base_responses_api_model.py).ttft_msis 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"]
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 asnemo.gym.request.phasewith valuesbefore_response_startandresponse_started. - Optionally add a
gym.server.requests.cancelled_duration_mshistogram 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.
Signed-off-by: Lin Jia <[email protected]>
…phase Signed-off-by: Lin Jia <[email protected]>
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]>
ananthsub
left a comment
There was a problem hiding this comment.
LGTM, thanks for the contribution!
|
/ok to test 3e7a27f |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38763462789 |
Client cancellations now extend #4474's existing
gym.server.requests.cancelled_totalcounter 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.