Skip to content

feat(observability): add per-rollout and per-run aggregate observability metrics - #2790

Merged
mlazuka merged 8 commits into
mainfrom
glazuka/automated-insights
Aug 27, 2026
Merged

mlazuka merged 8 commits into
mainfrom
glazuka/automated-insights

Conversation

@mlazuka

@mlazuka mlazuka commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Implements the P0 scope of the "Automated Insights" RFC (#1703): surfaces per-rollout token efficiency metrics that currently require custom extraction scripts against raw observability data.

  • ng_perf: a new field attached to each rollout record (alongside ng_trajectory/ ng_model_call_capture)
    • contains num_turns, num_tool_calls, prompt_tokens, cached_prompt_tokens, completion_tokens, reasoning_tokens, and an independently measured total_latency_ms
    • num_turns sums each invocation's own reasoning-turn count (explicit TrajectoryTurn records when the harness emits them, falling back to its resolved model-call count, then to 1) so a single invocation spanning many steps isn't undercounted as one turn
    • token fields exclude compaction-owned model calls so they reflect task-solving cost, not compaction overhead. Present only when observability_enabled=True and at least one reasoning turn was observed
    • each individual field is absent (not null) when its underlying data wasn't collected.
  • perf_summary: a new block in _aggregate_metrics.json
    • aggregates every rollout's ng_perf into mean/median/total token stats, mean/median tokens-per-turn, a full distribution (mean/median/std/min/p90/max) for num_turns, and p50/p90/p99/mean total_latency_ms
    • absent when no rollout in the run carried ng_perf.

Both are purely additive; see fern/versions/latest/pages/model-server/model-call-capture.mdx for the schema.

Completes P0 scope of #1703 (P1+ to follow).

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format/copyright pass).
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 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

Copy link
Copy Markdown
Contributor

@mlazuka
mlazuka marked this pull request as ready for review August 26, 2026 16:01
@mlazuka
mlazuka force-pushed the glazuka/automated-insights branch from 3150c25 to b7ae7a6 Compare August 26, 2026 16:02
@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 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.

@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test b7ae7a6

@ananthsub

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

SHIP — LGTM, no reliability concerns.

Reviewed the correctness-critical paths for this additive ng_perf/perf_summary observability feature:

  • No reward-metric contamination: ng_perf is a dict, and RewardProfiler.profile_from_data only promotes int/float/bool values into numeric metrics (reward_profile.py:230-234) — the perf dict cannot corrupt reward/score aggregation. compute_perf_summary writes only to the new perf_summary field.
  • No internal-key leak: _attach_ng_perf pops _ng_rollout_latency_ms before the observability gate (rollout_collection.py:468), so the timer key never persists regardless of the flag. Both run_examples callers (main loop + gdpval orchestrator) invoke it.
  • Honest wall-clock: latency measured inside async with semaphore (:1323), excluding queue-wait — matches the documented intent.
  • API-compatible: perf_summary is Optional[default=None] on AggregateMetrics; _call_aggregate_metrics forwards it only when present.
  • Edge cases handled & tested: None-on-empty keeps the field absent-not-null; single-value pstdev→0 not NaN; per-field presence gating; num_turns==0 excluded from tokens-per-turn; model-call dedup across conflicted invocations; build errors swallowed so an observability side-channel can't crash rollout collection.

The total_latency_p50_ms vs mean_prompt_tokens naming asymmetry is intentional and documented — not a finding.

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

Added two main comments I had, overall lgtm!

Comment thread nemo_gym/rollout_collection.py Resolved
Comment thread nemo_gym/reward_profile.py Resolved
@mlazuka

mlazuka commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b7aa596

@mlazuka

mlazuka commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Review incomplete: the PR revision changed during review. This review targeted head b7aa5965c27bcc608496c2229047f8c85579a37d (base 310d880426fae7251d5a024ce3fa81c6149413c6), but the current PR head is now 1ba8519248019404e1863ec30cf290dd32acdf79 (base ce9af1d07b39f3dc01b779f1e84b91d5b820eb76). Findings against the stale revision were withheld to avoid commenting on lines that may no longer exist. Please re-request review against the current head.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Aug 27, 2026
@mlazuka
mlazuka force-pushed the glazuka/automated-insights branch from 1ba8519 to ed84360 Compare August 27, 2026 19:56
@mlazuka

mlazuka commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ed84360

@mlazuka

mlazuka commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

SHIP WITH CARE — additive ng_perf/perf_summary observability. Correctness is sound; verifier/scoring paths untouched (ng_perf never feeds reward). One consistency gap.

RISK — perf_summary silently dropped on the reverification / gym eval aggregate path
nemo_gym/reward_profile.py:compute_aggregate_metrics now populates perf_summary, and rollout_collection.py:_call_aggregate_metrics (line ~1469) forwards it into the per-agent agent_entry. But the parallel nemo_gym/rollout_reverification.py:_call_aggregate_metrics (line ~624) builds its agent_entry from the same hand-picked allowlist (agent_metrics/key_metrics/group_level_metrics) and was not updated. WHAT BREAKS: rollouts re-aggregated via gym eval aggregate (or the reverification flow) that carry ng_perf will have their perf_summary computed server-side and then discarded from _aggregate_metrics.json. BLAST RADIUS: perf stats absent from any shard aggregated after the fact, even though present on the live-collection path — an easy-to-miss divergence. FIX: mirror the if agg_result.perf_summary is not None: agent_entry["perf_summary"] = agg_result.perf_summary block into rollout_reverification.py:_fetch_agent_metrics. The PR's own test_call_aggregate_metrics_includes_perf_summary_when_present guards the collection copy but there's no equivalent for the reverification copy.

NOTES (author's call):

  • _build_ng_perf token_observability_coverage = min(1.0, len(owned_calls)/num_turns): owned_calls counts resolved model calls across all invocations while num_turns can exceed that (per-invocation max(turns, owned_calls, 1) fallback), so coverage under-reports when some invocations report explicit turns but no resolved calls. Intentional per the docstring; just confirming it reads as designed, not a divide risk (num_turns >= 1 whenever invocations exist).
  • Compaction-call exclusion is correct: token sums iterate invocation.model_calls only, and compaction calls live on ContextCompactionObservation.model_calls, never on invocations.
  • _attach_ng_perf swallows all build exceptions and logs — good, an observability side-channel can't take down collection.

Async/API surface clean: no httpx, no ray.get, statistics/pandas.Series already imported, perf_summary field is Optional (back-compat safe), latency timer key stripped before persist.

Signed-off-by: Gosia Lazuka <[email protected]>
@mlazuka

mlazuka commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 55ea85f

@mlazuka
mlazuka merged commit bc433e5 into main Aug 27, 2026
37 checks passed
@mlazuka
mlazuka deleted the glazuka/automated-insights branch August 27, 2026 20:45

This branch was previously deployed

1 inactive deployment
public — 55ea85fd Deployed Aug 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #2135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Automated insights — Pareto of intelligence per token (Smart · Fastest · Lowest Cost)

3 participants