Repository navigation
feat(observability): correlate OpenCode calls with invocations - #2884
Conversation
|
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. |
a636c29 to
382aad9
Compare
|
/claude review |
|
SHIP — no reliability concerns. Reviewed the OpenCode model-call ownership change end to end. Correctness holds:
Test coverage is thorough (long-rollout scaling, phantom-call retention, other-producer passthrough, dedup, failure-path gaps). Non-blocking NOTE: the updated |
|
@giuliolovisotto added 3 comments, please review what is feasible/applicable in this PR context |
382aad9 to
7ed32bb
Compare
Signed-off-by: Giulio Lovisotto <[email protected]>
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]>
8799ef2 to
64f3136
Compare
## 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]>
…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]>
## 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]>
## 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]>
POR Test Summary — OpenCode Model-Call Ownership (#2961)Verdict: PASS — 3/3 named cases Added end-to-end ownership coverage and ran it on a clean Gym checkout at d6d7685.
Each assertion joins three independent evidence surfaces: the durable capture record's client session, OpenCode session-derived agent observations, and the canonical ng_trajectory/ng_perf projection. The cases also verify that invocation token totals count owned calls only and that unreadable/fallback session artifacts do not silently substitute rollout-level ownership.
This is post-merge POR coverage of the correlation contract introduced by #2884. |
What does this PR do?
Correlates OpenCode model requests with their exact
AgentInvocationby retaining OpenCode'sX-Session-Idrequest header as a single allowlisted capture field. During rollout finalization, calls whose client session matches an observed OpenCode invocation are projected as canonicalAgentInvocation.model_callsreferences.This avoids timestamp, ordering, payload, and model-name inference. Calls with absent, conflicting, or unknown session ownership retain the existing
model_call_ownership_unavailablegap. 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
TrajectoryTurnplacement 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)/v1/chat/completionsrequest; itsX-Session-Idexactly matched the session persisted in OpenCode's SQLite database; no auxiliary title requestpre-commit run --all-filesChecklist
pre-commit run --all-files) (so CI lint/format/copyright pass).git commit -s) (so the DCO check passes).