Repository navigation
feat(token-id-capture): attribute terminal model calls - #2676
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. |
f028522 to
3494141
Compare
3494141 to
aa17a2a
Compare
aa17a2a to
ebd2a71
Compare
ebd2a71 to
3e114f8
Compare
|
/claude review |
|
SHIP — no reliability concerns found. This is a careful, fail-closed change to a training-signal-critical path; I reviewed it for the one thing that matters here: can it deliver wrong tokens to a trainer? It cannot. What I verified
NOTE (not blocking). The reader-side lineage fields — Per the repo's own bar ("run real rollouts… green unit tests alone are not enough"): the unit coverage is strong, but since this newly unmasks multi-root rollouts that were previously dropped, validate the attribution join against a real multi-agent / retry-heavy rollout before relying on the reclaimed samples. |
## What does this PR do?
This PR records the response envelope ID on each captured model call.
The ID is a lightweight receipt that an agent can retain while token IDs
and log probabilities remain in the configured token sink.
- Adds the optional `TokenEntry.response_id` field to the existing
version 1 record schema.
- Records the top-level ID returned by the Responses, Chat Completions,
or Messages endpoint.
- Reuses the underlying Responses ID in the Anthropic conversion so the
client-visible ID matches the captured ID.
## Response ID flow
```mermaid
sequenceDiagram
participant Agent as Agent harness
participant Capture as Capture middleware
participant Route as Model API route
participant Model as Model server
participant Sink as Token sink
Agent->>Capture: Request /ng-rollout/{rollout_id}/training-token-capture/v1/{dialect}
Capture->>Capture: Strip prefix and set rollout_id + model_call_id
Capture->>Route: Forward dialect request with capture context
Route->>Model: Generate response
Model-->>Route: NeMoGymResponse(id, output, token metadata)
Route->>Sink: TokenEntry(model_call_id, response_id=id, token arrays, output items)
alt Responses or Chat Completions
Route-->>Agent: Client response carries the recorded id
else Anthropic Messages
Route->>Route: Convert response and preserve response.id as message.id
Route-->>Agent: Message response carries the recorded id
end
```
The response ID and token arrays are written to the same `TokenEntry`.
The agent only needs to retain the response ID; later code can use it to
locate the corresponding captured model call.
This is the first PR in the terminal-attribution stack. #2676 uses the
recorded ID as one witness when resolving the model call that produced
the verified response.
## 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: Ananth Subramaniam <[email protected]>
…2810) ## Why `container_build`, `gpu_e2e_tests`, `provider_e2e_tests`, and the full test suite were queuing indefinitely on every PR push against the shared `nemo-ci-aws-gpu-x2` runner pool (follow-up to #2801). ## Before → After | | Before | After | |---|---|---| | Heavy CI trigger | Every PR push + every merge to `main` | Every 4 hours (`0 */4 * * *`) or manual `workflow_dispatch` | | `Nemo_CICD_Test` gate | Docs-only shortcut could bypass checking the heavy jobs entirely | Single gate, branches on `event_name`, always checks the right jobs with proper `needs.*.result` gating | | Slack alerts | None for these jobs | Fire on failure, but only for `main`/release-branch runs; show all upstream results, not just the 3 nightly ones | | Alert gating | N/A | Keyed directly on `event_name` — can't silently disappear if an earlier job in the chain gets skipped | | Ref-check / notify logic | N/A | Deduped into a shared `.github/actions/is-main-or-release-ref` action; job renamed `notify-failure` to match `full-test-suite.yml`'s convention | | Test coverage | N/A | `tests/unit_tests/test_ci_environment.py` extended to cover the new gating/alerting behavior (67 passing) | Split out: the "commits since last run" alert feature is a separate stacked PR, #2812. ## Test plan - [ ] PR pushes skip `container_build`/`gpu_e2e_tests`/`provider_e2e_tests`; `Nemo_CICD_Test` still passes - [ ] Scheduled run triggers all nightly jobs + `full-test-suite.yml` on `main`, gated correctly - [ ] A nightly `unit_tests` or `pre-flight` failure still sends a Slack alert with the real cause - [ ] Merging to `main` no longer triggers `full-test-suite.yml` directly - [ ] `workflow_dispatch` runs on demand; alert suppressed on non-main/non-release refs - [ ] `pytest tests/unit_tests/test_ci_environment.py -q` passes --------- Signed-off-by: Kajal Jain <[email protected]>
Stateless fingerprint functions over message lists, byte-compatible with the lineage stack's hashing (same domains, tags, canonicalization). Any server may import them; lineage state stays confined to the capture locus. The tests pin the dialect-blind property: the same content in Chat, Responses, or Anthropic shape hashes identically. Signed-off-by: ananthsub <[email protected]>
…borating witnesses The /run result's response is the object the verifier scored. resolve_terminal joins it to exactly one captured call via independent witnesses: an explicit declared id, the served response_id, and the content fingerprint (final-turn, trailing-block, and cumulative readings pooled). Witnesses corroborate, never outrank; disagreement attributes nothing and persists the trail. Signed-off-by: ananthsub <[email protected]>
…inal With an attributed terminal the builder delivers the root-to-terminal chain: auxiliary calls and sub-agent forks are excluded instead of masking, calls served after the kept response truncate away, and final-retry groups resolve by the terminal path. Unattributed rollouts keep the strict single-chain policy bit-for-bit. The attribution verdict survives failed builds in metrics. Signed-off-by: ananthsub <[email protected]>
3e114f8 to
4f25ada
Compare
|
/ok to test 4f25ada |
What does this PR do?
This PR identifies the captured model call that produced the response scored by the verifier, then anchors trajectory selection to that call. It depends on #2675.
Terminal attribution flow
flowchart TD Result["Completed /run result<br/>response scored by verifier"] --> Finalize["finalize_rollout_token_capture"] Store["Frozen TokenEntry snapshot<br/>one entry per captured model call"] --> Finalize Finalize --> Resolve["resolve_terminal"] Explicit["Explicit terminal model_call_id<br/>when supplied"] --> Agreement ResponseId["Response ID witness<br/>result.response.id = TokenEntry.response_id"] --> Agreement Content["Content witness<br/>cross-dialect fingerprint match"] --> Agreement Resolve --> Explicit Resolve --> ResponseId Resolve --> Content Agreement{"Do all available witnesses<br/>identify the same token sequence?"} Agreement -- Yes --> Terminal["Resolved terminal model_call_id"] Agreement -- No witnesses or disagreement --> Abstain["No attribution"] Terminal --> Builder["Build token-prefix forest<br/>and select root-to-terminal chain"] Builder --> Intact{"Is the terminal chain intact?"} Intact -- Yes --> Deliver["Deliver verified chain unmasked<br/>exclude auxiliary calls and sibling branches"] Intact -- No --> Mask["Mask rollout<br/>known terminal is not safely deliverable"] Abstain --> Strict["Use existing strict single-chain policy"] Strict --> Unique{"Exactly one unambiguous chain?"} Unique -- Yes --> Deliver Unique -- No --> MaskThe response ID does not directly determine a trajectory. It identifies a captured
TokenEntry, whosemodel_call_idanchors selection in the token-prefix forest. Content and explicit-ID witnesses independently check that join. A disagreement fails closed instead of allowing one witness to override another.Known limitations
Checklist
pre-commit run --all-files) (so CI lint/format/copyright pass).git commit -s) (so the DCO check passes).