-
Notifications
You must be signed in to change notification settings - Fork 0
feat: bind promotion runners to risk provenance #294
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,14 @@ | |
| _REGIME_RISK_ORDER = (REGIME_NORMAL, REGIME_ELEVATED, REGIME_STRESS) | ||
|
|
||
|
|
||
| def _is_lower_hex(value: object, length: int) -> bool: | ||
| return ( | ||
| isinstance(value, str) | ||
| and len(value) == length | ||
| and all(character in "0123456789abcdef" for character in value) | ||
| ) | ||
|
|
||
|
|
||
| def normalise_regime(raw: str | None) -> str: | ||
| """Normalise a free-form regime string to one of the canonical constants.""" | ||
| value = str(raw or "").strip().lower() | ||
|
|
@@ -145,6 +153,52 @@ class RiskAction: | |
| notify: bool = True | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class CandidateRiskIdentity: | ||
| """Immutable identity of one mandate-bound promotion candidate.""" | ||
|
|
||
| strategy_profile: str | ||
| account_mode: str | ||
| strategy_revision: str | ||
| runner_revision: str | ||
| config_sha256: str | ||
| input_manifest_sha256: str | ||
| authority_receipt_sha256: str | ||
| candidate_sha256: str = field(init=False) | ||
|
|
||
| def __post_init__(self) -> None: | ||
| for name in ("strategy_profile", "account_mode"): | ||
| value = getattr(self, name) | ||
| if not isinstance(value, str) or not value or value != value.strip(): | ||
| raise ValueError(f"{name} must be a non-empty canonical string") | ||
| for name in ("strategy_revision", "runner_revision"): | ||
| if not _is_lower_hex(getattr(self, name), 40): | ||
| raise ValueError(f"{name} must be a lowercase 40-character Git revision") | ||
| for name in ( | ||
| "config_sha256", | ||
| "input_manifest_sha256", | ||
| "authority_receipt_sha256", | ||
| ): | ||
| if not _is_lower_hex(getattr(self, name), 64): | ||
| raise ValueError(f"{name} must be a lowercase SHA-256 digest") | ||
| payload = { | ||
| "strategy_profile": self.strategy_profile, | ||
| "account_mode": self.account_mode, | ||
| "strategy_revision": self.strategy_revision, | ||
| "runner_revision": self.runner_revision, | ||
| "config_sha256": self.config_sha256, | ||
| "input_manifest_sha256": self.input_manifest_sha256, | ||
| "authority_receipt_sha256": self.authority_receipt_sha256, | ||
| } | ||
| encoded = json.dumps( | ||
| payload, | ||
| sort_keys=True, | ||
| separators=(",", ":"), | ||
| allow_nan=False, | ||
| ).encode("utf-8") | ||
| object.__setattr__(self, "candidate_sha256", hashlib.sha256(encoded).hexdigest()) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RiskGateAssessment: | ||
| """Immutable redacted evidence from a scoped risk-gate evaluation.""" | ||
|
|
@@ -159,8 +213,10 @@ class RiskGateAssessment: | |
| mandate_version: str | None | ||
| mandate_authority_receipt_sha256: str | None | ||
| mandate_scope: str | None | ||
| candidate_identity_sha256: str | None | ||
| decision_digest_sha256: str | ||
| portfolio_snapshot_digest_sha256: str | ||
| normalization_origin_digest_sha256: str | None | ||
| effective_exposure_cap: float | None | ||
| observed_effective_exposure: float | None | ||
| proposed_effective_exposure: float | None | ||
|
|
@@ -180,8 +236,10 @@ def __post_init__(self) -> None: | |
| "mandate_version": self.mandate_version, | ||
| "mandate_authority_receipt_sha256": self.mandate_authority_receipt_sha256, | ||
| "mandate_scope": self.mandate_scope, | ||
| "candidate_identity_sha256": self.candidate_identity_sha256, | ||
| "decision_digest_sha256": self.decision_digest_sha256, | ||
| "portfolio_snapshot_digest_sha256": self.portfolio_snapshot_digest_sha256, | ||
| "normalization_origin_digest_sha256": self.normalization_origin_digest_sha256, | ||
|
Comment on lines
+239
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adding Useful? React with 👍 / 👎. |
||
| "effective_exposure_cap": self.effective_exposure_cap, | ||
| "observed_effective_exposure": self.observed_effective_exposure, | ||
| "proposed_effective_exposure": self.proposed_effective_exposure, | ||
|
|
||
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.
The risk gate passes the mandate's
effective_exposure_capinto this helper, and_mandate_fieldsaccepts mandate caps up to 1.0. With this hard 0.50 bootstrap ceiling, a valid mandate such as cap=0.75 reducing an observed 1.0 exposure to a target 0.75 is markedinvalid_reduce_only_normalization, soassess_with_evidencefalls back tomax(observed, target)and rejects with exposure errors instead of allowing the reduce-only transition. Use the mandate cap directly rather than the bootstrap constant here.Useful? React with 👍 / 👎.