Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/routes_activity.py +72 -23
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v83",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "ba721b3d1f9d",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v83",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
ba721b3d1f9d
|
api/routes_activity.py
CHANGED
|
@@ -3,6 +3,7 @@ import dash_norm
|
|
| 3 |
import json
|
| 4 |
import math
|
| 5 |
import re
|
|
|
|
| 6 |
import time
|
| 7 |
import uuid
|
| 8 |
from urllib.parse import urlsplit
|
|
@@ -258,31 +259,79 @@ def _retained(doc, tenant, now_ms):
|
|
| 258 |
return sorted(retained, key=lambda row: row["endedAt"])[-MAX_SESSIONS:]
|
| 259 |
|
| 260 |
|
| 261 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
from harness import runtime
|
| 263 |
|
| 264 |
-
def
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
# platform/ is available after session resolution, not necessarily at import.
|
| 287 |
try:
|
| 288 |
from harness.telemetry import error as telemetry_error
|
|
|
|
| 3 |
import json
|
| 4 |
import math
|
| 5 |
import re
|
| 6 |
+
import threading
|
| 7 |
import time
|
| 8 |
import uuid
|
| 9 |
from urllib.parse import urlsplit
|
|
|
|
| 259 |
return sorted(retained, key=lambda row: row["endedAt"])[-MAX_SESSIONS:]
|
| 260 |
|
| 261 |
|
| 262 |
+
def _apply(doc, user, tenant, session_id, events, dropped, now_ms):
|
| 263 |
+
"""`doc` with one batch merged into its session row."""
|
| 264 |
+
rows = _retained(doc, tenant, now_ms)
|
| 265 |
+
row = next((item for item in rows if item["sessionId"] == session_id and item["user"] == user), None)
|
| 266 |
+
if row is None:
|
| 267 |
+
row = {"sessionId": session_id, "user": user, "tenant": tenant,
|
| 268 |
+
"startedAt": min(event["ts"] for event in events), "endedAt": now_ms,
|
| 269 |
+
"route": next((event.get("to") or event.get("route") for event in events if event.get("to") or event.get("route")), "/"),
|
| 270 |
+
"events": [], "dropped": 0, "prunedEvents": 0}
|
| 271 |
+
rows.append(row)
|
| 272 |
+
merged = sorted(row["events"] + events, key=lambda event: event["ts"])
|
| 273 |
+
if merged[0]["ts"] < row["startedAt"]:
|
| 274 |
+
row["route"] = merged[0].get("to") or merged[0].get("route") or "/"
|
| 275 |
+
row["startedAt"] = min(row["startedAt"], merged[0]["ts"])
|
| 276 |
+
row["endedAt"] = merged[-1]["ts"]
|
| 277 |
+
row["prunedEvents"] += max(0, len(merged) - MAX_EVENTS_PER_SESSION)
|
| 278 |
+
row["dropped"] += dropped
|
| 279 |
+
row["events"] = merged[-MAX_EVENTS_PER_SESSION:]
|
| 280 |
+
return {"sessions": sorted(rows, key=lambda item: item["endedAt"])[-MAX_SESSIONS:]}
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# ⛔ One write rewrites the whole multi-MB document under a row lock, and the pg store ignores
|
| 284 |
+
# flush="async". Every tab posting every 10 s stalled live reads (2026-10-21), so a tenant writes
|
| 285 |
+
# at most once per COALESCE_S: the first batch after a quiet window writes now, later ones wait here.
|
| 286 |
+
# A container loss drops at most COALESCE_S of buffered telemetry.
|
| 287 |
+
COALESCE_S = 60.0
|
| 288 |
+
_PENDING: dict = {}
|
| 289 |
+
_LAST_WRITE: dict = {}
|
| 290 |
+
_TIMERS: dict = {}
|
| 291 |
+
_COALESCE_LOCK = threading.Lock()
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def _write(tenant, batches):
|
| 295 |
from harness import runtime
|
| 296 |
|
| 297 |
+
def _merge(doc):
|
| 298 |
+
for batch in batches:
|
| 299 |
+
doc = _apply(doc, *batch)
|
| 300 |
+
return doc
|
| 301 |
+
|
| 302 |
+
runtime.get_runtime(tenant).update(BUCKET, _merge, flush="async")
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def _flush_pending(tenant):
|
| 306 |
+
with _COALESCE_LOCK:
|
| 307 |
+
batches = _PENDING.pop(tenant, [])
|
| 308 |
+
_TIMERS.pop(tenant, None)
|
| 309 |
+
_LAST_WRITE[tenant] = time.monotonic()
|
| 310 |
+
if batches:
|
| 311 |
+
try:
|
| 312 |
+
_write(tenant, batches)
|
| 313 |
+
except Exception as exc: # noqa: BLE001
|
| 314 |
+
print(f"[activity] buffered write lost {len(batches)} batch(es) for {tenant}: "
|
| 315 |
+
f"{type(exc).__name__}", flush=True)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def _record(session, session_id, events, dropped, now_ms):
|
| 319 |
+
tenant = str(session.tenant)
|
| 320 |
+
batch = (session.uname, session.tenant, session_id, events, dropped, now_ms)
|
| 321 |
+
with _COALESCE_LOCK:
|
| 322 |
+
wait = COALESCE_S - (time.monotonic() - _LAST_WRITE.get(tenant, -math.inf))
|
| 323 |
+
write_now = wait <= 0 and tenant not in _PENDING
|
| 324 |
+
if write_now:
|
| 325 |
+
_LAST_WRITE[tenant] = time.monotonic()
|
| 326 |
+
else:
|
| 327 |
+
if tenant not in _PENDING:
|
| 328 |
+
timer = threading.Timer(max(wait, 1.0), _flush_pending, args=(tenant,))
|
| 329 |
+
timer.daemon = True
|
| 330 |
+
_TIMERS[tenant] = timer
|
| 331 |
+
timer.start()
|
| 332 |
+
_PENDING.setdefault(tenant, []).append(batch)
|
| 333 |
+
if write_now:
|
| 334 |
+
_write(tenant, [batch])
|
| 335 |
# platform/ is available after session resolution, not necessarily at import.
|
| 336 |
try:
|
| 337 |
from harness.telemetry import error as telemetry_error
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
c5cc8fbb14e6bc53e4d98a5b176dc07a5c9c2a52ad0e425ace43b6896e59dcff
|