Spaces:
Building
Building
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): Dockerfile, a11oy_model_intel.py, model_release/frontier-qualification/frontier_admission_guard.py
Deleted (gone from the repo + Dockerfile COPY set): (none)
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- Dockerfile +1 -0
- a11oy_model_intel.py +307 -4
- model_release/frontier-qualification/frontier_admission_guard.py +442 -0
Dockerfile
CHANGED
|
@@ -127,6 +127,7 @@ COPY ayllu/ ./ayllu/
|
|
| 127 |
# Canonical model-family/control-plane evidence ships with the runtime image so
|
| 128 |
# deployed status surfaces can be audited against the same release contracts.
|
| 129 |
COPY model_release/szl-forge-family.json model_release/szl-compute-plane.json model_release/szl-ayllu-binding.json model_release/szl-khipu-second-brain.json ./model_release/
|
|
|
|
| 130 |
COPY model_release/receipt-agent/ ./model_release/receipt-agent/
|
| 131 |
# Brain-derived rows remain quarantined until this deterministic, fail-closed
|
| 132 |
# admission engine validates immutable provenance, rights, contamination, and
|
|
|
|
| 127 |
# Canonical model-family/control-plane evidence ships with the runtime image so
|
| 128 |
# deployed status surfaces can be audited against the same release contracts.
|
| 129 |
COPY model_release/szl-forge-family.json model_release/szl-compute-plane.json model_release/szl-ayllu-binding.json model_release/szl-khipu-second-brain.json ./model_release/
|
| 130 |
+
COPY model_release/frontier-qualification/ ./model_release/frontier-qualification/
|
| 131 |
COPY model_release/receipt-agent/ ./model_release/receipt-agent/
|
| 132 |
# Brain-derived rows remain quarantined until this deterministic, fail-closed
|
| 133 |
# admission engine validates immutable provenance, rights, contamination, and
|
a11oy_model_intel.py
CHANGED
|
@@ -37,8 +37,11 @@ Artificial Analysis, OpenRouter. No data is fabricated.
|
|
| 37 |
Co-Authored-By: Perplexity Computer Agent <agent@perplexity.ai>
|
| 38 |
"""
|
| 39 |
|
|
|
|
|
|
|
| 40 |
import threading
|
| 41 |
import time
|
|
|
|
| 42 |
from typing import Any, Optional
|
| 43 |
|
| 44 |
import httpx
|
|
@@ -53,6 +56,15 @@ _DATASETS_ROWS = "https://datasets-server.huggingface.co/rows"
|
|
| 53 |
_DATASETS_SPLITS = "https://datasets-server.huggingface.co/splits"
|
| 54 |
_LMARENA_DS = "lmarena-ai/leaderboard-dataset"
|
| 55 |
_HF_MODELS = "https://huggingface.co/api/models"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# Prior-art citations surfaced to the operator (never claimed as ours).
|
| 58 |
CITED = {
|
|
@@ -226,6 +238,285 @@ def get_hub(limit: int = 40) -> dict[str, Any]:
|
|
| 226 |
"doctrine": DOCTRINE}
|
| 227 |
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
def get_pareto(limit: int = 40) -> dict[str, Any]:
|
| 230 |
"""Quality (LMArena Elo) × adoption (HF downloads) non-dominated frontier.
|
| 231 |
Both axes are REAL public signals. Price / tokens-per-sec are ROADMAP (no
|
|
@@ -283,24 +574,36 @@ def register(app: FastAPI, ns: str = "a11oy") -> dict[str, Any]:
|
|
| 283 |
|
| 284 |
@app.get(base + "/leaderboard", include_in_schema=False)
|
| 285 |
@app.get("/v1/models/leaderboard", include_in_schema=False)
|
| 286 |
-
|
| 287 |
return JSONResponse(get_leaderboard(limit))
|
| 288 |
|
| 289 |
@app.get(base + "/hub", include_in_schema=False)
|
| 290 |
@app.get("/v1/models/hub", include_in_schema=False)
|
| 291 |
-
|
| 292 |
return JSONResponse(get_hub(limit))
|
| 293 |
|
| 294 |
@app.get(base + "/pareto", include_in_schema=False)
|
| 295 |
@app.get("/v1/models/pareto", include_in_schema=False)
|
| 296 |
-
|
| 297 |
return JSONResponse(get_pareto(limit))
|
| 298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
@app.get(base + "/info", include_in_schema=False)
|
| 300 |
@app.get("/v1/models/info", include_in_schema=False)
|
| 301 |
async def _models_info():
|
| 302 |
return JSONResponse({"module": "a11oy_model_intel", "base": base,
|
| 303 |
-
"endpoints": ["/leaderboard", "/hub", "/pareto", "/info"],
|
| 304 |
"cited": CITED, "locked": LOCKED, "doctrine": DOCTRINE,
|
| 305 |
"honesty": "Live external model intel; advisory quality signal, "
|
| 306 |
"never a proof. SAMPLE/ROADMAP labelled where not live."})
|
|
|
|
| 37 |
Co-Authored-By: Perplexity Computer Agent <agent@perplexity.ai>
|
| 38 |
"""
|
| 39 |
|
| 40 |
+
import json
|
| 41 |
+
import re
|
| 42 |
import threading
|
| 43 |
import time
|
| 44 |
+
from pathlib import Path
|
| 45 |
from typing import Any, Optional
|
| 46 |
|
| 47 |
import httpx
|
|
|
|
| 56 |
_DATASETS_SPLITS = "https://datasets-server.huggingface.co/splits"
|
| 57 |
_LMARENA_DS = "lmarena-ai/leaderboard-dataset"
|
| 58 |
_HF_MODELS = "https://huggingface.co/api/models"
|
| 59 |
+
_HF_ORG = "SZLHOLDINGS"
|
| 60 |
+
_HF_ORG_REPOSITORY_RE = re.compile(r"^SZLHOLDINGS/[A-Za-z0-9._-]+$")
|
| 61 |
+
_HF_REVISION_RE = re.compile(r"^[0-9a-f]{40}$")
|
| 62 |
+
_FRONTIER_REGISTRY = (
|
| 63 |
+
Path(__file__).resolve().parent
|
| 64 |
+
/ "model_release"
|
| 65 |
+
/ "frontier-qualification"
|
| 66 |
+
/ "frontier-adoption.json"
|
| 67 |
+
)
|
| 68 |
|
| 69 |
# Prior-art citations surfaced to the operator (never claimed as ours).
|
| 70 |
CITED = {
|
|
|
|
| 238 |
"doctrine": DOCTRINE}
|
| 239 |
|
| 240 |
|
| 241 |
+
def _load_frontier_registry() -> dict[str, Any]:
|
| 242 |
+
value = json.loads(_FRONTIER_REGISTRY.read_text(encoding="utf-8"))
|
| 243 |
+
if not isinstance(value, dict):
|
| 244 |
+
raise ValueError("frontier adoption registry is not a JSON object")
|
| 245 |
+
if value.get("schema_version") != "szl.frontier-adoption.v1":
|
| 246 |
+
raise ValueError("frontier adoption registry schema is unsupported")
|
| 247 |
+
if value.get("status") != "GOVERNED_PLAN_NOT_LOCAL_QUALIFICATION":
|
| 248 |
+
raise ValueError("frontier adoption registry honesty state changed")
|
| 249 |
+
policy = value.get("evidence_policy", {})
|
| 250 |
+
expected_policy = {
|
| 251 |
+
"local_measurements_present": False,
|
| 252 |
+
"download_performed_by_this_contract": False,
|
| 253 |
+
"promotion_authority": False,
|
| 254 |
+
"unknown_repository_policy": "DENY",
|
| 255 |
+
"zero_download_policy": "ZERO_DOWNLOADS_ALONE_NEVER_AUTHORIZES_DELETE_OR_ARCHIVE",
|
| 256 |
+
}
|
| 257 |
+
if not isinstance(policy, dict):
|
| 258 |
+
raise ValueError("frontier adoption registry evidence policy is missing")
|
| 259 |
+
for field, expected in expected_policy.items():
|
| 260 |
+
if policy.get(field) != expected:
|
| 261 |
+
raise ValueError(f"frontier adoption registry policy mismatch: {field}")
|
| 262 |
+
mutations = value.get("external_mutations")
|
| 263 |
+
if not isinstance(mutations, dict) or not mutations:
|
| 264 |
+
raise ValueError("frontier adoption registry mutation ledger is missing")
|
| 265 |
+
if any(item is not False for item in mutations.values()):
|
| 266 |
+
raise ValueError("frontier adoption registry reports an external mutation")
|
| 267 |
+
brain = value.get("brain_model_truth")
|
| 268 |
+
if not isinstance(brain, dict):
|
| 269 |
+
raise ValueError("frontier adoption registry Brain truth is missing")
|
| 270 |
+
if brain.get("raw_nodes_observed") != 9464:
|
| 271 |
+
raise ValueError("frontier adoption registry Brain node count changed")
|
| 272 |
+
if brain.get("raw_nodes_admitted_to_gradients") != 0:
|
| 273 |
+
raise ValueError("frontier adoption registry reports unadmitted gradient rows")
|
| 274 |
+
github_estate = value.get("github_estate_strategy")
|
| 275 |
+
if not isinstance(github_estate, dict):
|
| 276 |
+
raise ValueError("frontier adoption registry GitHub estate strategy is missing")
|
| 277 |
+
if github_estate.get("source_reported_repository_count") != 54:
|
| 278 |
+
raise ValueError("frontier adoption registry GitHub source count changed")
|
| 279 |
+
if github_estate.get("inventory_complete") is not False:
|
| 280 |
+
raise ValueError("frontier adoption registry overclaims a complete GitHub inventory")
|
| 281 |
+
if github_estate.get("public_github_repositories_observed") != 50:
|
| 282 |
+
raise ValueError("frontier adoption registry public GitHub readback count changed")
|
| 283 |
+
if github_estate.get("public_archived_observed") != 9:
|
| 284 |
+
raise ValueError("frontier adoption registry public GitHub archive count changed")
|
| 285 |
+
if github_estate.get("reconciliation_state") != (
|
| 286 |
+
"SOURCE_REPORT_54_PUBLIC_READBACK_50_ATTACHMENT_TRUNCATED_REVIEW_REQUIRED"
|
| 287 |
+
):
|
| 288 |
+
raise ValueError("frontier adoption registry GitHub reconciliation state changed")
|
| 289 |
+
if github_estate.get("code_to_weight_policy") != (
|
| 290 |
+
"CODE_REPOSITORIES_ARE_SERVICES_LIBRARIES_OR_EVIDENCE_NOT_MODEL_WEIGHTS"
|
| 291 |
+
):
|
| 292 |
+
raise ValueError("frontier adoption registry code-to-weight boundary changed")
|
| 293 |
+
if github_estate.get("unclassified_repository_policy") != (
|
| 294 |
+
"DISCOVER_CLASSIFY_FAIL_CLOSED_NO_ARCHIVE"
|
| 295 |
+
):
|
| 296 |
+
raise ValueError("frontier adoption registry unclassified repository policy changed")
|
| 297 |
+
layers = github_estate.get("layers")
|
| 298 |
+
if not isinstance(layers, list) or len(layers) < 8:
|
| 299 |
+
raise ValueError("frontier adoption registry GitHub estate layer map is incomplete")
|
| 300 |
+
candidates = value.get("candidates")
|
| 301 |
+
if not isinstance(candidates, list) or len(candidates) < 9:
|
| 302 |
+
raise ValueError("frontier adoption registry candidate inventory is incomplete")
|
| 303 |
+
for candidate in candidates:
|
| 304 |
+
if not isinstance(candidate, dict):
|
| 305 |
+
raise ValueError("frontier adoption registry candidate record is malformed")
|
| 306 |
+
required_candidate = {
|
| 307 |
+
"id", "decision", "upstream", "runtime", "allowed_operations",
|
| 308 |
+
"prohibited_operations", "required_evidence_by_operation",
|
| 309 |
+
}
|
| 310 |
+
if not required_candidate.issubset(candidate):
|
| 311 |
+
raise ValueError("frontier adoption registry candidate record is incomplete")
|
| 312 |
+
upstream = candidate.get("upstream")
|
| 313 |
+
if not isinstance(upstream, dict) or not {
|
| 314 |
+
"repository_id", "revision", "artifact_inventory"
|
| 315 |
+
}.issubset(upstream):
|
| 316 |
+
raise ValueError("frontier adoption registry candidate upstream record is incomplete")
|
| 317 |
+
estate = value.get("hf_estate")
|
| 318 |
+
repositories = estate.get("repositories") if isinstance(estate, dict) else None
|
| 319 |
+
if not isinstance(repositories, list) or len(repositories) < 15:
|
| 320 |
+
raise ValueError("frontier adoption registry Hugging Face estate is incomplete")
|
| 321 |
+
repository_ids = []
|
| 322 |
+
for item in repositories:
|
| 323 |
+
if not isinstance(item, dict):
|
| 324 |
+
raise ValueError("frontier adoption registry estate record is malformed")
|
| 325 |
+
required = {
|
| 326 |
+
"repository_id", "observed_revision", "artifact_class", "weight_bearing",
|
| 327 |
+
"strategy", "canonical_family", "delete_authorized",
|
| 328 |
+
}
|
| 329 |
+
if not required.issubset(item):
|
| 330 |
+
raise ValueError("frontier adoption registry estate record is incomplete")
|
| 331 |
+
if item["delete_authorized"] is not False:
|
| 332 |
+
raise ValueError("frontier adoption registry estate record authorizes deletion")
|
| 333 |
+
repository_ids.append(item["repository_id"])
|
| 334 |
+
if len(repository_ids) != len(set(repository_ids)):
|
| 335 |
+
raise ValueError("frontier adoption registry estate contains duplicate repositories")
|
| 336 |
+
return value
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def get_frontier_adoption() -> dict[str, Any]:
|
| 340 |
+
"""Return the checked-in adoption contract without upgrading its honesty state."""
|
| 341 |
+
try:
|
| 342 |
+
registry = _load_frontier_registry()
|
| 343 |
+
except (OSError, ValueError, TypeError, KeyError, json.JSONDecodeError) as exc:
|
| 344 |
+
return {
|
| 345 |
+
"state": "UNAVAILABLE",
|
| 346 |
+
"reason": f"{type(exc).__name__}: {str(exc)[:180]}",
|
| 347 |
+
"qualificationAuthority": False,
|
| 348 |
+
"promotionAuthority": False,
|
| 349 |
+
"deleteAuthority": False,
|
| 350 |
+
"externalMutationPerformed": False,
|
| 351 |
+
"doctrine": DOCTRINE,
|
| 352 |
+
}
|
| 353 |
+
policy = registry["evidence_policy"]
|
| 354 |
+
mutations = registry["external_mutations"]
|
| 355 |
+
return {
|
| 356 |
+
"state": registry["status"],
|
| 357 |
+
"registry": registry,
|
| 358 |
+
"qualificationAuthority": bool(policy["local_measurements_present"]),
|
| 359 |
+
"promotionAuthority": bool(policy["promotion_authority"]),
|
| 360 |
+
"deleteAuthority": False,
|
| 361 |
+
"externalMutationPerformed": any(bool(value) for value in mutations.values()),
|
| 362 |
+
"doctrine": DOCTRINE,
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def _parse_hf_org_models(items: Any) -> list[dict[str, Any]]:
|
| 367 |
+
rows: list[dict[str, Any]] = []
|
| 368 |
+
for model in items if isinstance(items, list) else []:
|
| 369 |
+
if not isinstance(model, dict):
|
| 370 |
+
continue
|
| 371 |
+
repository_id = model.get("id")
|
| 372 |
+
if not isinstance(repository_id, str) or not _HF_ORG_REPOSITORY_RE.fullmatch(repository_id):
|
| 373 |
+
continue
|
| 374 |
+
revision = model.get("sha")
|
| 375 |
+
if not isinstance(revision, str) or not _HF_REVISION_RE.fullmatch(revision):
|
| 376 |
+
revision = None
|
| 377 |
+
siblings = model.get("siblings")
|
| 378 |
+
filenames = [
|
| 379 |
+
str(item.get("rfilename", ""))
|
| 380 |
+
for item in siblings or []
|
| 381 |
+
if isinstance(item, dict)
|
| 382 |
+
]
|
| 383 |
+
lowered_filenames = [name.lower() for name in filenames]
|
| 384 |
+
basenames = [name.rsplit("/", 1)[-1] for name in lowered_filenames]
|
| 385 |
+
weight_bearing = any(
|
| 386 |
+
name.endswith(".safetensors")
|
| 387 |
+
or name.endswith(".gguf")
|
| 388 |
+
or name.endswith(".onnx")
|
| 389 |
+
or name.endswith(".pt")
|
| 390 |
+
or name.endswith(".pth")
|
| 391 |
+
or name.endswith(".ckpt")
|
| 392 |
+
or name.endswith(".npz")
|
| 393 |
+
or name.endswith(".h5")
|
| 394 |
+
or name.endswith(".msgpack")
|
| 395 |
+
or name in {"pytorch_model.bin", "adapter_model.bin", "tf_model.h5", "flax_model.msgpack"}
|
| 396 |
+
or bool(re.fullmatch(r"pytorch_model-\d+-of-\d+\.bin", name))
|
| 397 |
+
for name in basenames
|
| 398 |
+
)
|
| 399 |
+
rows.append({
|
| 400 |
+
"repository_id": repository_id,
|
| 401 |
+
"revision": revision,
|
| 402 |
+
"downloads": model.get("downloads"),
|
| 403 |
+
"likes": model.get("likes"),
|
| 404 |
+
"last_modified": model.get("lastModified"),
|
| 405 |
+
"pipeline_tag": model.get("pipeline_tag"),
|
| 406 |
+
"library_name": model.get("library_name"),
|
| 407 |
+
"weight_bearing_from_filenames": weight_bearing,
|
| 408 |
+
"file_count": len(filenames),
|
| 409 |
+
})
|
| 410 |
+
return rows
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def _download_sort_value(value: Any) -> int:
|
| 414 |
+
try:
|
| 415 |
+
parsed = int(value)
|
| 416 |
+
except (TypeError, ValueError, OverflowError):
|
| 417 |
+
return 0
|
| 418 |
+
return max(parsed, 0)
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
def get_szl_estate() -> dict[str, Any]:
|
| 422 |
+
"""Merge live no-key Hub metadata with the pinned estate classification.
|
| 423 |
+
|
| 424 |
+
Live download counts are observations, never deletion or promotion authority.
|
| 425 |
+
Unknown or revision-drifted repositories remain visible and fail closed.
|
| 426 |
+
"""
|
| 427 |
+
try:
|
| 428 |
+
registry = _load_frontier_registry()
|
| 429 |
+
except (OSError, ValueError, TypeError, KeyError, json.JSONDecodeError) as exc:
|
| 430 |
+
return {
|
| 431 |
+
"state": "UNAVAILABLE",
|
| 432 |
+
"reason": f"{type(exc).__name__}: {str(exc)[:180]}",
|
| 433 |
+
"models": [],
|
| 434 |
+
"deleteAuthority": False,
|
| 435 |
+
"externalMutationPerformed": False,
|
| 436 |
+
"doctrine": DOCTRINE,
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
static_rows = registry["hf_estate"]["repositories"]
|
| 440 |
+
by_id = {item["repository_id"]: item for item in static_rows}
|
| 441 |
+
feed = _cached_fetch(
|
| 442 |
+
"hf_szlholdings_estate",
|
| 443 |
+
_HF_MODELS,
|
| 444 |
+
ttl=900,
|
| 445 |
+
parser=_parse_hf_org_models,
|
| 446 |
+
params={"author": _HF_ORG, "limit": 100, "full": "true"},
|
| 447 |
+
)
|
| 448 |
+
live_rows = feed.get("value") or []
|
| 449 |
+
live_by_id = {item["repository_id"]: item for item in live_rows if item.get("repository_id")}
|
| 450 |
+
merged: list[dict[str, Any]] = []
|
| 451 |
+
|
| 452 |
+
for repository_id in sorted(set(by_id) | set(live_by_id)):
|
| 453 |
+
classification = by_id.get(repository_id)
|
| 454 |
+
live = live_by_id.get(repository_id)
|
| 455 |
+
if classification is None:
|
| 456 |
+
merged.append({
|
| 457 |
+
**(live or {"repository_id": repository_id}),
|
| 458 |
+
"live_present": live is not None,
|
| 459 |
+
"classification_state": "UNCLASSIFIED_FAIL_CLOSED",
|
| 460 |
+
"strategy": "REVIEW_REQUIRED",
|
| 461 |
+
"canonical_family": None,
|
| 462 |
+
"delete_authorized": False,
|
| 463 |
+
})
|
| 464 |
+
continue
|
| 465 |
+
revision_state = "NOT_OBSERVED_LIVE"
|
| 466 |
+
if live is not None:
|
| 467 |
+
revision_state = (
|
| 468 |
+
"PIN_MATCH"
|
| 469 |
+
if live.get("revision") == classification["observed_revision"]
|
| 470 |
+
else "REVISION_DRIFT_REVIEW_REQUIRED"
|
| 471 |
+
)
|
| 472 |
+
merged.append({
|
| 473 |
+
**classification,
|
| 474 |
+
**(live or {}),
|
| 475 |
+
"repository_id": repository_id,
|
| 476 |
+
"live_present": live is not None,
|
| 477 |
+
"classification_state": revision_state,
|
| 478 |
+
"delete_authorized": False,
|
| 479 |
+
})
|
| 480 |
+
|
| 481 |
+
freshness = feed.get("freshness") or {}
|
| 482 |
+
freshness_status = freshness.get("status")
|
| 483 |
+
if not live_rows:
|
| 484 |
+
state = "STATIC_CLASSIFICATION_LIVE_FEED_UNAVAILABLE"
|
| 485 |
+
elif freshness_status == "live":
|
| 486 |
+
state = "LIVE"
|
| 487 |
+
elif freshness_status == "cached":
|
| 488 |
+
state = "CACHED"
|
| 489 |
+
elif freshness_status == "stale":
|
| 490 |
+
state = "STALE_LAST_GOOD"
|
| 491 |
+
else:
|
| 492 |
+
state = "LIVE_DATA_FRESHNESS_UNKNOWN"
|
| 493 |
+
|
| 494 |
+
return {
|
| 495 |
+
"state": state,
|
| 496 |
+
"organization": _HF_ORG,
|
| 497 |
+
"models": sorted(
|
| 498 |
+
merged,
|
| 499 |
+
key=lambda item: _download_sort_value(item.get("downloads")),
|
| 500 |
+
reverse=True,
|
| 501 |
+
),
|
| 502 |
+
"summary": {
|
| 503 |
+
"classified_repositories": len(by_id),
|
| 504 |
+
"live_repositories": len(live_rows),
|
| 505 |
+
"weight_bearing_live": sum(bool(item.get("weight_bearing_from_filenames")) for item in live_rows),
|
| 506 |
+
"unclassified_live": sum(item.get("classification_state") == "UNCLASSIFIED_FAIL_CLOSED" for item in merged),
|
| 507 |
+
"revision_drift": sum(item.get("classification_state") == "REVISION_DRIFT_REVIEW_REQUIRED" for item in merged),
|
| 508 |
+
},
|
| 509 |
+
"freshness": freshness,
|
| 510 |
+
"downloadsAreAdoptionSignalNotQuality": True,
|
| 511 |
+
"zeroDownloadsAuthorizeDeletion": False,
|
| 512 |
+
"qualificationAuthority": False,
|
| 513 |
+
"promotionAuthority": False,
|
| 514 |
+
"deleteAuthority": False,
|
| 515 |
+
"externalMutationPerformed": False,
|
| 516 |
+
"doctrine": DOCTRINE,
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
|
| 520 |
def get_pareto(limit: int = 40) -> dict[str, Any]:
|
| 521 |
"""Quality (LMArena Elo) × adoption (HF downloads) non-dominated frontier.
|
| 522 |
Both axes are REAL public signals. Price / tokens-per-sec are ROADMAP (no
|
|
|
|
| 574 |
|
| 575 |
@app.get(base + "/leaderboard", include_in_schema=False)
|
| 576 |
@app.get("/v1/models/leaderboard", include_in_schema=False)
|
| 577 |
+
def _models_leaderboard(limit: int = 40):
|
| 578 |
return JSONResponse(get_leaderboard(limit))
|
| 579 |
|
| 580 |
@app.get(base + "/hub", include_in_schema=False)
|
| 581 |
@app.get("/v1/models/hub", include_in_schema=False)
|
| 582 |
+
def _models_hub(limit: int = 40):
|
| 583 |
return JSONResponse(get_hub(limit))
|
| 584 |
|
| 585 |
@app.get(base + "/pareto", include_in_schema=False)
|
| 586 |
@app.get("/v1/models/pareto", include_in_schema=False)
|
| 587 |
+
def _models_pareto(limit: int = 40):
|
| 588 |
return JSONResponse(get_pareto(limit))
|
| 589 |
|
| 590 |
+
@app.get(base + "/frontier-adoption", include_in_schema=False)
|
| 591 |
+
@app.get("/v1/models/frontier-adoption", include_in_schema=False)
|
| 592 |
+
async def _models_frontier_adoption():
|
| 593 |
+
payload = get_frontier_adoption()
|
| 594 |
+
return JSONResponse(payload, status_code=200 if payload["state"] != "UNAVAILABLE" else 503)
|
| 595 |
+
|
| 596 |
+
@app.get(base + "/estate", include_in_schema=False)
|
| 597 |
+
@app.get("/v1/models/estate", include_in_schema=False)
|
| 598 |
+
def _models_estate():
|
| 599 |
+
payload = get_szl_estate()
|
| 600 |
+
return JSONResponse(payload, status_code=200 if payload["state"] != "UNAVAILABLE" else 503)
|
| 601 |
+
|
| 602 |
@app.get(base + "/info", include_in_schema=False)
|
| 603 |
@app.get("/v1/models/info", include_in_schema=False)
|
| 604 |
async def _models_info():
|
| 605 |
return JSONResponse({"module": "a11oy_model_intel", "base": base,
|
| 606 |
+
"endpoints": ["/leaderboard", "/hub", "/pareto", "/frontier-adoption", "/estate", "/info"],
|
| 607 |
"cited": CITED, "locked": LOCKED, "doctrine": DOCTRINE,
|
| 608 |
"honesty": "Live external model intel; advisory quality signal, "
|
| 609 |
"never a proof. SAMPLE/ROADMAP labelled where not live."})
|
model_release/frontier-qualification/frontier_admission_guard.py
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Offline, fail-closed admission guard for external frontier models.
|
| 2 |
+
|
| 3 |
+
The registry is research and qualification policy, not a downloader, trainer,
|
| 4 |
+
router, publisher, or deletion tool. Unknown repositories and unpinned
|
| 5 |
+
revisions are denied. A permitted operation is only a preflight admission of a
|
| 6 |
+
signed declaration after its exact evidence requirements are supplied; it never
|
| 7 |
+
grants execution authority or implies model quality or promotion eligibility.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import importlib
|
| 14 |
+
import json
|
| 15 |
+
import re
|
| 16 |
+
import sys
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from typing import Any
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
HERE = Path(__file__).resolve().parent
|
| 22 |
+
DEFAULT_REGISTRY = HERE / "frontier-adoption.json"
|
| 23 |
+
SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
|
| 24 |
+
REPO_ROOT = HERE.parents[1]
|
| 25 |
+
EVIDENCE_PAYLOAD_TYPE = "application/vnd.szl.frontier-operation-evidence.v1+json"
|
| 26 |
+
UNSIGNED_OPERATION_ALLOWLIST = frozenset({"READ_METADATA"})
|
| 27 |
+
HARD_DENIED_OPERATIONS = frozenset({
|
| 28 |
+
"TRAIN",
|
| 29 |
+
"SERVE_PRODUCTION",
|
| 30 |
+
"PROMOTE",
|
| 31 |
+
"MERGE_WEIGHTS",
|
| 32 |
+
"INGEST_UPSTREAM_TRAINING_TRACES",
|
| 33 |
+
"IDENTITY_EDIT_REAL_PERSON",
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class FrontierAdmissionError(RuntimeError):
|
| 38 |
+
"""The requested external-model operation failed closed."""
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _load_object(path: Path) -> dict[str, Any]:
|
| 42 |
+
value = json.loads(path.read_text(encoding="utf-8"))
|
| 43 |
+
if not isinstance(value, dict):
|
| 44 |
+
raise FrontierAdmissionError(f"expected JSON object: {path}")
|
| 45 |
+
return value
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def load_registry(path: Path = DEFAULT_REGISTRY) -> dict[str, Any]:
|
| 49 |
+
if not path.is_file():
|
| 50 |
+
raise FrontierAdmissionError(f"frontier adoption registry missing: {path}")
|
| 51 |
+
registry = _load_object(path)
|
| 52 |
+
if registry.get("schema_version") != "szl.frontier-adoption.v1":
|
| 53 |
+
raise FrontierAdmissionError("unsupported frontier adoption registry schema")
|
| 54 |
+
if registry.get("status") != "GOVERNED_PLAN_NOT_LOCAL_QUALIFICATION":
|
| 55 |
+
raise FrontierAdmissionError("frontier registry honesty state changed")
|
| 56 |
+
policy = registry.get("evidence_policy", {})
|
| 57 |
+
required_policy = {
|
| 58 |
+
"local_measurements_present": False,
|
| 59 |
+
"download_performed_by_this_contract": False,
|
| 60 |
+
"promotion_authority": False,
|
| 61 |
+
"unknown_repository_policy": "DENY",
|
| 62 |
+
"zero_download_policy": "ZERO_DOWNLOADS_ALONE_NEVER_AUTHORIZES_DELETE_OR_ARCHIVE",
|
| 63 |
+
}
|
| 64 |
+
for field, expected in required_policy.items():
|
| 65 |
+
if policy.get(field) != expected:
|
| 66 |
+
raise FrontierAdmissionError(f"registry policy mismatch: {field}")
|
| 67 |
+
mutations = registry.get("external_mutations")
|
| 68 |
+
if not isinstance(mutations, dict) or not mutations:
|
| 69 |
+
raise FrontierAdmissionError("registry external_mutations contract is missing")
|
| 70 |
+
if any(value is not False for value in mutations.values()):
|
| 71 |
+
raise FrontierAdmissionError("registry reports an external mutation")
|
| 72 |
+
brain = registry.get("brain_model_truth")
|
| 73 |
+
if not isinstance(brain, dict):
|
| 74 |
+
raise FrontierAdmissionError("registry brain_model_truth is missing")
|
| 75 |
+
if brain.get("raw_nodes_observed") != 9464:
|
| 76 |
+
raise FrontierAdmissionError("registry Brain node observation changed")
|
| 77 |
+
if brain.get("raw_nodes_admitted_to_gradients") != 0:
|
| 78 |
+
raise FrontierAdmissionError("registry reports unadmitted Brain gradient rows")
|
| 79 |
+
github_estate = registry.get("github_estate_strategy")
|
| 80 |
+
if not isinstance(github_estate, dict):
|
| 81 |
+
raise FrontierAdmissionError("registry github_estate_strategy is missing")
|
| 82 |
+
if github_estate.get("source_reported_repository_count") != 54:
|
| 83 |
+
raise FrontierAdmissionError("registry GitHub source count changed")
|
| 84 |
+
if github_estate.get("inventory_complete") is not False:
|
| 85 |
+
raise FrontierAdmissionError("registry overclaims a complete GitHub inventory")
|
| 86 |
+
if github_estate.get("public_github_repositories_observed") != 50:
|
| 87 |
+
raise FrontierAdmissionError("registry public GitHub readback count changed")
|
| 88 |
+
if github_estate.get("public_archived_observed") != 9:
|
| 89 |
+
raise FrontierAdmissionError("registry public GitHub archive count changed")
|
| 90 |
+
if github_estate.get("reconciliation_state") != (
|
| 91 |
+
"SOURCE_REPORT_54_PUBLIC_READBACK_50_ATTACHMENT_TRUNCATED_REVIEW_REQUIRED"
|
| 92 |
+
):
|
| 93 |
+
raise FrontierAdmissionError("registry GitHub reconciliation state changed")
|
| 94 |
+
if github_estate.get("code_to_weight_policy") != (
|
| 95 |
+
"CODE_REPOSITORIES_ARE_SERVICES_LIBRARIES_OR_EVIDENCE_NOT_MODEL_WEIGHTS"
|
| 96 |
+
):
|
| 97 |
+
raise FrontierAdmissionError("registry code-to-weight boundary changed")
|
| 98 |
+
if github_estate.get("unclassified_repository_policy") != (
|
| 99 |
+
"DISCOVER_CLASSIFY_FAIL_CLOSED_NO_ARCHIVE"
|
| 100 |
+
):
|
| 101 |
+
raise FrontierAdmissionError("registry unclassified repository policy changed")
|
| 102 |
+
layers = github_estate.get("layers")
|
| 103 |
+
if not isinstance(layers, list) or len(layers) < 8:
|
| 104 |
+
raise FrontierAdmissionError("registry GitHub estate layer map is incomplete")
|
| 105 |
+
candidates = registry.get("candidates")
|
| 106 |
+
if not isinstance(candidates, list) or len(candidates) < 9:
|
| 107 |
+
raise FrontierAdmissionError("registry candidate inventory is incomplete")
|
| 108 |
+
for candidate in candidates:
|
| 109 |
+
if not isinstance(candidate, dict):
|
| 110 |
+
raise FrontierAdmissionError("registry candidate record is malformed")
|
| 111 |
+
required_candidate = {
|
| 112 |
+
"id", "decision", "upstream", "runtime", "allowed_operations",
|
| 113 |
+
"prohibited_operations", "required_evidence_by_operation",
|
| 114 |
+
}
|
| 115 |
+
if not required_candidate.issubset(candidate):
|
| 116 |
+
raise FrontierAdmissionError("registry candidate record is incomplete")
|
| 117 |
+
upstream = candidate.get("upstream")
|
| 118 |
+
if not isinstance(upstream, dict) or not {
|
| 119 |
+
"repository_id", "revision", "artifact_inventory"
|
| 120 |
+
}.issubset(upstream):
|
| 121 |
+
raise FrontierAdmissionError("registry candidate upstream record is incomplete")
|
| 122 |
+
allowed = candidate.get("allowed_operations")
|
| 123 |
+
prohibited = candidate.get("prohibited_operations")
|
| 124 |
+
requirements = candidate.get("required_evidence_by_operation")
|
| 125 |
+
if not isinstance(allowed, list) or not allowed:
|
| 126 |
+
raise FrontierAdmissionError("registry candidate operation allowlist is missing")
|
| 127 |
+
if not isinstance(prohibited, list) or not HARD_DENIED_OPERATIONS.issubset(prohibited):
|
| 128 |
+
raise FrontierAdmissionError("registry candidate hard-deny boundary changed")
|
| 129 |
+
if set(allowed) & set(prohibited):
|
| 130 |
+
raise FrontierAdmissionError("registry candidate operation is both allowed and prohibited")
|
| 131 |
+
if not isinstance(requirements, dict):
|
| 132 |
+
raise FrontierAdmissionError("registry candidate evidence policy is missing")
|
| 133 |
+
for permitted in allowed:
|
| 134 |
+
if permitted in UNSIGNED_OPERATION_ALLOWLIST:
|
| 135 |
+
continue
|
| 136 |
+
fields = requirements.get(permitted)
|
| 137 |
+
if not isinstance(fields, list) or not fields:
|
| 138 |
+
raise FrontierAdmissionError(
|
| 139 |
+
f"registry candidate signed evidence requirements missing: {permitted}"
|
| 140 |
+
)
|
| 141 |
+
estate = registry.get("hf_estate")
|
| 142 |
+
repositories = estate.get("repositories") if isinstance(estate, dict) else None
|
| 143 |
+
if not isinstance(repositories, list) or len(repositories) < 15:
|
| 144 |
+
raise FrontierAdmissionError("registry Hugging Face estate is incomplete")
|
| 145 |
+
return registry
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _candidate_for_repo(registry: dict[str, Any], repository_id: str) -> dict[str, Any]:
|
| 149 |
+
matches = [
|
| 150 |
+
candidate
|
| 151 |
+
for candidate in registry.get("candidates", [])
|
| 152 |
+
if candidate.get("upstream", {}).get("repository_id") == repository_id
|
| 153 |
+
]
|
| 154 |
+
if len(matches) != 1:
|
| 155 |
+
raise FrontierAdmissionError(
|
| 156 |
+
f"repository is unknown or ambiguous and is denied: {repository_id}"
|
| 157 |
+
)
|
| 158 |
+
return matches[0]
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def _validate_evidence(
|
| 162 |
+
candidate: dict[str, Any],
|
| 163 |
+
operation: str,
|
| 164 |
+
revision: str,
|
| 165 |
+
evidence: dict[str, Any],
|
| 166 |
+
) -> None:
|
| 167 |
+
requirements = candidate.get("required_evidence_by_operation", {}).get(operation, [])
|
| 168 |
+
missing = [field for field in requirements if not evidence.get(field)]
|
| 169 |
+
if missing:
|
| 170 |
+
raise FrontierAdmissionError(
|
| 171 |
+
f"{operation} missing required evidence: {','.join(sorted(missing))}"
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
upstream = candidate["upstream"]
|
| 175 |
+
runtime = candidate["runtime"]
|
| 176 |
+
if "exact_revision" in requirements and evidence["exact_revision"] != revision:
|
| 177 |
+
raise FrontierAdmissionError("evidence exact_revision does not match requested revision")
|
| 178 |
+
if "method_source_revision" in requirements and evidence["method_source_revision"] != revision:
|
| 179 |
+
raise FrontierAdmissionError("method source revision does not match the pinned model card")
|
| 180 |
+
if "runtime_revision" in requirements:
|
| 181 |
+
expected_runtime = runtime["revision"]
|
| 182 |
+
if expected_runtime == "MODEL_CARD_ONLY" or evidence["runtime_revision"] != expected_runtime:
|
| 183 |
+
raise FrontierAdmissionError("runtime revision is absent or does not match the pinned runtime")
|
| 184 |
+
if "artifact_sha256" in requirements:
|
| 185 |
+
allowlisted = {
|
| 186 |
+
item["sha256"] for item in upstream.get("artifact_inventory", [])
|
| 187 |
+
}
|
| 188 |
+
if evidence["artifact_sha256"] not in allowlisted:
|
| 189 |
+
raise FrontierAdmissionError("artifact digest is not in the pinned candidate inventory")
|
| 190 |
+
|
| 191 |
+
for field in requirements:
|
| 192 |
+
if field.endswith("_sha256") and not SHA256_RE.fullmatch(str(evidence[field])):
|
| 193 |
+
raise FrontierAdmissionError(f"invalid SHA-256 evidence value: {field}")
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _verified_evidence_payload(
|
| 197 |
+
evidence_document: dict[str, Any],
|
| 198 |
+
repository_id: str,
|
| 199 |
+
revision: str,
|
| 200 |
+
operation: str,
|
| 201 |
+
) -> tuple[dict[str, Any], dict[str, Any]]:
|
| 202 |
+
"""Verify a signed evidence envelope and bind it to this exact operation.
|
| 203 |
+
|
| 204 |
+
Digest-looking strings are not receipts. Every evidence-bearing operation
|
| 205 |
+
requires an ECDSA-P256 DSSE envelope verifiable by the checked-in SZL public
|
| 206 |
+
key. The signed payload must bind repository, revision, operation, and the
|
| 207 |
+
complete evidence object before any bounded preflight admission can be emitted.
|
| 208 |
+
"""
|
| 209 |
+
|
| 210 |
+
envelope = evidence_document.get("dsse")
|
| 211 |
+
if not isinstance(envelope, dict):
|
| 212 |
+
raise FrontierAdmissionError("signed DSSE evidence envelope is required")
|
| 213 |
+
if str(REPO_ROOT) not in sys.path:
|
| 214 |
+
sys.path.insert(0, str(REPO_ROOT))
|
| 215 |
+
try:
|
| 216 |
+
verifier = importlib.import_module("szl_dsse")
|
| 217 |
+
verdict = verifier.verify_envelope(envelope)
|
| 218 |
+
except Exception as exc:
|
| 219 |
+
raise FrontierAdmissionError(
|
| 220 |
+
f"DSSE verifier unavailable: {type(exc).__name__}"
|
| 221 |
+
) from exc
|
| 222 |
+
if verdict.get("verified") is not True:
|
| 223 |
+
raise FrontierAdmissionError(
|
| 224 |
+
f"DSSE evidence verification failed: {verdict.get('reason', 'signature mismatch')}"
|
| 225 |
+
)
|
| 226 |
+
if verdict.get("payloadType") != EVIDENCE_PAYLOAD_TYPE:
|
| 227 |
+
raise FrontierAdmissionError("signed evidence DSSE payloadType mismatch")
|
| 228 |
+
signatures = verdict.get("signatures") or []
|
| 229 |
+
if not any(
|
| 230 |
+
item.get("verified") is True
|
| 231 |
+
and item.get("keyid") == verdict.get("keyid_expected")
|
| 232 |
+
for item in signatures
|
| 233 |
+
if isinstance(item, dict)
|
| 234 |
+
):
|
| 235 |
+
raise FrontierAdmissionError("signed evidence key identity mismatch")
|
| 236 |
+
payload = verdict.get("payload_decoded")
|
| 237 |
+
if not isinstance(payload, dict):
|
| 238 |
+
raise FrontierAdmissionError("signed DSSE evidence payload is not a JSON object")
|
| 239 |
+
expected_binding = {
|
| 240 |
+
"schema_version": "szl.frontier-operation-evidence.v1",
|
| 241 |
+
"repository_id": repository_id,
|
| 242 |
+
"revision": revision,
|
| 243 |
+
"operation": operation,
|
| 244 |
+
}
|
| 245 |
+
for field, expected in expected_binding.items():
|
| 246 |
+
if payload.get(field) != expected:
|
| 247 |
+
raise FrontierAdmissionError(f"signed evidence binding mismatch: {field}")
|
| 248 |
+
evidence = payload.get("evidence")
|
| 249 |
+
if not isinstance(evidence, dict):
|
| 250 |
+
raise FrontierAdmissionError("signed evidence payload has no evidence object")
|
| 251 |
+
return evidence, verdict
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def assert_operation_allowed(
|
| 255 |
+
repository_id: str,
|
| 256 |
+
revision: str,
|
| 257 |
+
operation: str,
|
| 258 |
+
evidence: dict[str, Any] | None = None,
|
| 259 |
+
registry_path: Path = DEFAULT_REGISTRY,
|
| 260 |
+
) -> dict[str, Any]:
|
| 261 |
+
"""Preflight-admit one bounded operation declaration or fail closed.
|
| 262 |
+
|
| 263 |
+
The return value is deliberately explicit that this check is not a model
|
| 264 |
+
qualification, execution, or promotion decision. Metadata reads are the only
|
| 265 |
+
directly authorized operation; signed declarations still require a separate
|
| 266 |
+
replay-protected executor admission.
|
| 267 |
+
"""
|
| 268 |
+
|
| 269 |
+
registry = load_registry(registry_path)
|
| 270 |
+
candidate = _candidate_for_repo(registry, repository_id)
|
| 271 |
+
pinned_revision = candidate["upstream"]["revision"]
|
| 272 |
+
if revision != pinned_revision:
|
| 273 |
+
raise FrontierAdmissionError(
|
| 274 |
+
f"revision mismatch for {repository_id}: expected {pinned_revision}"
|
| 275 |
+
)
|
| 276 |
+
if operation in HARD_DENIED_OPERATIONS:
|
| 277 |
+
raise FrontierAdmissionError(
|
| 278 |
+
f"operation is hard-denied by executable policy: {operation}"
|
| 279 |
+
)
|
| 280 |
+
if operation in candidate.get("prohibited_operations", []):
|
| 281 |
+
raise FrontierAdmissionError(
|
| 282 |
+
f"operation is explicitly prohibited for {repository_id}: {operation}"
|
| 283 |
+
)
|
| 284 |
+
if operation not in candidate.get("allowed_operations", []):
|
| 285 |
+
raise FrontierAdmissionError(
|
| 286 |
+
f"operation is not allowlisted for {repository_id}: {operation}"
|
| 287 |
+
)
|
| 288 |
+
requirements = candidate.get("required_evidence_by_operation", {}).get(operation, [])
|
| 289 |
+
if operation not in UNSIGNED_OPERATION_ALLOWLIST and not requirements:
|
| 290 |
+
raise FrontierAdmissionError(
|
| 291 |
+
f"operation lacks mandatory signed evidence requirements: {operation}"
|
| 292 |
+
)
|
| 293 |
+
evidence_verified = False
|
| 294 |
+
dsse_pae_sha256 = None
|
| 295 |
+
evidence_values: dict[str, Any] = {}
|
| 296 |
+
if requirements:
|
| 297 |
+
evidence_values, verdict = _verified_evidence_payload(
|
| 298 |
+
evidence or {}, repository_id, revision, operation
|
| 299 |
+
)
|
| 300 |
+
evidence_verified = True
|
| 301 |
+
dsse_pae_sha256 = verdict.get("pae_sha256")
|
| 302 |
+
_validate_evidence(candidate, operation, revision, evidence_values)
|
| 303 |
+
metadata_read = operation in UNSIGNED_OPERATION_ALLOWLIST
|
| 304 |
+
return {
|
| 305 |
+
"schema_version": "szl.frontier-operation-admission.v1",
|
| 306 |
+
"repository_id": repository_id,
|
| 307 |
+
"revision": revision,
|
| 308 |
+
"candidate_id": candidate["id"],
|
| 309 |
+
"decision": candidate["decision"],
|
| 310 |
+
"operation": operation,
|
| 311 |
+
"operation_allowed_by_registry": True,
|
| 312 |
+
"operation_authorized": metadata_read,
|
| 313 |
+
"operation_preflight_admitted": metadata_read or evidence_verified,
|
| 314 |
+
"execution_authority": False,
|
| 315 |
+
"replay_protected": False,
|
| 316 |
+
"execution_boundary": (
|
| 317 |
+
"METADATA_READ_ONLY"
|
| 318 |
+
if metadata_read
|
| 319 |
+
else "SIGNED_DECLARATION_ONLY_REQUIRES_RUN_BOUND_EXECUTOR_ADMISSION"
|
| 320 |
+
),
|
| 321 |
+
"evidence_verified": evidence_verified,
|
| 322 |
+
"signed_evidence_declaration_verified": evidence_verified,
|
| 323 |
+
"underlying_receipt_content_recomputed": False,
|
| 324 |
+
"dsse_pae_sha256": dsse_pae_sha256,
|
| 325 |
+
"model_qualified": False,
|
| 326 |
+
"training_authorized": False,
|
| 327 |
+
"production_serving_authorized": False,
|
| 328 |
+
"promotion_authorized": False,
|
| 329 |
+
"external_mutation_performed": False,
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def classify_hf_repository(
|
| 334 |
+
repository_id: str,
|
| 335 |
+
registry_path: Path = DEFAULT_REGISTRY,
|
| 336 |
+
) -> dict[str, Any]:
|
| 337 |
+
registry = load_registry(registry_path)
|
| 338 |
+
matches = [
|
| 339 |
+
item
|
| 340 |
+
for item in registry.get("hf_estate", {}).get("repositories", [])
|
| 341 |
+
if item.get("repository_id") == repository_id
|
| 342 |
+
]
|
| 343 |
+
if len(matches) != 1:
|
| 344 |
+
return {
|
| 345 |
+
"repository_id": repository_id,
|
| 346 |
+
"classification": "UNCLASSIFIED_FAIL_CLOSED",
|
| 347 |
+
"delete_authorized": False,
|
| 348 |
+
}
|
| 349 |
+
return dict(matches[0])
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def audit_registry(registry_path: Path = DEFAULT_REGISTRY) -> dict[str, Any]:
|
| 353 |
+
registry = load_registry(registry_path)
|
| 354 |
+
errors: list[str] = []
|
| 355 |
+
candidates = registry.get("candidates", [])
|
| 356 |
+
ids = [candidate.get("id") for candidate in candidates]
|
| 357 |
+
repos = [candidate.get("upstream", {}).get("repository_id") for candidate in candidates]
|
| 358 |
+
if len(ids) != len(set(ids)):
|
| 359 |
+
errors.append("duplicate candidate id")
|
| 360 |
+
if len(repos) != len(set(repos)):
|
| 361 |
+
errors.append("duplicate candidate repository")
|
| 362 |
+
|
| 363 |
+
for candidate in candidates:
|
| 364 |
+
allowed = set(candidate.get("allowed_operations", []))
|
| 365 |
+
prohibited = set(candidate.get("prohibited_operations", []))
|
| 366 |
+
if allowed & prohibited:
|
| 367 |
+
errors.append(f"{candidate.get('id')}: operation both allowed and prohibited")
|
| 368 |
+
if candidate.get("decision", "").startswith("QUARANTINE_") and allowed != {"READ_METADATA"}:
|
| 369 |
+
errors.append(f"{candidate.get('id')}: quarantine may only allow metadata reads")
|
| 370 |
+
if candidate.get("decision") in {"LOCAL_QUALIFY", "EVALUATION_ONLY_INFERENCE_ARTIFACT"}:
|
| 371 |
+
if not candidate.get("required_evidence_by_operation", {}).get("EVALUATE_SANDBOXED"):
|
| 372 |
+
errors.append(f"{candidate.get('id')}: sandbox evaluation lacks evidence requirements")
|
| 373 |
+
if "TRAIN" not in prohibited or "PROMOTE" not in prohibited or "MERGE_WEIGHTS" not in prohibited:
|
| 374 |
+
errors.append(f"{candidate.get('id')}: frontier candidates must deny train/promote/merge")
|
| 375 |
+
|
| 376 |
+
estate = registry.get("hf_estate", {}).get("repositories", [])
|
| 377 |
+
estate_ids = [item.get("repository_id") for item in estate]
|
| 378 |
+
if len(estate_ids) != len(set(estate_ids)):
|
| 379 |
+
errors.append("duplicate Hugging Face estate repository")
|
| 380 |
+
if any(item.get("delete_authorized") is not False for item in estate):
|
| 381 |
+
errors.append("an estate record authorizes deletion")
|
| 382 |
+
|
| 383 |
+
policy = registry["evidence_policy"]
|
| 384 |
+
mutations = registry["external_mutations"]
|
| 385 |
+
github_estate = registry["github_estate_strategy"]
|
| 386 |
+
return {
|
| 387 |
+
"schema_version": "szl.frontier-adoption-audit.v1",
|
| 388 |
+
"state": "PASS" if not errors else "FAIL",
|
| 389 |
+
"candidate_count": len(candidates),
|
| 390 |
+
"estate_repository_count": len(estate),
|
| 391 |
+
"github_source_report_count": github_estate["source_reported_repository_count"],
|
| 392 |
+
"github_public_readback_count": github_estate["public_github_repositories_observed"],
|
| 393 |
+
"github_inventory_complete": github_estate["inventory_complete"],
|
| 394 |
+
"local_measurements_present": bool(policy["local_measurements_present"]),
|
| 395 |
+
"promotion_authority": bool(policy["promotion_authority"]),
|
| 396 |
+
"external_mutation_performed": any(bool(value) for value in mutations.values()),
|
| 397 |
+
"errors": errors,
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def _main(argv: list[str] | None = None) -> int:
|
| 402 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 403 |
+
parser.add_argument("--registry", type=Path, default=DEFAULT_REGISTRY)
|
| 404 |
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
| 405 |
+
subparsers.add_parser("audit")
|
| 406 |
+
check = subparsers.add_parser("check")
|
| 407 |
+
check.add_argument("--repository", required=True)
|
| 408 |
+
check.add_argument("--revision", required=True)
|
| 409 |
+
check.add_argument("--operation", required=True)
|
| 410 |
+
check.add_argument("--evidence-json", type=Path)
|
| 411 |
+
classify = subparsers.add_parser("classify-estate")
|
| 412 |
+
classify.add_argument("--repository", required=True)
|
| 413 |
+
args = parser.parse_args(argv)
|
| 414 |
+
try:
|
| 415 |
+
if args.command == "audit":
|
| 416 |
+
result = audit_registry(args.registry)
|
| 417 |
+
print(json.dumps(result, indent=2, sort_keys=True))
|
| 418 |
+
return 0 if result["state"] == "PASS" else 2
|
| 419 |
+
if args.command == "classify-estate":
|
| 420 |
+
print(json.dumps(classify_hf_repository(args.repository, args.registry), indent=2, sort_keys=True))
|
| 421 |
+
return 0
|
| 422 |
+
evidence = _load_object(args.evidence_json) if args.evidence_json else {}
|
| 423 |
+
result = assert_operation_allowed(
|
| 424 |
+
args.repository,
|
| 425 |
+
args.revision,
|
| 426 |
+
args.operation,
|
| 427 |
+
evidence,
|
| 428 |
+
args.registry,
|
| 429 |
+
)
|
| 430 |
+
print(json.dumps(result, indent=2, sort_keys=True))
|
| 431 |
+
return 0
|
| 432 |
+
except (OSError, ValueError, KeyError, FrontierAdmissionError) as exc:
|
| 433 |
+
print(json.dumps({
|
| 434 |
+
"state": "BLOCKED",
|
| 435 |
+
"reason": str(exc),
|
| 436 |
+
"external_mutation_performed": False,
|
| 437 |
+
}, indent=2, sort_keys=True))
|
| 438 |
+
return 3
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
if __name__ == "__main__":
|
| 442 |
+
raise SystemExit(_main())
|