Skip to content

fix: write traces on timeout (Apptainer) + improve Hermes traces - #1973

Merged
cmunley1 merged 11 commits into
NVIDIA-NeMo:mainfrom
elisam0:elisam0/fix-hermes-and-timeout-traces
Sep 4, 2026
Merged

cmunley1 merged 11 commits into
NVIDIA-NeMo:mainfrom
elisam0:elisam0/fix-hermes-and-timeout-traces

Conversation

@elisam0

@elisam0 elisam0 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fix Hermes agent traces and sandbox timeout handling

Summary

Ensures Hermes agent trajectories are captured and surfaced even when a run times out or fails, and makes the Apptainer sandbox timeout terminate processes gracefully so in-container agents can flush partial traces before being killed.

Changes

nemo_gym/sandbox/providers/apptainer/provider.py

  • On timeout, send SIGTERM to the process group first and wait a short grace period (default 15s, configurable via NEMO_GYM_SANDBOX_TIMEOUT_GRACE_S), then SIGKILL only if the process is still alive. This gives an in-container agent's SIGTERM handler a chance to flush a partial trace before it's hard-killed. Applied to both timeout paths.

responses_api_agents/hermes_agent/app.py

  • Reasoning in traces: emit assistant reasoning text as a NeMoGymResponseReasoningItem in the output items.
  • Incomplete detection: mark the response status="incomplete" when run_conversation reports it didn't complete (ran out of turns / blew the context window).
  • Interruption tracking: track interrupted agents (interrupted_agents set) via the SIGTERM dispatcher so timeouts are reflected in the response.
  • Diagnosability metadata: populate response metadata with interrupted, failed, partial, turns, and hermes_error, and set the structured error field (code="server_error", message from the harness error) when the run fails.

Motivation

Timeouts and failures previously produced empty or misleading traces (a hard kill left no trace; incomplete runs could score as passes). These changes preserve partial trajectories and expose run outcome, making failed and timed-out rollouts diagnosable.

Env vars

  • NEMO_GYM_SANDBOX_TIMEOUT_GRACE_S (default 15) — grace period between SIGTERM and SIGKILL on sandbox timeout.

elisam0 added 3 commits July 9, 2026 16:05
Signed-off-by: Elisa Martinez Abad <[email protected]>
Signed-off-by: Elisa Martinez Abad <[email protected]>
Signed-off-by: Elisa Martinez Abad <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Jul 9, 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.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Jul 9, 2026
@elisam0
elisam0 marked this pull request as ready for review July 9, 2026 14:24
@cwing-nvidia
cwing-nvidia requested a review from a team July 9, 2026 16:46
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Jul 11, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Jul 17, 2026
@sephmard sephmard moved this from Label Sync to Dev Todo in NeMo Gym 0.5.0 - Aug 5 Jul 27, 2026
@sephmard sephmard moved this from Dev Todo to At Risk in NeMo Gym 0.5.0 - Aug 5 Jul 29, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

SHIP WITH CARE — two independent, additive reliability changes. No verifier/scorer/reward-aggregation logic touched; no async-HTTP or ray.get() violations; imports resolve.

apptainer/provider.py — graceful timeout (SIGTERM → grace → SIGKILL)
Logic is correct: proc.returncode is None correctly gates the hard kill only when the process survived the grace period, and the trailing await proc.wait() after an uncatchable SIGKILL cannot hang. os/signal/contextlib all imported. One operability NOTE inline: the grace-period env-var is parsed with bare float() inside the timeout handler, so a non-numeric operator value raises ValueError that replaces the TimeoutError and skips the SIGKILL — parse it once at module scope.

hermes_agent/app.py — reasoning items + status/error/metadata

  • Correctness-positive: status="completed" if agent_completed else "incomplete" with agent_completed = result.get("completed", True). Default True is the safe choice — a harness that omits the key won't be spuriously marked incomplete. This lets a downstream consumer (anyswe) mask an out-of-turns accidental pass instead of scoring it 1.0. Good.
  • NeMoGymResponseReasoningItem is a valid member of the NeMoGymResponseOutputItem union and maps to ...ReasoningItemForTraining, so the added reasoning items round-trip through the training/responses converters. Note these reasoning items carry no generation_token_ids; if the training path expects token IDs on reasoning items you'll want a follow-up, but as authored they're valid output items.
  • metadata values truncated to 2000 chars: fine locally — OpenAI's Metadata is a plain Dict[str,str] alias with no client-side length check; the 512-char limit is server-side only and this response is Gym-internal.
  • interrupted via id(agent) in self.interrupted_agents: id() reuse after GC is theoretically possible, but this only ever flips a diagnostic metadata["interrupted"] flag — it does not feed scoring — and the entry is discard-ed immediately after read. Not a correctness risk.

RISK to flag for the author's decision: no test covers the new reasoning-item branch in _trajectory_to_output_items or the status/error/metadata population in responses(). Existing test_app.py exercises the old paths only. Given CLAUDE.md's coverage bar and that these fields feed eval-report diagnosability, add a case asserting an assistant message with reasoning yields a leading NeMoGymResponseReasoningItem, and one asserting status=='incomplete' when result['completed'] is False.

Nothing here silently corrupts scores or hangs a run. Merge after deciding on the env-var parse and the missing tests.

@NVIDIA-NeMo NVIDIA-NeMo deleted a comment from claude Bot Aug 17, 2026
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Aug 17, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Aug 17, 2026
@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Aug 18, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Aug 29, 2026
model=model_name,
object="response",
output=output_items,
status="completed" if agent_completed else "incomplete",

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.

Harness/API failures have completed=False, so this labels them incomplete even when error is populated and metadata.failed=true. Should this return failed when harness_error or result["failed"] is set?

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.

Changed the logic to achieve this.

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Sep 3, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Sep 3, 2026
Previously only agent_completed drove status, so a harness_error or
result["failed"] with completed=False still reported status="incomplete",
indistinguishable from the model running out of turns.

Signed-off-by: Riccardo Roveri <[email protected]>
@cmunley1
cmunley1 requested a review from hemildesai September 4, 2026 17:56
@cmunley1

cmunley1 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

/ok to test 3a4948f

@cmunley1

cmunley1 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

/ok to test 5b5240e

@cmunley1
cmunley1 merged commit d23a85a into NVIDIA-NeMo:main Sep 4, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from At Risk to Done in NeMo Gym 0.5.0 - Aug 5 Sep 4, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Sep 4, 2026
jkyi-nvidia pushed a commit that referenced this pull request Sep 11, 2026
# Fix Hermes agent traces and sandbox timeout handling

## Summary

Ensures Hermes agent trajectories are captured and surfaced even when a
run times out or fails, and makes the Apptainer sandbox timeout
terminate processes gracefully so in-container agents can flush partial
traces before being killed.

## Changes

### `nemo_gym/sandbox/providers/apptainer/provider.py`
- On timeout, send `SIGTERM` to the process group first and wait a short
grace period (default 15s, configurable via
`NEMO_GYM_SANDBOX_TIMEOUT_GRACE_S`), then `SIGKILL` only if the process
is still alive. This gives an in-container agent's SIGTERM handler a
chance to flush a partial trace before it's hard-killed. Applied to both
timeout paths.

### `responses_api_agents/hermes_agent/app.py`
- **Reasoning in traces:** emit assistant `reasoning` text as a
`NeMoGymResponseReasoningItem` in the output items.
- **Incomplete detection:** mark the response `status="incomplete"` when
`run_conversation` reports it didn't complete (ran out of turns / blew
the context window).
- **Interruption tracking:** track interrupted agents
(`interrupted_agents` set) via the SIGTERM dispatcher so timeouts are
reflected in the response.
- **Diagnosability metadata:** populate response `metadata` with
`interrupted`, `failed`, `partial`, `turns`, and `hermes_error`, and set
the structured `error` field (`code="server_error"`, message from the
harness error) when the run fails.

## Motivation

Timeouts and failures previously produced empty or misleading traces (a
hard kill left no trace; incomplete runs could score as passes). These
changes preserve partial trajectories and expose run outcome, making
failed and timed-out rollouts diagnosable.

## Env vars

- `NEMO_GYM_SANDBOX_TIMEOUT_GRACE_S` (default `15`) — grace period
between SIGTERM and SIGKILL on sandbox timeout.

---------

Signed-off-by: Elisa Martinez Abad <[email protected]>
Signed-off-by: Riccardo Roveri <[email protected]>
Co-authored-by: Christian Munley <[email protected]>
Co-authored-by: Riccardo Roveri <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 5b5240ee Deployed Sep 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #2580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants