Spaces:
Running
Running
perf: defer runtime inspection until model evidence
Browse filesFiles changed (4)
92 unmodified lines9394959697989910010110210310410510610710810992 unmodified linesfinally:stop(process)stop(canary)if (percentile(starts, 95) >= 1000or percentile(qualification, 95) >= 100or percentile(empties, 95) >= 500):raise RuntimeError("content latency gate failed")results["latency_ms"] = {"process_start_to_first_stop_p95": percentile(starts, 95),"qualification_to_first_stop_p95": percentile(qualification, 95),"trigger_to_empty_p95": percentile(empties, 95),}results["result"] = "PASS"args.output.write_text(json.dumps(results, sort_keys=True) + "\n", encoding="utf-8")return 092 unmodified lines9394959697989910010110210310410510610710810992 unmodified linesfinally:stop(process)stop(canary)results["latency_ms"] = {"process_start_to_first_stop_p95": percentile(starts, 95),"qualification_to_first_stop_p95": percentile(qualification, 95),"trigger_to_empty_p95": percentile(empties, 95),}if (percentile(starts, 95) >= 1000or percentile(qualification, 95) >= 100or percentile(empties, 95) >= 500):raise RuntimeError("content latency gate failed")results["result"] = "PASS"args.output.write_text(json.dumps(results, sort_keys=True) + "\n", encoding="utf-8")return 0
110 unmodified lines11111211311411511635 unmodified lines152153154155156157158159160161110 unmodified linesos.close(descriptor)def from_process_fds(snapshot: object, *, proc: Path = Path("/proc")) -> tuple[ArtifactEvidence, ...]:35 unmodified linesdef from_snapshot(snapshot: object, *, proc: Path = Path("/proc")) -> tuple[ArtifactEvidence, ...]:"""Collect bounded GGUF evidence from open descriptors and mapped files."""result = list(from_process_fds(snapshot, proc=proc))for raw in tuple(getattr(snapshot, "map_paths", ()))[:MAX_ARTIFACTS]:if not isinstance(raw, str) or not raw.startswith("/"):continueevidence = validate_path(Path(raw))if evidence is not None and evidence not in result:result.append(evidence)return tuple(result[:MAX_ARTIFACTS])110 unmodified lines11111211311411511611711811912012112212312412512612712812913013113235 unmodified lines168169170171172173174175176177178179180110 unmodified linesos.close(descriptor)def _looks_like_gguf(path: Path) -> bool:"""Use only a four-byte bounded probe before full artifact validation."""flags = os.O_RDONLY | getattr(os, "O_CLOEXEC", 0) | getattr(os, "O_NOFOLLOW", 0)try:descriptor = os.open(path, flags)except OSError:return Falsetry:metadata = os.fstat(descriptor)return stat.S_ISREG(metadata.st_mode) and os.read(descriptor, 4) == b"GGUF"except OSError:return Falsefinally:os.close(descriptor)def from_process_fds(snapshot: object, *, proc: Path = Path("/proc")) -> tuple[ArtifactEvidence, ...]:35 unmodified linesdef from_snapshot(snapshot: object, *, proc: Path = Path("/proc")) -> tuple[ArtifactEvidence, ...]:"""Collect bounded GGUF evidence from open descriptors and mapped files."""result = list(from_process_fds(snapshot, proc=proc))for raw in tuple(getattr(snapshot, "map_paths", ())):if not isinstance(raw, str) or not raw.startswith("/"):continuepath = Path(raw)evidence = validate_path(path) if _looks_like_gguf(path) else Noneif evidence is not None and evidence not in result:result.append(evidence)if len(result) >= MAX_ARTIFACTS:breakreturn tuple(result[:MAX_ARTIFACTS])
485 unmodified lines486487488489490491492485 unmodified linesfirst_seen_ns = time.monotonic_ns()if detected is None:content = artifacts_from_snapshot(snapshot)runtimes = runtime_from_snapshot(snapshot)supplied = {"MODEL_CONTENT": {item.evidence_id for item in content},"INFERENCE_RUNTIME": {item.evidence_id for item in runtimes},485 unmodified lines486487488489490491492485 unmodified linesfirst_seen_ns = time.monotonic_ns()if detected is None:content = artifacts_from_snapshot(snapshot)runtimes = runtime_from_snapshot(snapshot) if content else ()supplied = {"MODEL_CONTENT": {item.evidence_id for item in content},"INFERENCE_RUNTIME": {item.evidence_id for item in runtimes},
33 unmodified lines34353637383933 unmodified linespath.write_bytes(body)self.assertIsNone(validate_path(path))def test_symlink_and_non_regular_files_do_not_qualify(self) -> None:with tempfile.TemporaryDirectory() as raw:root = Path(raw)33 unmodified lines34353637383940414243444533 unmodified linespath.write_bytes(body)self.assertIsNone(validate_path(path))def test_ai_looking_filename_is_not_content_evidence(self) -> None:with tempfile.TemporaryDirectory() as raw:path = Path(raw) / "model.gguf"path.write_bytes(b"not a model")self.assertIsNone(validate_path(path))def test_symlink_and_non_regular_files_do_not_qualify(self) -> None:with tempfile.TemporaryDirectory() as raw:root = Path(raw)
scripts/run_content_matrix.py+5-5
src/lumi_eggcracker/artifacts.py+21-2
src/lumi_eggcracker/supervisor.py+1-1
tests/test_artifacts.py+6