Spaces:
Running
Running
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): szl_sovereign_compute.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.
- szl_sovereign_compute.py +216 -0
szl_sovereign_compute.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 3 |
+
# Doctrine v11 LOCKED: 749 declarations · 14 unique axioms · 163 sorries · 13-axis
|
| 4 |
+
# Co-Authored-By: Perplexity Computer Agent
|
| 5 |
+
"""
|
| 6 |
+
szl_sovereign_compute.py — ADDITIVE single-pane readiness for the SOVEREIGN
|
| 7 |
+
COMPUTE stack (a11oy). One honest endpoint + mobile panel that answers the
|
| 8 |
+
Warhacker-outbrief question: "is the agent running on our own GPU yet, and what
|
| 9 |
+
is real vs roadmap right now?"
|
| 10 |
+
|
| 11 |
+
It does NOT invent status. Every line is read live from surfaces already shipped:
|
| 12 |
+
* brain — GET /api/a11oy/v1/code/health (inference: self-hosted-gpu |
|
| 13 |
+
hf-router | NO-CREDENTIAL; primary_model; #319)
|
| 14 |
+
* embeddings — GET /api/a11oy/v1/alloy-embed-fabric/health (backend.kind:
|
| 15 |
+
self-hosted-gpu | hf-router | catalog-only; #320)
|
| 16 |
+
* doctrine — the LOCKED anchor (8 / 749-14-163 / c7c0ba17 / Λ=Conjecture 1),
|
| 17 |
+
surfaced verbatim, never recomputed here.
|
| 18 |
+
|
| 19 |
+
Each capability gets an honest tier:
|
| 20 |
+
LIVE-SOVEREIGN — running on our own GPU (self-hosted-gpu, reachable)
|
| 21 |
+
LIVE-MANAGED — live, but via a managed router (hf-router)
|
| 22 |
+
HONEST-STUB — up in a deterministic/catalog state, no live model (never faked)
|
| 23 |
+
ROADMAP — declared, not yet wired (e.g. PQC, Iron Bank) — label only
|
| 24 |
+
|
| 25 |
+
from szl_sovereign_compute import register as register_sovereign_compute
|
| 26 |
+
register_sovereign_compute(app, ns="a11oy")
|
| 27 |
+
|
| 28 |
+
Routes (NEW; never collide):
|
| 29 |
+
GET /api/{ns}/v1/sovereign-compute — JSON posture (machine-readable)
|
| 30 |
+
GET /sovereign-compute — mobile-first HTML panel
|
| 31 |
+
|
| 32 |
+
Doctrine v11 LOCKED. SLSA L1 honest. Defensive: can never take down a route.
|
| 33 |
+
"""
|
| 34 |
+
from __future__ import annotations
|
| 35 |
+
|
| 36 |
+
import json as _json
|
| 37 |
+
import os as _os
|
| 38 |
+
import urllib.request as _ureq
|
| 39 |
+
|
| 40 |
+
DOCTRINE = {
|
| 41 |
+
"version": "v11",
|
| 42 |
+
"locked_proven": ["F1", "F4", "F7", "F11", "F12", "F18", "F19", "F22"],
|
| 43 |
+
"locked_count": 8,
|
| 44 |
+
"corpus": "749/14/163",
|
| 45 |
+
"kernel_commit": "c7c0ba17",
|
| 46 |
+
"lambda": "Conjecture 1 (advisory floor; unconditional uniqueness machine-checked FALSE; NOT a theorem)",
|
| 47 |
+
"khipu_bft": "Conjecture 2",
|
| 48 |
+
"slsa": "L1 honest (L2 .att emitted not independently verified; L3/FedRAMP/IronBank/CMMC = roadmap)",
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# ROADMAP capabilities — declared, honestly NOT live until their dep/feed is wired.
|
| 52 |
+
ROADMAP = [
|
| 53 |
+
{"id": "pqc", "name": "Post-quantum hybrid signing (ML-DSA/ML-KEM/SLH-DSA)",
|
| 54 |
+
"tier": "ROADMAP", "note": "Wires LIVE when liboqs/oqs-python is in the image. Never fabricates a PQC sig today."},
|
| 55 |
+
{"id": "ironbank", "name": "Iron Bank hardened base images",
|
| 56 |
+
"tier": "ROADMAP", "note": "registry1.dso.mil base — unblocks FedRAMP/CMMC/IL-5/6 prework."},
|
| 57 |
+
{"id": "wire_d_mesh", "name": "Wire D cross-mesh traceparent propagation",
|
| 58 |
+
"tier": "ROADMAP", "note": "traceparent is in-process today; cross-organ needs >=2 organs live (mesh)."},
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _get_json(url: str, timeout: float = 6.0):
|
| 63 |
+
try:
|
| 64 |
+
req = _ureq.Request(url, headers={"User-Agent": "szl-sovereign-compute"})
|
| 65 |
+
with _ureq.urlopen(req, timeout=timeout) as r: # noqa: S310
|
| 66 |
+
if r.status != 200:
|
| 67 |
+
return None, r.status
|
| 68 |
+
return _json.loads(r.read().decode()), 200
|
| 69 |
+
except Exception as e: # noqa: BLE001
|
| 70 |
+
return None, type(e).__name__
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _self_base(ns: str) -> str:
|
| 74 |
+
# Probe THIS process via loopback so the posture reflects the running app,
|
| 75 |
+
# not a cached external view. Port honored from the app's own env.
|
| 76 |
+
port = _os.environ.get("A11OY_PORT") or _os.environ.get("PORT") or "7860"
|
| 77 |
+
return f"http://127.0.0.1:{port}"
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _brain_capability(base: str, ns: str) -> dict:
|
| 81 |
+
data, code = _get_json(f"{base}/api/{ns}/v1/code/health")
|
| 82 |
+
if not data:
|
| 83 |
+
return {"id": "brain", "name": "Agent brain (code/chat completion)",
|
| 84 |
+
"tier": "UNREACHABLE", "probe_http": code,
|
| 85 |
+
"note": "code/health did not return 200 from loopback."}
|
| 86 |
+
inf = data.get("inference", "")
|
| 87 |
+
model = data.get("primary_model")
|
| 88 |
+
if inf == "self-hosted-gpu":
|
| 89 |
+
tier = "LIVE-SOVEREIGN"
|
| 90 |
+
elif inf == "hf-router":
|
| 91 |
+
tier = "LIVE-MANAGED"
|
| 92 |
+
else:
|
| 93 |
+
tier = "HONEST-STUB"
|
| 94 |
+
return {"id": "brain", "name": "Agent brain (code/chat completion)", "tier": tier,
|
| 95 |
+
"inference": inf, "mode": data.get("mode"), "primary_model": model,
|
| 96 |
+
"router_base": data.get("router_base"), "token_source": data.get("token_source"),
|
| 97 |
+
"note": ("Running on our own GPU." if tier == "LIVE-SOVEREIGN"
|
| 98 |
+
else "Live via managed HF Router." if tier == "LIVE-MANAGED"
|
| 99 |
+
else "Up in honest deterministic stub (no live model credential).")}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _embed_capability(base: str, ns: str) -> dict:
|
| 103 |
+
data, code = _get_json(f"{base}/api/{ns}/v1/alloy-embed-fabric/health")
|
| 104 |
+
if not data:
|
| 105 |
+
return {"id": "embeddings", "name": "Vertical retrieval embeddings",
|
| 106 |
+
"tier": "UNREACHABLE", "probe_http": code,
|
| 107 |
+
"note": "embed-fabric health did not return 200 from loopback."}
|
| 108 |
+
b = data.get("backend", {})
|
| 109 |
+
kind = b.get("kind", "")
|
| 110 |
+
if kind == "self-hosted-gpu" and b.get("reachable"):
|
| 111 |
+
tier = "LIVE-SOVEREIGN"
|
| 112 |
+
elif kind == "self-hosted-gpu":
|
| 113 |
+
tier = "WIRED-UNREACHABLE"
|
| 114 |
+
elif kind == "hf-router":
|
| 115 |
+
tier = "LIVE-MANAGED"
|
| 116 |
+
else:
|
| 117 |
+
tier = "HONEST-STUB" # catalog-only
|
| 118 |
+
return {"id": "embeddings", "name": "Vertical retrieval embeddings", "tier": tier,
|
| 119 |
+
"kind": kind, "model": b.get("model"), "reachable": b.get("reachable"),
|
| 120 |
+
"note": ("Live embedder on our own GPU." if tier == "LIVE-SOVEREIGN"
|
| 121 |
+
else "GPU endpoint configured but not reachable (check network/box)." if tier == "WIRED-UNREACHABLE"
|
| 122 |
+
else "Catalog-only: no live embedder wired (keyword retrieval still honest).")}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _posture(ns: str) -> dict:
|
| 126 |
+
base = _self_base(ns)
|
| 127 |
+
caps = [_brain_capability(base, ns), _embed_capability(base, ns)]
|
| 128 |
+
sovereign = any(c["tier"] == "LIVE-SOVEREIGN" for c in caps)
|
| 129 |
+
summary = ("SOVEREIGN-GPU LIVE" if all(c["tier"] == "LIVE-SOVEREIGN" for c in caps)
|
| 130 |
+
else "PARTIAL SOVEREIGN (some on own GPU)" if sovereign
|
| 131 |
+
else "MANAGED/STUB — not yet on our GPU")
|
| 132 |
+
return {
|
| 133 |
+
"service": "sovereign-compute", "doctrine": DOCTRINE["version"],
|
| 134 |
+
"summary": summary, "sovereign_any": sovereign,
|
| 135 |
+
"capabilities": caps, "roadmap": ROADMAP, "doctrine_lock": DOCTRINE,
|
| 136 |
+
"honesty": ("Every capability tier is derived from a live loopback probe of an "
|
| 137 |
+
"already-shipped health endpoint — never asserted. LIVE-SOVEREIGN means a "
|
| 138 |
+
"real self-hosted GPU endpoint answered; ROADMAP items are labelled, not faked."),
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _html(p: dict) -> str:
|
| 143 |
+
def chip(t: str) -> str:
|
| 144 |
+
col = {"LIVE-SOVEREIGN": "#42d392", "LIVE-MANAGED": "#5fb8ff",
|
| 145 |
+
"HONEST-STUB": "#e0b34a", "WIRED-UNREACHABLE": "#ff7b72",
|
| 146 |
+
"UNREACHABLE": "#ff7b72", "ROADMAP": "#9aa7b4"}.get(t, "#9aa7b4")
|
| 147 |
+
return f'<span class="tier" style="color:{col};border-color:{col}">{t}</span>'
|
| 148 |
+
caps = "".join(f"""
|
| 149 |
+
<article class="card">
|
| 150 |
+
<div class="row"><h3>{c['name']}</h3>{chip(c['tier'])}</div>
|
| 151 |
+
<p class="what">{c.get('note','')}</p>
|
| 152 |
+
<p class="meta">{c.get('inference') or c.get('kind') or ''} {('· '+str(c.get('primary_model') or c.get('model') or '')) if (c.get('primary_model') or c.get('model')) else ''}</p>
|
| 153 |
+
</article>""" for c in p["capabilities"])
|
| 154 |
+
road = "".join(f"""
|
| 155 |
+
<article class="card road">
|
| 156 |
+
<div class="row"><h3>{r['name']}</h3>{chip(r['tier'])}</div>
|
| 157 |
+
<p class="what">{r['note']}</p>
|
| 158 |
+
</article>""" for r in p["roadmap"])
|
| 159 |
+
d = p["doctrine_lock"]
|
| 160 |
+
return f"""<!doctype html>
|
| 161 |
+
<html lang="en"><head><meta charset="utf-8">
|
| 162 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
| 163 |
+
<meta name="theme-color" content="#0a0e14"><title>Sovereign Compute — a11oy</title>
|
| 164 |
+
<style>
|
| 165 |
+
:root{{color-scheme:dark}} *{{box-sizing:border-box}}
|
| 166 |
+
body{{margin:0;background:#0a0e14;color:#e6edf3;font:16px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
|
| 167 |
+
padding:max(16px,env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom))}}
|
| 168 |
+
header{{max-width:880px;margin:0 auto 18px}}
|
| 169 |
+
h1{{font-size:clamp(1.4rem,5vw,2rem);margin:0 0 6px}}
|
| 170 |
+
.summary{{font-weight:700;font-size:1.05rem;color:#42d392;margin:0 0 4px}}
|
| 171 |
+
.sub{{color:#9aa7b4;font-size:.85rem}}
|
| 172 |
+
.grid{{max-width:880px;margin:0 auto;display:grid;gap:14px;grid-template-columns:1fr}}
|
| 173 |
+
@media(min-width:720px){{.grid{{grid-template-columns:1fr 1fr}}}}
|
| 174 |
+
.card{{background:#111722;border:1px solid #1e2a3a;border-radius:14px;padding:15px}}
|
| 175 |
+
.card.road{{opacity:.78}}
|
| 176 |
+
.row{{display:flex;align-items:center;justify-content:space-between;gap:10px}}
|
| 177 |
+
h3{{font-size:1rem;margin:0}}
|
| 178 |
+
.tier{{font:600 .68rem/1 ui-monospace,monospace;letter-spacing:.05em;border:1px solid;border-radius:999px;padding:4px 9px;white-space:nowrap}}
|
| 179 |
+
.what{{color:#c4cdd6;font-size:.88rem;margin:9px 0 4px}}
|
| 180 |
+
.meta{{color:#6b7785;font-size:.76rem;font-family:ui-monospace,monospace;margin:0;word-break:break-word}}
|
| 181 |
+
footer{{max-width:880px;margin:22px auto 0;color:#6b7785;font-size:.76rem}}
|
| 182 |
+
.lock{{font-family:ui-monospace,monospace;color:#9aa7b4}}
|
| 183 |
+
</style></head><body>
|
| 184 |
+
<header>
|
| 185 |
+
<h1>Sovereign Compute</h1>
|
| 186 |
+
<p class="summary">{p['summary']}</p>
|
| 187 |
+
<p class="sub">Live loopback probe of the running app. Each tier is read, never asserted.</p>
|
| 188 |
+
</header>
|
| 189 |
+
<main class="grid">{caps}{road}</main>
|
| 190 |
+
<footer>
|
| 191 |
+
<p class="lock">Doctrine {d['version']} LOCKED · locked-proven={d['locked_count']} {{{', '.join(d['locked_proven'])}}} ·
|
| 192 |
+
{d['corpus']} @ {d['kernel_commit']} · Λ = {d['lambda'].split('(')[0].strip()} (NOT a theorem) · {d['slsa'].split('(')[0].strip()}</p>
|
| 193 |
+
<p>LIVE-SOVEREIGN = our own GPU answered · LIVE-MANAGED = managed router · HONEST-STUB = up, no live model · ROADMAP = declared, not faked.</p>
|
| 194 |
+
</footer></body></html>"""
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def register(app, ns: str = "a11oy") -> dict:
|
| 198 |
+
from fastapi.responses import HTMLResponse, JSONResponse
|
| 199 |
+
|
| 200 |
+
@app.get(f"/api/{ns}/v1/sovereign-compute")
|
| 201 |
+
async def _sc_json(): # noqa: ANN202
|
| 202 |
+
return JSONResponse(_posture(ns))
|
| 203 |
+
|
| 204 |
+
@app.get("/sovereign-compute", response_class=HTMLResponse)
|
| 205 |
+
async def _sc_panel(): # noqa: ANN202
|
| 206 |
+
return HTMLResponse(_html(_posture(ns)))
|
| 207 |
+
|
| 208 |
+
return {"ok": True, "ns": ns,
|
| 209 |
+
"routes": [f"/api/{ns}/v1/sovereign-compute", "/sovereign-compute"]}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
if __name__ == "__main__":
|
| 213 |
+
import sys
|
| 214 |
+
p = _posture("a11oy")
|
| 215 |
+
print(f"[sovereign-compute] summary={p['summary']} caps={[c['tier'] for c in p['capabilities']]} "
|
| 216 |
+
f"html_bytes={len(_html(p))}", file=sys.stderr)
|