Skip to navigation

nemo_gym.models.token_capture.staging.rebuild

View as MarkdownOpen in Claude

Verify a rollout receipt and rebuild its selected token sequence.

The verifier reads token columns from StagedCallBaseSnapshot. It does not fetch or decode optional extras. For each selected call, it returns an ExtrasCommitment. Consumers fetch the extras and compare their digest before use.

Module Contents

Classes

NameDescription
ExtrasCommitmentThe receipt-bound extras digest for one selected call.
LinearizedRowOne verified terminal chain ready for framework publication.
RebuildErrorA verified manifest cannot form the declared terminal ancestry.
ReceiptVerificationErrorA receipt or staged snapshot failed a custody invariant.
WeightVersionSpanPolicy version covering one call’s newly contributed token span.

Functions

NameDescription
_attribution_reasonsReturn the reason tokens of the receipt’s attribution trail.
_carry_boundary-
_compare_manifest_fields-
_fail-
_recompute_integrity-
_staging_ownerReturn the capture key record was staged under.
_terminal_chain-
_validate_manifest_graph-
_verify_versions-
linearizeCompatibility wrapper that still executes the production verifier.
verify_and_linearizeVerify an untrusted staged base set and linearize the declared terminal chain.

API

class nemo_gym.models.token_capture.staging.rebuild.ExtrasCommitment(
model_call_id: str,
extras_digest_version: int,
extras_digest: str
)
Dataclass

The receipt-bound extras digest for one selected call.

A commitment proves what the extras payload must hash to — not that the payload was fetched or valid. Consumers verify deferred extras bytes against it with compute_extras_digest at their own point of use.

extras_digest
str
extras_digest_version
int
model_call_id
str
class nemo_gym.models.token_capture.staging.rebuild.LinearizedRow(
rollout_id: str,
token_ids: list[int],
token_mask: list[float],
logprobs: list[float],
model_call_ids: list[str],
prompt_len: int,
weight_versions: list[int],
link_spans: list[tuple[str, int, int]] = list(),
terminal_finish_reason: str | None = None,
finish_reason_resolved: bool = True
)
Dataclass

One verified terminal chain ready for framework publication.

This is a proof that the base training row was verified. It carries no extras payloads; extras_commitments lists the selected calls’ receipt-bound digests root-to-terminal for point-of-use verification.

call_ids
list[str]

Compatibility spelling for existing framework consumers.

extras_commitments
list[ExtrasCommitment] = field(default_factory=list)
finish_reason_resolved
bool = True
incomplete_reason
str | None

The incomplete_details.reason the rebuilt response reports, or None for a complete ending.

Only the terminal call decides: an earlier length stop did not end the chain, because a later call extended it. The mapping is the one the local capture path applies, and so is the abstention: an unresolved finish reason (finish_reason_resolved is False) gives no verdict rather than one that follows the call-id order of identical retries.

A framework consumer puts this verdict on the harness response with nemo_gym.models.token_capture.apply_capture_incomplete_verdict, the precedence rule the local delivery applies as well: a harness that reported incomplete or failed itself keeps its own verdict, and only a response that reported completed or no status takes this one.

link_spans
list[tuple[str, int, int]] = field(default_factory=list)
logprobs
list[float]
model_call_ids
list[str]
prompt_len
int
rollout_id
str
terminal_finish_reason
str | None = None
token_ids
list[int]
token_mask
list[float]
weight_version_spans
list[WeightVersionSpan]
weight_versions
list[int]
class nemo_gym.models.token_capture.staging.rebuild.RebuildError()

Bases: ReceiptVerificationError

A verified manifest cannot form the declared terminal ancestry.

class nemo_gym.models.token_capture.staging.rebuild.ReceiptVerificationError(
code: str,
detail: str
)

Bases: ValueError

A receipt or staged snapshot failed a custody invariant.

class nemo_gym.models.token_capture.staging.rebuild.WeightVersionSpan(
model_call_id: str,
start: int,
end: int,
weight_version: int
)
Dataclass

Policy version covering one call’s newly contributed token span.

end
int
model_call_id
str
start
int
weight_version
int
nemo_gym.models.token_capture.staging.rebuild._attribution_reasons(
) -> set[str]

Return the reason tokens of the receipt’s attribution trail.

resolve_terminal joins its abstention, corroboration, and disagreement tokens with commas, and the framework copies the string onto terminal_attribution_reason; a receipt from a framework that records no trail has none.

nemo_gym.models.token_capture.staging.rebuild._carry_boundary(
) -> int
nemo_gym.models.token_capture.staging.rebuild._fail(
code: str,
detail: str
nemo_gym.models.token_capture.staging.rebuild._recompute_integrity(
) -> None
nemo_gym.models.token_capture.staging.rebuild._staging_owner(
) -> str

Return the capture key record was staged under.

A restored episode keeps the calls made before its checkpoint, staged under an earlier attempt of the same rollout. Any other owner would splice a foreign rollout’s tokens into this receipt.

nemo_gym.models.token_capture.staging.rebuild._validate_manifest_graph(
) -> None
nemo_gym.models.token_capture.staging.rebuild._verify_versions(
) -> None
nemo_gym.models.token_capture.staging.rebuild.linearize(
rollout_id: str,
terminal_hint: str | None = None

Compatibility wrapper that still executes the production verifier.

Verify an untrusted staged base set and linearize the declared terminal chain.

Metadata-only: extras payloads are never read. The returned row’s extras_commitments carry the selected calls’ receipt-bound digests for consumers to verify fetched extras against at their own point of use.