Skip to content

fix(hermes): observe limit summaries and invocation stops - #4040

Merged
giuliolovisotto merged 4 commits into
mainfrom
codex/hermes-summary-fix
Oct 12, 2026
Merged

giuliolovisotto merged 4 commits into
mainfrom
codex/hermes-summary-fix

Conversation

@giuliolovisotto

@giuliolovisotto giuliolovisotto commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Pinned Hermes replays internal tool-call fields when it asks for a summary at the iteration limit. Gym rejects that request with HTTP 422, and the summary call bypasses Gym's observed model-call path. Delegated delegate_task children construct fresh Hermes agents, so they need the same adapter; otherwise their limit summaries fail and lack child invocation ownership.

Keep the existing cmunley1/hermes-agent@26bb847a pin. Gym now installs its summary adapter before root and delegated child agents run, sanitizes only the outgoing summary history, and routes summaries and retries through the observed model-call method. The original trajectory stays intact and no turns are added. A documented on_iteration_limit_reached(*, invocation_id: str) -> None observer hook records stop_reason=max_iterations and incomplete once on the affected invocation before summary dispatch. A child's limit does not mark or terminate its parent. The sandbox observation bridge preserves this invocation-scoped outcome. No hook registry, budget change, or dependency repin is introduced.

This addresses the follow-up to #3554 and is tracked by FEA-399. Native usage accounting is supplied by #4139 on main. The adapter uses private methods of this pinned Hermes version, so a future dependency update must recheck these hooks. No configuration migration is needed. A valid terminal summary may change the final trajectory and benchmark result.

Validation after rebasing onto main 4a9236e48c82f0dc23365a4c0088b1e54d00d3a8 (head eb435d5da130538e2d87cd9ca0c384444aba9c54):

  • Hermes component suite plus shared observability tests: 293 passed, 6 skipped. The delegated-child regression uses Hermes's pinned child constructor in both host and sandbox observer paths and both installation orders. It verifies strict Gym schema acceptance, child-owned summary response IDs and limit outcome, and unchanged parent state. Other tests cover summary-error independence, one notification per limit, and sandbox observation import.
  • pre-commit run --all-files and git diff --check passed. All commits have DCO sign-off. Rebase compatibility changes are limited to the supervisor import and the sandbox observation test’s required runtime_info argument.
  • Fresh controlled conformance suite: python scripts/run_harness_conformance.py --harness hermes --output <new-directory> passed 7/7 scenarios on the rebased head, including retry, omitted usage, terminal model error, and verifier failure scenarios.
  • Earlier controlled HTTP check: pinned Hermes → live Gym Model Server → scripted upstream returned HTTP 200 for a forced root summary, with an owned response ID and captured call. Outgoing tool calls had no internal fields. Script: /tmp/hermes-summary-http-smoke-gym.py.
  • Real-model root-summary smoke: HSG job 7676935 completed against earlier Gym commit 030307b48d4267a58b5c952cde1f0dd758b56a3c on Super 3.5 direct P/D serving with max_turns=1, observability and model-call capture. Initial and limit-summary calls returned HTTP 200 and belong to the root invocation, with no trajectory gaps. The response is incomplete with stop_reason=max_iterations and no error. The verifier applied a patch and graded it unresolved; cleanup job 7676936 found zero sandboxes. Its summary response was reasoning-only, so Hermes appended no substantive assistant summary. Evidence: /lustre/fsw/portfolios/nemotron/users/glovisotto/nemo-evaluator-rundirs/super-3dot5-pd/swe-bench-pro-hermes-summary-smoke/20261005_102034-a219dd2ebd76f36d/results on HSG. This predates the child and invocation-hook changes, so it validates only the root summary path.
  • Real-model delegated-child smoke before this rebase: HSG job 7755765 completed against 5a6784a69c7cb8e13ee7643db14469cfddd87b1f on Super 3.5 direct P/D serving with explicit delegation tools, parent cap 3, child cap 1, observability, and model-call capture. The model created root.child-1 through delegate_task; all six calls returned HTTP 200, with two response IDs owned by the child and four by the root. The child is incomplete with stop_reason=max_iterations; the parent made two more model calls after the child returned, then independently reached its own limit and has the same stop reason. The rollout has no failure row or observation/trajectory gaps. The verifier applied a patch and graded it unresolved; cleanup job 7755766 found zero remaining sandboxes. Capture request bodies contain no internal call_id/response_item_id fields. Evidence: /lustre/fsw/portfolios/nemotron/users/glovisotto/nemo-evaluator-rundirs/super-3dot5-pd/swe-bench-pro-hermes-child-summary-smoke/20261006_193101-3549a070ecb3cafb/results on HSG. Health flags only the separate zero-aggregate-usage mismatch tracked by fix(agent): reconcile harness-reported and captured token usage #3981 / FEA-397.

The rebased CI run records validation of the current head. The live-model smokes above are historical, with their source commits stated explicitly; this rebase changes no intended runtime behavior.

CI: core coverage, all eight server-suite shards, Nemo_CICD_Test, lint, and DCO passed on the rebased head.

CI conformance: Hermes passes 7/7 on this head. The overall P0 check remains red for OpenCode (2 failed scenarios), Pi (1), and Codex (7), matching the current-main baseline exactly. Those failures are outside this Hermes summary fix.

@copy-pr-bot

copy-pr-bot Bot commented Oct 5, 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.

@giuliolovisotto giuliolovisotto added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working labels Oct 5, 2026
@giuliolovisotto
giuliolovisotto force-pushed the codex/hermes-summary-fix branch from 149d852 to 030307b Compare October 5, 2026 08:18
@giuliolovisotto giuliolovisotto changed the title fix(hermes): preserve valid observable budget summaries fix(hermes): adapt limit summaries for Gym Oct 5, 2026
@giuliolovisotto
giuliolovisotto marked this pull request as ready for review October 5, 2026 08:41
@giuliolovisotto giuliolovisotto added the needs-review PR is ready for code review and waiting on a reviewer label Oct 5, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 5, 2026 08:42
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

@giuliolovisotto

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

SHIP — LGTM, no reliability concerns.

Reviewed the full diff against the pinned-Hermes integration. The change correctly routes Hermes's iteration-limit summary through Gym's observed model path, and I verified the three things that could have broken:

  • Observability attribution: create_summary resolves agent._interruptible_api_call dynamically at call time, so the summary request is captured by the observer wrapper in both the host path (install → instrument) and the sandbox path (instrument → install). The new tests assert the summary response_id appears in model_calls/model_response_ids.
  • Result classification: _gym_iteration_limit_reached + setdefault("stop_reason", "max_iterations") yields status=incomplete, error=None, and metadata[stop_reason]=max_iterations — the summary is gradable rather than lost/mis-graded. No collision with the sandbox interrupt path, which raises and takes the progress() branch where a more-specific cancelled/wall_time reason wins.
  • Strict-API schema: the summary request is copied and stripped (codex_reasoning_items/reasoning/finish_reason) + sanitized before _model_api_kwargs, without mutating the original trajectory; the integration test validates the second model-server request against NeMoGymChatCompletionCreateParamsNonStreaming.

install_summary_compat degrades gracefully (no-op) if the pinned Hermes lacks the hooked methods. Tests assert real behavior across host/sandbox × retry. Nothing to block on.

@yaoyu-33 yaoyu-33 added the complexity:low Localized change in one scope with a small, straightforward review surface label Oct 5, 2026
)

agent._build_api_kwargs = _patched_build_api_kwargs
install_summary_compat(agent, preserve_reasoning_history=self.config.chat_template_kwargs_enabled)

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.

Could we also install this on delegate_task children, in both host and sandbox paths? They create fresh AIAgent instances, so this root-only patch is not inherited. When a child reaches its iteration limit, its summary still sends internal tool-call fields and gets a Gym 422; summary ownership is also missing. Reproduced with the pinned child constructor. Please apply the hook at child creation and add a regression test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@yaoyu-33

yaoyu-33 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Could we define a small, documented Gym-adapter hook contract, e.g. on_iteration_limit_reached(*, invocation_id: str) -> None, for other harnesses to follow? It should record stop_reason=max_iterations once for the affected invocation, without changing budgets, generating a summary, or terminating the parent when only a child hits the limit. Harnesses with native stop events can map directly to this contract; Hermes can call it from the compatibility shim for now. Please keep summary request sanitation/dispatch separate. A documented convention is enough; no hook registry or new framework needed.

@giuliolovisotto giuliolovisotto changed the title fix(hermes): adapt limit summaries for Gym fix(hermes): observe limit summaries and invocation stops Oct 6, 2026
@giuliolovisotto

Copy link
Copy Markdown
Contributor Author

/claude review

@giuliolovisotto

Copy link
Copy Markdown
Contributor Author

Could we define a small, documented Gym-adapter hook contract, e.g. on_iteration_limit_reached(*, invocation_id: str) -> None, for other harnesses to follow? It should record stop_reason=max_iterations once for the affected invocation, without changing budgets, generating a summary, or terminating the parent when only a child hits the limit. Harnesses with native stop events can map directly to this contract; Hermes can call it from the compatibility shim for now. Please keep summary request sanitation/dispatch separate. A documented convention is enough; no hook registry or new framework needed.

Done.

@claude

claude Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

SHIP — LGTM, no reliability concerns.

Reviewed the max_iterations observability change end-to-end (host app.py, sandbox_runner.py, both observers, model_kwargs.install_summary_compat).

What I verified:

  • Invocation scoping is correct. Root result only gets stop_reason=max_iterations when the root agent tripped the limit; a delegated child that hits its own limit records on the child invocation and leaves the parent untouched (test_delegated_child_limit_summary_uses_gym_and_belongs_to_child).
  • Callback fires once, before the summary, and survives summary failure (test_iteration_limit_hook_fires_once_before_summary_even_when_summary_fails).
  • Children-list wrapping composes in both install orders via _gym_child_hook_supported/_gym_prepare_child (parametrized install_before_observer).
  • Status override respects stop_reason — _record_conversation in both observers keeps incomplete when stop_reason == max_iterations, so a later conversation record can't overwrite it.
  • Graceful degradation + idempotence — install_summary_compat no-ops on an incompatible Hermes and guards re-install.
  • API compat — new AgentInvocation.stop_reason is Optional[str] defaulting to None (additive).

The summary call is now routed through _interruptible_api_call so it reaches the Model Server and its response ID is captured in model_calls/model_response_ids, matching the test assertions. No verifier/scoring, async-HTTP, or public-API concerns.

Keep the existing Hermes dependency pin while making iteration-limit summaries valid and observable at the Gym integration boundary. Record the budget stop explicitly without changing the turn limit.

Signed-off-by: Giulio Lovisotto <[email protected]>
@giuliolovisotto
giuliolovisotto 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/38200849608

Merged via the queue into main with commit 2d6170d Oct 12, 2026
49 of 51 checks passed
@giuliolovisotto
giuliolovisotto deleted the codex/hermes-summary-fix branch October 12, 2026 03:58

This branch was previously deployed

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

Labels

area:agent Agent harnesses and Responses API agent behavior 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.

2 participants