betterwithage commited on
Commit
5384703
·
verified ·
1 Parent(s): aa558a5

chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)

Browse files

Automated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): routers/series_a_control_plane.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.

Files changed (1) hide show
  1. routers/series_a_control_plane.py +16 -1
routers/series_a_control_plane.py CHANGED
@@ -783,6 +783,8 @@ class Service:
783
  latest = self.store.latest_snapshot()
784
  if latest is None:
785
  return ["FRESH_SERVER_EVIDENCE_REQUIRED"]
 
 
786
  try:
787
  valid_until = datetime.fromisoformat(latest["valid_until"].replace("Z", "+00:00"))
788
  except (TypeError, ValueError):
@@ -1052,6 +1054,19 @@ def _asset(name: str) -> str:
1052
  return path.read_text(encoding="utf-8")
1053
 
1054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1055
  def register(app: FastAPI, ns: str = "a11oy", *, db_path: str | None = None) -> dict[str, Any]:
1056
  if any(getattr(route, "path", None) == f"/api/{ns}/v1/series-a/status" for route in app.router.routes):
1057
  return {"ok": True, "state": "ALREADY_REGISTERED", "routes": []}
@@ -1136,7 +1151,7 @@ def register(app: FastAPI, ns: str = "a11oy", *, db_path: str | None = None) ->
1136
  return Response(service.signer.public_pem, media_type="text/plain", headers={"cache-control": "public,max-age=300"})
1137
 
1138
  async def events(request: Request) -> StreamingResponse:
1139
- last = int(request.query_params.get("after", "0") or 0)
1140
 
1141
  async def generate() -> AsyncIterator[bytes]:
1142
  cursor = max(0, last)
 
783
  latest = self.store.latest_snapshot()
784
  if latest is None:
785
  return ["FRESH_SERVER_EVIDENCE_REQUIRED"]
786
+ if latest.get("manifest", {}).get("status") != "OBSERVED":
787
+ return ["OBSERVED_SERVER_EVIDENCE_REQUIRED"]
788
  try:
789
  valid_until = datetime.fromisoformat(latest["valid_until"].replace("Z", "+00:00"))
790
  except (TypeError, ValueError):
 
1054
  return path.read_text(encoding="utf-8")
1055
 
1056
 
1057
+ def _event_cursor(request: Request) -> int:
1058
+ raw = request.headers.get("last-event-id")
1059
+ if raw is None:
1060
+ raw = request.query_params.get("after", "0")
1061
+ try:
1062
+ cursor = int(raw or 0)
1063
+ except (TypeError, ValueError) as exc:
1064
+ raise HTTPException(status_code=400, detail="event cursor must be an integer") from exc
1065
+ if cursor < 0 or cursor > 9_223_372_036_854_775_807:
1066
+ raise HTTPException(status_code=400, detail="event cursor is outside the supported range")
1067
+ return cursor
1068
+
1069
+
1070
  def register(app: FastAPI, ns: str = "a11oy", *, db_path: str | None = None) -> dict[str, Any]:
1071
  if any(getattr(route, "path", None) == f"/api/{ns}/v1/series-a/status" for route in app.router.routes):
1072
  return {"ok": True, "state": "ALREADY_REGISTERED", "routes": []}
 
1151
  return Response(service.signer.public_pem, media_type="text/plain", headers={"cache-control": "public,max-age=300"})
1152
 
1153
  async def events(request: Request) -> StreamingResponse:
1154
+ last = _event_cursor(request)
1155
 
1156
  async def generate() -> AsyncIterator[bytes]:
1157
  cursor = max(0, last)