Spaces:
Running
Running
perf: defer runtime inspection until model evidence
Browse files
scripts/run_content_matrix.py
CHANGED
|
@@ -93,17 +93,17 @@ def main() -> int:
|
|
| 93 |
finally:
|
| 94 |
stop(process)
|
| 95 |
stop(canary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if (
|
| 97 |
percentile(starts, 95) >= 1000
|
| 98 |
or percentile(qualification, 95) >= 100
|
| 99 |
or percentile(empties, 95) >= 500
|
| 100 |
):
|
| 101 |
raise RuntimeError("content latency gate failed")
|
| 102 |
-
results["latency_ms"] = {
|
| 103 |
-
"process_start_to_first_stop_p95": percentile(starts, 95),
|
| 104 |
-
"qualification_to_first_stop_p95": percentile(qualification, 95),
|
| 105 |
-
"trigger_to_empty_p95": percentile(empties, 95),
|
| 106 |
-
}
|
| 107 |
results["result"] = "PASS"
|
| 108 |
args.output.write_text(json.dumps(results, sort_keys=True) + "\n", encoding="utf-8")
|
| 109 |
return 0
|
|
|
|
| 93 |
finally:
|
| 94 |
stop(process)
|
| 95 |
stop(canary)
|
| 96 |
+
results["latency_ms"] = {
|
| 97 |
+
"process_start_to_first_stop_p95": percentile(starts, 95),
|
| 98 |
+
"qualification_to_first_stop_p95": percentile(qualification, 95),
|
| 99 |
+
"trigger_to_empty_p95": percentile(empties, 95),
|
| 100 |
+
}
|
| 101 |
if (
|
| 102 |
percentile(starts, 95) >= 1000
|
| 103 |
or percentile(qualification, 95) >= 100
|
| 104 |
or percentile(empties, 95) >= 500
|
| 105 |
):
|
| 106 |
raise RuntimeError("content latency gate failed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
results["result"] = "PASS"
|
| 108 |
args.output.write_text(json.dumps(results, sort_keys=True) + "\n", encoding="utf-8")
|
| 109 |
return 0
|
src/lumi_eggcracker/artifacts.py
CHANGED
|
@@ -111,6 +111,22 @@ def validate_path(path: Path) -> ArtifactEvidence | None:
|
|
| 111 |
os.close(descriptor)
|
| 112 |
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
def from_process_fds(
|
| 115 |
snapshot: object, *, proc: Path = Path("/proc")
|
| 116 |
) -> tuple[ArtifactEvidence, ...]:
|
|
@@ -152,10 +168,13 @@ def from_process_fds(
|
|
| 152 |
def from_snapshot(snapshot: object, *, proc: Path = Path("/proc")) -> tuple[ArtifactEvidence, ...]:
|
| 153 |
"""Collect bounded GGUF evidence from open descriptors and mapped files."""
|
| 154 |
result = list(from_process_fds(snapshot, proc=proc))
|
| 155 |
-
for raw in tuple(getattr(snapshot, "map_paths", ()))
|
| 156 |
if not isinstance(raw, str) or not raw.startswith("/"):
|
| 157 |
continue
|
| 158 |
-
|
|
|
|
| 159 |
if evidence is not None and evidence not in result:
|
| 160 |
result.append(evidence)
|
|
|
|
|
|
|
| 161 |
return tuple(result[:MAX_ARTIFACTS])
|
|
|
|
| 111 |
os.close(descriptor)
|
| 112 |
|
| 113 |
|
| 114 |
+
def _looks_like_gguf(path: Path) -> bool:
|
| 115 |
+
"""Use only a four-byte bounded probe before full artifact validation."""
|
| 116 |
+
flags = os.O_RDONLY | getattr(os, "O_CLOEXEC", 0) | getattr(os, "O_NOFOLLOW", 0)
|
| 117 |
+
try:
|
| 118 |
+
descriptor = os.open(path, flags)
|
| 119 |
+
except OSError:
|
| 120 |
+
return False
|
| 121 |
+
try:
|
| 122 |
+
metadata = os.fstat(descriptor)
|
| 123 |
+
return stat.S_ISREG(metadata.st_mode) and os.read(descriptor, 4) == b"GGUF"
|
| 124 |
+
except OSError:
|
| 125 |
+
return False
|
| 126 |
+
finally:
|
| 127 |
+
os.close(descriptor)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
def from_process_fds(
|
| 131 |
snapshot: object, *, proc: Path = Path("/proc")
|
| 132 |
) -> tuple[ArtifactEvidence, ...]:
|
|
|
|
| 168 |
def from_snapshot(snapshot: object, *, proc: Path = Path("/proc")) -> tuple[ArtifactEvidence, ...]:
|
| 169 |
"""Collect bounded GGUF evidence from open descriptors and mapped files."""
|
| 170 |
result = list(from_process_fds(snapshot, proc=proc))
|
| 171 |
+
for raw in tuple(getattr(snapshot, "map_paths", ())):
|
| 172 |
if not isinstance(raw, str) or not raw.startswith("/"):
|
| 173 |
continue
|
| 174 |
+
path = Path(raw)
|
| 175 |
+
evidence = validate_path(path) if _looks_like_gguf(path) else None
|
| 176 |
if evidence is not None and evidence not in result:
|
| 177 |
result.append(evidence)
|
| 178 |
+
if len(result) >= MAX_ARTIFACTS:
|
| 179 |
+
break
|
| 180 |
return tuple(result[:MAX_ARTIFACTS])
|
src/lumi_eggcracker/supervisor.py
CHANGED
|
@@ -486,7 +486,7 @@ class Supervisor:
|
|
| 486 |
first_seen_ns = time.monotonic_ns()
|
| 487 |
if detected is None:
|
| 488 |
content = artifacts_from_snapshot(snapshot)
|
| 489 |
-
runtimes = runtime_from_snapshot(snapshot)
|
| 490 |
supplied = {
|
| 491 |
"MODEL_CONTENT": {item.evidence_id for item in content},
|
| 492 |
"INFERENCE_RUNTIME": {item.evidence_id for item in runtimes},
|
|
|
|
| 486 |
first_seen_ns = time.monotonic_ns()
|
| 487 |
if detected is None:
|
| 488 |
content = artifacts_from_snapshot(snapshot)
|
| 489 |
+
runtimes = runtime_from_snapshot(snapshot) if content else ()
|
| 490 |
supplied = {
|
| 491 |
"MODEL_CONTENT": {item.evidence_id for item in content},
|
| 492 |
"INFERENCE_RUNTIME": {item.evidence_id for item in runtimes},
|
tests/test_artifacts.py
CHANGED
|
@@ -34,6 +34,12 @@ class ArtifactTests(unittest.TestCase):
|
|
| 34 |
path.write_bytes(body)
|
| 35 |
self.assertIsNone(validate_path(path))
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def test_symlink_and_non_regular_files_do_not_qualify(self) -> None:
|
| 38 |
with tempfile.TemporaryDirectory() as raw:
|
| 39 |
root = Path(raw)
|
|
|
|
| 34 |
path.write_bytes(body)
|
| 35 |
self.assertIsNone(validate_path(path))
|
| 36 |
|
| 37 |
+
def test_ai_looking_filename_is_not_content_evidence(self) -> None:
|
| 38 |
+
with tempfile.TemporaryDirectory() as raw:
|
| 39 |
+
path = Path(raw) / "model.gguf"
|
| 40 |
+
path.write_bytes(b"not a model")
|
| 41 |
+
self.assertIsNone(validate_path(path))
|
| 42 |
+
|
| 43 |
def test_symlink_and_non_regular_files_do_not_qualify(self) -> None:
|
| 44 |
with tempfile.TemporaryDirectory() as raw:
|
| 45 |
root = Path(raw)
|