-
Notifications
You must be signed in to change notification settings - Fork 0
feat(estimator): refuse a checkpoint as the CPU f64 estimator #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
88704a5
feat(relation): refuse support edges as state transitions
seonghobae 5b8bd7d
feat(estimator): refuse a checkpoint as the CPU f64 estimator
seonghobae af0417c
Merge remote-tracking branch 'origin/main' into review/pr140-current
seonghobae e61e331
Merge remote-tracking branch 'origin/main' into review/pr130-current
seonghobae ce1879f
test: derive crate contract from workspace manifest
seonghobae ed83e7e
docs: synchronize workspace crate count
seonghobae 72a4c43
Merge remote-tracking branch 'origin/agent/checkpoint-estimator-autho…
seonghobae ec27241
fix: remove orphan support edge after crate replacement
seonghobae b321a31
docs(checkpoint): remove stale support edge references
seonghobae 4feb427
Merge current main into checkpoint authority gate
seonghobae 1c7cfcb
Merge remote-tracking branch 'origin/main' into agent/checkpoint-esti…
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # CodeGraph data files — local to each machine, not for committing. | ||
| # Ignore everything in .codegraph/ except this file itself, so transient | ||
| # files (the database, daemon.pid, sockets, logs) never show up in git. | ||
| * | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "checkpoint_authority" | ||
| description = "A model checkpoint is not the CPU f64 estimator." | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| authors.workspace = true | ||
| repository.workspace = true | ||
| homepage.workspace = true | ||
| readme.workspace = true | ||
| keywords.workspace = true | ||
| categories.workspace = true | ||
| publish = false | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| //! Checkpoint artifacts versus the CPU `f64` estimator. | ||
|
|
||
| use crate::CheckpointAuthorityError; | ||
|
|
||
| /// Closed vocabulary of scientific-authority roles for a run artifact. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum ArtifactRole { | ||
| /// The production CPU `f64` reference estimator. | ||
| CpuF64Estimator, | ||
| /// A serialized model checkpoint produced by a run. | ||
| ModelCheckpoint, | ||
| } | ||
|
|
||
| impl ArtifactRole { | ||
| /// Return the stable wire role name. | ||
| #[must_use] | ||
| pub const fn wire_name(self) -> &'static str { | ||
| match self { | ||
| Self::CpuF64Estimator => "cpu_f64_estimator", | ||
| Self::ModelCheckpoint => "model_checkpoint", | ||
| } | ||
| } | ||
|
|
||
| /// Parse a stable wire role name. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`CheckpointAuthorityError::InvalidAuthorityPayload`] for | ||
| /// unrecognized names. | ||
| pub fn from_wire_name(name: &str) -> Result<Self, CheckpointAuthorityError> { | ||
| match name { | ||
| "cpu_f64_estimator" => Ok(Self::CpuF64Estimator), | ||
| "model_checkpoint" => Ok(Self::ModelCheckpoint), | ||
| _ => Err(CheckpointAuthorityError::InvalidAuthorityPayload), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Identity, digest, and run provenance required to accept a checkpoint | ||
| /// as an artifact (never as the estimator). | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub struct CheckpointOffer<'a> { | ||
| /// Opaque artifact identity assigned by the owning boundary. | ||
| pub artifact_identity: &'a str, | ||
| /// Canonical lowercase hex `SHA-256` of the checkpoint bytes. | ||
| pub content_digest: &'a str, | ||
| /// Model-run identity that produced the checkpoint. | ||
| pub model_run_identity: &'a str, | ||
| } | ||
|
|
||
| /// Refuse to treat a checkpoint as the CPU `f64` estimator. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`CheckpointAuthorityError::CheckpointIsNotEstimator`] when | ||
| /// `role` is [`ArtifactRole::ModelCheckpoint`]. | ||
| pub fn refuse_checkpoint_as_estimator(role: ArtifactRole) -> Result<(), CheckpointAuthorityError> { | ||
| match role { | ||
| ArtifactRole::ModelCheckpoint => Err(CheckpointAuthorityError::CheckpointIsNotEstimator), | ||
| ArtifactRole::CpuF64Estimator => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Accept a checkpoint only as a validated run artifact. | ||
| /// | ||
| /// Identity, model-run provenance, and a canonical digest are required. | ||
| /// Success does not grant estimator authority. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns a missing-field or digest error when the offer is untrusted. | ||
| pub fn accept_checkpoint_artifact( | ||
| offer: &CheckpointOffer<'_>, | ||
| ) -> Result<(), CheckpointAuthorityError> { | ||
| if offer.artifact_identity.is_empty() { | ||
| return Err(CheckpointAuthorityError::MissingIdentity); | ||
| } | ||
| if offer.model_run_identity.is_empty() { | ||
| return Err(CheckpointAuthorityError::MissingProvenance); | ||
| } | ||
| validate_sha256_hex(offer.content_digest) | ||
| } | ||
|
|
||
| /// Fraction of recovered artifact roles that match known truth. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`CheckpointAuthorityError::InvalidAuthorityPayload`] when either | ||
| /// slice is empty or the lengths differ. | ||
| pub fn authority_recovery_rate( | ||
| truth: &[ArtifactRole], | ||
| decided: &[ArtifactRole], | ||
| ) -> Result<f64, CheckpointAuthorityError> { | ||
| if truth.is_empty() || truth.len() != decided.len() { | ||
| return Err(CheckpointAuthorityError::InvalidAuthorityPayload); | ||
| } | ||
| let mut matches = 0_u32; | ||
| for (truth_role, decided_role) in truth.iter().zip(decided) { | ||
| if truth_role == decided_role { | ||
| matches += 1; | ||
| } | ||
| } | ||
| Ok(f64::from(matches) / truth.len() as f64) | ||
| } | ||
|
|
||
| fn validate_sha256_hex(digest: &str) -> Result<(), CheckpointAuthorityError> { | ||
| if digest.is_empty() { | ||
| return Err(CheckpointAuthorityError::MissingDigest); | ||
| } | ||
| if digest.len() != 64 | ||
| || !digest | ||
| .bytes() | ||
| .all(|byte| byte.is_ascii_hexdigit() && !byte.is_ascii_uppercase()) | ||
| { | ||
| return Err(CheckpointAuthorityError::InvalidDigest); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::{ | ||
| ArtifactRole, CheckpointOffer, accept_checkpoint_artifact, authority_recovery_rate, | ||
| refuse_checkpoint_as_estimator, | ||
| }; | ||
| use crate::CheckpointAuthorityError; | ||
|
|
||
| #[test] | ||
| fn local_branches_cover_roles_payloads_and_wire_names() { | ||
| assert_eq!( | ||
| refuse_checkpoint_as_estimator(ArtifactRole::ModelCheckpoint), | ||
| Err(CheckpointAuthorityError::CheckpointIsNotEstimator) | ||
| ); | ||
| refuse_checkpoint_as_estimator(ArtifactRole::CpuF64Estimator).expect("estimator"); | ||
| for role in [ArtifactRole::CpuF64Estimator, ArtifactRole::ModelCheckpoint] { | ||
| assert_eq!( | ||
| ArtifactRole::from_wire_name(role.wire_name()).expect("round-trip"), | ||
| role | ||
| ); | ||
| } | ||
| assert_eq!( | ||
| ArtifactRole::from_wire_name("posterior_summary"), | ||
| Err(CheckpointAuthorityError::InvalidAuthorityPayload) | ||
| ); | ||
| let offer = CheckpointOffer { | ||
| artifact_identity: "artifact-01", | ||
| content_digest: &"cd".repeat(32), | ||
| model_run_identity: "run-01", | ||
| }; | ||
| accept_checkpoint_artifact(&offer).expect("artifact"); | ||
| assert_eq!( | ||
| accept_checkpoint_artifact(&CheckpointOffer { | ||
| artifact_identity: "", | ||
| ..offer | ||
| }), | ||
| Err(CheckpointAuthorityError::MissingIdentity) | ||
| ); | ||
| assert_eq!( | ||
| accept_checkpoint_artifact(&CheckpointOffer { | ||
| model_run_identity: "", | ||
| ..offer | ||
| }), | ||
| Err(CheckpointAuthorityError::MissingProvenance) | ||
| ); | ||
| assert_eq!( | ||
| accept_checkpoint_artifact(&CheckpointOffer { | ||
| content_digest: "", | ||
| ..offer | ||
| }), | ||
| Err(CheckpointAuthorityError::MissingDigest) | ||
| ); | ||
| assert_eq!( | ||
| accept_checkpoint_artifact(&CheckpointOffer { | ||
| content_digest: "ab", | ||
| ..offer | ||
| }), | ||
| Err(CheckpointAuthorityError::InvalidDigest) | ||
| ); | ||
| assert_eq!( | ||
| accept_checkpoint_artifact(&CheckpointOffer { | ||
| content_digest: &"gh".repeat(32), | ||
| ..offer | ||
| }), | ||
| Err(CheckpointAuthorityError::InvalidDigest) | ||
| ); | ||
| let matched = authority_recovery_rate( | ||
| &[ArtifactRole::ModelCheckpoint], | ||
| &[ArtifactRole::ModelCheckpoint], | ||
| ) | ||
| .expect("rate"); | ||
| assert!((matched - 1.0).abs() < f64::EPSILON); | ||
| assert_eq!( | ||
| authority_recovery_rate(&[], &[]), | ||
| Err(CheckpointAuthorityError::InvalidAuthorityPayload) | ||
| ); | ||
| assert_eq!( | ||
| authority_recovery_rate(&[ArtifactRole::ModelCheckpoint], &[]), | ||
| Err(CheckpointAuthorityError::InvalidAuthorityPayload) | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| //! Fail-closed checkpoint-authority errors. | ||
|
|
||
| use std::fmt; | ||
|
|
||
| /// A fail-closed checkpoint-authority error. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| #[non_exhaustive] | ||
| pub enum CheckpointAuthorityError { | ||
| /// A checkpoint was treated as the CPU `f64` estimator. | ||
| CheckpointIsNotEstimator, | ||
| /// Artifact identity was missing or empty. | ||
| MissingIdentity, | ||
| /// Model-run provenance was missing or empty. | ||
| MissingProvenance, | ||
| /// Content digest was missing or empty. | ||
| MissingDigest, | ||
| /// Content digest was not canonical lowercase hex `SHA-256`. | ||
| InvalidDigest, | ||
| /// A recovery slice was empty or length-mismatched. | ||
| InvalidAuthorityPayload, | ||
| } | ||
|
|
||
| impl fmt::Display for CheckpointAuthorityError { | ||
| fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| let message = match self { | ||
| Self::CheckpointIsNotEstimator => "a model checkpoint is not the cpu f64 estimator", | ||
| Self::MissingIdentity => "checkpoint artifact is missing identity", | ||
| Self::MissingProvenance => "checkpoint artifact is missing model-run provenance", | ||
| Self::MissingDigest => "checkpoint artifact is missing content digest", | ||
| Self::InvalidDigest => "checkpoint artifact digest is not canonical sha-256", | ||
| Self::InvalidAuthorityPayload => "invalid checkpoint-authority payload", | ||
| }; | ||
| formatter.write_str(message) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for CheckpointAuthorityError {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::CheckpointAuthorityError; | ||
|
|
||
| #[test] | ||
| fn error_messages_are_stable() { | ||
| for (error, message) in [ | ||
| ( | ||
| CheckpointAuthorityError::CheckpointIsNotEstimator, | ||
| "a model checkpoint is not the cpu f64 estimator", | ||
| ), | ||
| ( | ||
| CheckpointAuthorityError::MissingIdentity, | ||
| "checkpoint artifact is missing identity", | ||
| ), | ||
| ( | ||
| CheckpointAuthorityError::MissingProvenance, | ||
| "checkpoint artifact is missing model-run provenance", | ||
| ), | ||
| ( | ||
| CheckpointAuthorityError::MissingDigest, | ||
| "checkpoint artifact is missing content digest", | ||
| ), | ||
| ( | ||
| CheckpointAuthorityError::InvalidDigest, | ||
| "checkpoint artifact digest is not canonical sha-256", | ||
| ), | ||
| ( | ||
| CheckpointAuthorityError::InvalidAuthorityPayload, | ||
| "invalid checkpoint-authority payload", | ||
| ), | ||
| ] { | ||
| assert_eq!(error.to_string(), message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #![forbid(unsafe_code)] | ||
| #![deny(missing_docs)] | ||
| #![allow(clippy::cast_precision_loss)] | ||
| //! A model checkpoint is not the CPU `f64` estimator. | ||
| //! | ||
| //! Checkpoints stay untrusted run artifacts until identity, digest, and | ||
| //! model-run provenance validate. They cannot replace the reference | ||
| //! estimator or promote a scientific claim (ADR 0001/0014). | ||
|
|
||
| mod authority; | ||
| mod error; | ||
|
|
||
| /// Closed vocabulary of scientific-authority roles for a run artifact. | ||
| pub use authority::ArtifactRole; | ||
| /// Identity, digest, and run provenance for one checkpoint offer. | ||
| pub use authority::CheckpointOffer; | ||
| /// Accept a checkpoint only as a validated run artifact. | ||
| pub use authority::accept_checkpoint_artifact; | ||
| /// Fraction of recovered artifact roles that match known truth. | ||
| pub use authority::authority_recovery_rate; | ||
| /// Refuse to treat a checkpoint as the CPU `f64` estimator. | ||
| pub use authority::refuse_checkpoint_as_estimator; | ||
| /// Fail-closed checkpoint-authority errors. | ||
| pub use error::CheckpointAuthorityError; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: checkpoint_authority estimator/recovery logic reviewed as correct
Reviewed authority.rs:
refuse_checkpoint_as_estimator,accept_checkpoint_artifact,validate_sha256_hex(correctly rejects non-64-length, non-hex, and uppercase hex digests), andauthority_recovery_rate(fails closed on empty/length-mismatch, computes matches/len). No logic errors found. The new crate satisfies the workspace contract checks in check_workspace_contract.py (name, publish=false, workspace lints, inherited fields, lib.rs docs/forbid/deny, crate_contract.rs test present).Was this helpful? React with 👍 or 👎 to provide feedback.