Skip to content

feat(health): evaluate invocation-owned model calls - #2885

Merged
giuliolovisotto merged 8 commits into
mainfrom
glovisotto/health-invocation-calls
Sep 10, 2026
Merged

giuliolovisotto merged 8 commits into
mainfrom
glovisotto/health-invocation-calls

Conversation

@giuliolovisotto

@giuliolovisotto giuliolovisotto commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Extends five rollout-level checks to consume exact model-call references owned by either TrajectoryTurn or AgentInvocation:

  • model_call_failed
  • model_call_missing_token_counts
  • model_call_runaway_generation
  • model_call_zero_completion_tokens
  • trajectory_capture_mismatch

The runner resolves exact references before deduplicating captured calls. Equivalent turn and invocation references therefore evaluate a call once, while an unbindable turn reference remains a correspondence finding without hiding a valid invocation reference. It never infers ownership from list position, timestamps, model names, or payload similarity. Repeated contradictory references for one call identity produce one mismatch finding without making the binding complete.

Failed-call terminality follows the saved captured-call order. A length-limited call whose response payload was not retained makes model_call_runaway_generation unobserved instead of being treated as an empty response.

Structural checks remain TrajectoryTurn-only. rollout_token_count_mismatch and task_no_successful_model_calls retain their existing turn-bound aggregate accounting. The rollout-health documentation states these evidence boundaries explicitly.

This PR is stacked on and depends on #2884, which produces exact OpenCode AgentInvocation.model_calls ownership.

Validation

  • pytest tests/unit_tests/test_rollout_health.py -q (64 passed)
  • Health and runner coverage: 98% (required: 96%)
  • Combined stack suite: 425 passed, 13 subtests passed
  • pre-commit run --all-files
  • cd fern && npm run check (0 errors)

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 31, 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

@giuliolovisotto giuliolovisotto changed the title Evaluate invocation-owned model calls in rollout health feat(health): evaluate invocation-owned model calls Sep 1, 2026
@giuliolovisotto
giuliolovisotto force-pushed the glovisotto/health-invocation-calls branch from d858c49 to 9a974a9 Compare September 1, 2026 13:10
@giuliolovisotto giuliolovisotto changed the title feat(health): evaluate invocation-owned model calls [2/3] feat(health): evaluate invocation-owned model calls Sep 2, 2026
@giuliolovisotto
giuliolovisotto force-pushed the glovisotto/health-invocation-calls branch from ad41700 to ab7bde3 Compare September 3, 2026 08:44
@giuliolovisotto
giuliolovisotto force-pushed the glovisotto/opencode-call-ownership branch from a636c29 to 382aad9 Compare September 3, 2026 08:44
@giuliolovisotto
giuliolovisotto marked this pull request as ready for review September 3, 2026 09:53
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Sep 4, 2026
@Glorf

Glorf commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

SHIP — LGTM, no reliability concerns.

Reviewed the model-call binding refactor that splits the per-call OWNED_MODEL_CALLS view (turn OR invocation ownership) from the turn-only BOUND_CALLS view used by the aggregate checks. Traced the correctness-critical paths:

  • No KeyError in build_bindings: resolved is built from owned_reference_items (deduped turn∪invocation); turn signatures are a subset, so every resolved[signature] lookup resolves for both views.
  • Same call referenced by turn + invocation is evaluated once — matched_positions dedupes by call position (test_turn_and_invocation_reference_evaluate_one_call).
  • Aggregates stay turn-bound: rollout_token_count_mismatch, successful_model_calls, and policy_calls_observed all use turn_bindings, so invocation-only support calls can't satisfy a trajectory token total or successful-call claim (test_task_no_successful_model_calls_remains_turn_bound).
  • model_call_failed.terminal now keyed on max call_index; equivalent to the old last-position logic since call_index == enumerate position, but more robust.
  • Runaway guard marks the check unobserved only when a matched length-limited call has response is None — the conservative, false-positive-avoiding direction, and response={} still fires.
  • CheckSpec validator rejects declaring both binding views — good invariant, tested.

Tests assert real behavior; docs updated consistently. No async/public-API/dependency surface touched.

@Glorf

Glorf commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

is owned_model_calls interesting/enough evidence for us? I thought we seek full evidence only...
Also I'm not sure why we allow this kind of hack - is opencode somehow completely obscure and we're unable to gather turn-correlation information literally in any way?

@giuliolovisotto
giuliolovisotto force-pushed the glovisotto/opencode-call-ownership branch from 382aad9 to 7ed32bb Compare September 7, 2026 18:04
Glorf
Glorf previously approved these changes Sep 10, 2026
Keep session association producer-owned and non-mutating. Index exact references so long rollouts remain linear, while missing or failed client correlation stays explicitly unowned.

Signed-off-by: Giulio Lovisotto <[email protected]>
Pass an explicit title so OpenCode does not issue an auxiliary title-model request under the policy session. Clarify that ng_perf sums every invocation-owned call, including compaction when listed there.

Signed-off-by: Giulio Lovisotto <[email protected]>
Signed-off-by: Giulio Lovisotto <[email protected]>
@giuliolovisotto
giuliolovisotto force-pushed the glovisotto/opencode-call-ownership branch from 8799ef2 to 64f3136 Compare September 10, 2026 14:17
Deduplicate after exact binding so equivalent references cannot double-count and stale turn references cannot hide invocation evidence. Preserve turn-bound aggregate semantics.

Signed-off-by: Giulio Lovisotto <[email protected]>
Treat a missing saved response as unobserved when evaluating a length-limited call. Collapse indistinguishable reference mismatches without treating contradictory bindings as complete.

Signed-off-by: Giulio Lovisotto <[email protected]>
@giuliolovisotto
giuliolovisotto force-pushed the glovisotto/health-invocation-calls branch from ab7bde3 to 4917c1a Compare September 10, 2026 14:18
@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Sep 10, 2026
giuliolovisotto added a commit that referenced this pull request Sep 10, 2026
…2884)

## What does this PR do?

Correlates OpenCode model requests with their exact `AgentInvocation` by
retaining OpenCode's `X-Session-Id` request header as a single
allowlisted capture field. During rollout finalization, calls whose
client session matches an observed OpenCode invocation are projected as
canonical `AgentInvocation.model_calls` references.

This avoids timestamp, ordering, payload, and model-name inference.
Calls with absent, conflicting, or unknown session ownership retain the
existing `model_call_ownership_unavailable` gap. The session header is
client-declared correlation evidence, not an authentication boundary.

The standalone OpenCode harness supplies an explicit title so OpenCode
does not make an auxiliary title-model request under the same session
identity. Invocation-owned performance totals include every call listed
by the harness, including compaction calls when they are also listed on
the invocation.

This PR is the producer half of a stack. Stacked draft #2885 lets
call-level rollout-health checks consume exact invocation-owned calls
when `TrajectoryTurn` placement is unavailable.

### Validation

- `pytest tests/unit_tests/test_rollout_observability.py
tests/unit_tests/test_base_responses_api_model.py
tests/unit_tests/test_rollout_collection.py
responses_api_agents/opencode_agent/tests/test_app.py -q` (336 passed)
- OpenCode 1.17.11 local binary smoke against a localhost
OpenAI-compatible endpoint: one `/v1/chat/completions` request; its
`X-Session-Id` exactly matched the session persisted in OpenCode's
SQLite database; no auxiliary title request
- Producer association helper coverage: 100% (required: 96%)
- `pre-commit run --all-files`

## Checklist

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

---------

Signed-off-by: Giulio Lovisotto <[email protected]>
Base automatically changed from glovisotto/opencode-call-ownership to main September 10, 2026 14:31
@giuliolovisotto
giuliolovisotto dismissed Glorf’s stale review September 10, 2026 14:31

The base branch was changed.

@giuliolovisotto
giuliolovisotto enabled auto-merge (squash) September 10, 2026 14:58
@giuliolovisotto giuliolovisotto changed the title [2/3] feat(health): evaluate invocation-owned model calls feat(health): evaluate invocation-owned model calls Sep 10, 2026
@giuliolovisotto
giuliolovisotto merged commit 5be3614 into main Sep 10, 2026
39 checks passed
@giuliolovisotto
giuliolovisotto deleted the glovisotto/health-invocation-calls branch September 10, 2026 15:12
jkyi-nvidia pushed a commit that referenced this pull request Sep 11, 2026
…2884)

## What does this PR do?

Correlates OpenCode model requests with their exact `AgentInvocation` by
retaining OpenCode's `X-Session-Id` request header as a single
allowlisted capture field. During rollout finalization, calls whose
client session matches an observed OpenCode invocation are projected as
canonical `AgentInvocation.model_calls` references.

This avoids timestamp, ordering, payload, and model-name inference.
Calls with absent, conflicting, or unknown session ownership retain the
existing `model_call_ownership_unavailable` gap. The session header is
client-declared correlation evidence, not an authentication boundary.

The standalone OpenCode harness supplies an explicit title so OpenCode
does not make an auxiliary title-model request under the same session
identity. Invocation-owned performance totals include every call listed
by the harness, including compaction calls when they are also listed on
the invocation.

This PR is the producer half of a stack. Stacked draft #2885 lets
call-level rollout-health checks consume exact invocation-owned calls
when `TrajectoryTurn` placement is unavailable.

### Validation

- `pytest tests/unit_tests/test_rollout_observability.py
tests/unit_tests/test_base_responses_api_model.py
tests/unit_tests/test_rollout_collection.py
responses_api_agents/opencode_agent/tests/test_app.py -q` (336 passed)
- OpenCode 1.17.11 local binary smoke against a localhost
OpenAI-compatible endpoint: one `/v1/chat/completions` request; its
`X-Session-Id` exactly matched the session persisted in OpenCode's
SQLite database; no auxiliary title request
- Producer association helper coverage: 100% (required: 96%)
- `pre-commit run --all-files`

## Checklist

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

---------

Signed-off-by: Giulio Lovisotto <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>
jkyi-nvidia pushed a commit that referenced this pull request Sep 11, 2026
## What does this PR do?

Extends five rollout-level checks to consume exact model-call references
owned by either `TrajectoryTurn` or `AgentInvocation`:

- `model_call_failed`
- `model_call_missing_token_counts`
- `model_call_runaway_generation`
- `model_call_zero_completion_tokens`
- `trajectory_capture_mismatch`

The runner resolves exact references before deduplicating captured
calls. Equivalent turn and invocation references therefore evaluate a
call once, while an unbindable turn reference remains a correspondence
finding without hiding a valid invocation reference. It never infers
ownership from list position, timestamps, model names, or payload
similarity. Repeated contradictory references for one call identity
produce one mismatch finding without making the binding complete.

Failed-call terminality follows the saved captured-call order. A
length-limited call whose response payload was not retained makes
`model_call_runaway_generation` unobserved instead of being treated as
an empty response.

Structural checks remain `TrajectoryTurn`-only.
`rollout_token_count_mismatch` and `task_no_successful_model_calls`
retain their existing turn-bound aggregate accounting. The
rollout-health documentation states these evidence boundaries
explicitly.

This PR is stacked on and depends on #2884, which produces exact
OpenCode `AgentInvocation.model_calls` ownership.

### Validation

- `pytest tests/unit_tests/test_rollout_health.py -q` (64 passed)
- Health and runner coverage: 98% (required: 96%)
- Combined stack suite: 425 passed, 13 subtests passed
- `pre-commit run --all-files`
- `cd fern && npm run check` (0 errors)

## Checklist

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

---------

Signed-off-by: Giulio Lovisotto <[email protected]>
Co-authored-by: ritaneves <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>
pull Bot pushed a commit to Stars1233/Gym that referenced this pull request Sep 18, 2026
## What does this PR do?

Adds canonical `TrajectoryTurn` records to `opencode_agent` and
`opencode_sandboxed_agent` when observability is enabled. This makes
their persisted assistant content usable by
`rollout_missing_agent_turns` and `agent_turn_hollow` health checks,
while preserving the invocation-owned model calls introduced by NVIDIA-NeMo#2884
and consumed by NVIDIA-NeMo#2885.

### Evidence contract

- A turn is one persisted OpenCode assistant message with provider-step
evidence (`step-start` or `step-finish`). Its native message/part IDs
establish membership; ordering only numbers turns within a session.
- Answer text, reasoning, and tool calls come from that message's parts.
Compaction summaries and explicitly synthetic shell/subtask bookkeeping
do not become policy turns.
- `question` stays unset: the persisted user message is not proof of the
complete provider request. `step_count` counts completed provider steps
cumulatively within each session.
- `TrajectoryTurn.model_calls` stays empty. Existing exact
`AgentInvocation.model_calls` ownership is preserved; this PR does not
infer turn-to-call links from order, timing, or content similarity.
- Interrupted, malformed, or incomplete evidence retains known content
and records `turns_unavailable`, preventing content checks from
declaring a partially observed trajectory healthy or hollow.

There are no changes to health-check semantics, model servers, OpenCode
itself, or existing configs. Call-level checks continue to consume
invocation ownership; token-total reconciliation and the task-level
successful-call check still require complete turn bindings.

### Validation

- 184 agent, rollout-health, and observability regression tests passed;
190 rollout-collection tests passed.
- New shared parser: 100% statement coverage. Existing
application-module coverage is 93.07% (local) / 83.30% (sandboxed); this
is not a claim of 100% coverage for those modules.
- `pre-commit run --all-files` passed.
- Real local OpenCode 1.17.11 run through Gym's model proxy: executed a
Python calculation, wrote and verified `391`, produced three canonical
turns and four invocation-owned captured calls. Content and owned-call
checks evaluated with zero findings; overall verdict remained
`unobserved` because token reconciliation lacks per-turn call
references.
- Both SQLite parsers produced identical canonical turns from the local
live database.
- Real Docker-backed OpenCode 1.17.11 smoke on ARM64: the sandboxed
agent's `run()` path executed a Python calculation, wrote and
independently verified `391`, exported its native SQLite evidence, and
finalized with `opencode_finished=true`. It produced three canonical
turns and three exactly invocation-owned captured calls. Independent
checks confirmed native message/part membership and capture/session
ownership. Health reports contained zero findings; content and
owned-call checks evaluated, while overall verdict remained `unobserved`
because token reconciliation lacks per-turn call references.
- Docker smoke scope: a temporary driver supplied an already-created
Docker sandbox because this branch's Docker provider lacks
`serialize()/connect()` support. Sandbox reconnection was not exercised;
agent execution, export, observation parsing, verification, and
finalization used the real implementation. The small verifier checked
the generated file, not a SWE-bench task. Existing sandbox-lifecycle
timing and verifier-observation gaps remained. No repository files were
changed for this smoke.

The live run used a supported explicit OpenCode provider config. The
automatic provider config reproduced an existing incompatibility:
assistant tool-call history containing `reasoning: ""` is rejected by
Gym's chat schema (HTTP 422). That separate issue is unchanged by this
PR.

## Checklist

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

---------

Signed-off-by: Giulio Lovisotto <[email protected]>
giuliolovisotto added a commit that referenced this pull request Oct 6, 2026
Compaction summaries can contribute to response usage without becoming
policy turns. The rollout token-total check previously summed only
turn-bound calls and incorrectly reported those summaries as
discrepancies. Compare response totals against the existing deduplicated
invocation-or-turn-owned call view, which includes exactly owned
compaction calls and still excludes unowned auxiliary calls.

This intentionally advances only token-total accounting beyond the
turn-only boundary retained in #2885. Successful-task-call checks and
structural turn checks keep their existing scope. Missing or ambiguous
references, missing token counts, and the existing incomplete-scope gap
remain conservative; real total mismatches still produce findings. The
documentation describes the revised contract. The change affects health
accounting, not generated answers or benchmark rewards.

Stacked on #3871, above #3856 / #3764 / #3711. This focused follow-up
does not need a separate issue.

Validation:
- 96 focused tests pass: 71 health tests and 25 sandbox-agent tests.
- New regressions cover invocation-only compaction accounting, duplicate
references, unowned-call exclusion, missing captures and genuinely
incorrect totals. The compaction regression fails against the parent
implementation.
- `pre-commit run --all-files` passes; Fern validation reports zero
errors (authenticated redirect validation was skipped).
- Ran the actual Gym health-check CLI at the prior tip
`bbe2d7eb8d3d9bd702ae5f1416b1c6f335b9f550` over 2,193 retained records,
saving new reports. On untouched records, all three compaction warnings
clear. The broader ownership view also exposes 16 pre-existing
unfinished-call usage discrepancies that turn-only accounting could not
see.
- A separately saved producer-usage replay for parent #3871 clears all
140 child-session mismatches. Final combined result: 2,175 healthy, 17
unhealthy, 1 unobserved; zero trajectory/capture mismatch findings and
zero check execution errors. Remaining findings are the 16 unfinished
native/captured-usage discrepancies and one recovered server-error
incident; one sandbox failure lacks canonical evidence.
- The child replay used retained native root exports plus
capture-derived child token metadata passed through the production
reader/converter: original child SQLite snapshots were unavailable.
Original records/reports remain intact, no checks are ignored, and the
parent PR separately has a live parent/child model smoke. This is not a
new benchmark rollout or a score-parity claim.
- Enabled GitHub checks pass at this head. Draft-gated automated
review/integration checks were skipped; no unresolved review threads
were present when checked.

## Parent header-property update

Restacked on #3711, which now obtains the optional capture header from a
harness-owned property. The previous run-level header option is removed.
OpenCode declares its existing binary header in its own package; no
binary rebuild or selection change is required. The focused
property/startup/correlation suite passes 397 tests and all-files
pre-commit passes. A fresh live attempt retained IDs but failed in the
upstream proxy, so successful new deployment validation is not claimed.
Historical deployment/replay results above remain tied to their original
commits.

The restacked accounting tip `a94028067d4861a14ccceb135e72fda0d554addd`
passes **730 selected tests**, including both adapters, collection,
shared correlation and health. No saved-run health replay was repeated
for this wiring-only change.

## Rebase validation (2026-10-02)

Rebased the five-PR stack onto `main` at
`4f95540cc61c2ad783312d0cdb48d8a7c95c30e4`, preserving the new capture
execution metadata and failed-call health checks. Each PR targets its
immediate parent.

At the final tip `00f19f01a18097cdbe7504de691090505effcbd9`: **918
selected tests pass**, all-files pre-commit passes, and Fern validation
reports zero errors and one warning. Range-diff confirms only
conflict-context adaptations; all nine commits retain DCO sign-off and
SSH signatures. Historical deployment and saved-run replay results above
remain tied to their original commits; no new model run or full
saved-run health replay was performed for this rebase.

Stack: main → #3711 → #3764 → #3856 → #3871 → #3872

---------

Signed-off-by: Giulio Lovisotto <[email protected]>

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants