Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Deploy AIOS web (React glide grid + FastAPI slice)
Browse files
api/routes_automation.py
CHANGED
|
@@ -5,11 +5,9 @@ cron, a URL the SSRF rail refuses, a key field that is not one of the mapped col
|
|
| 5 |
in `automation_engine`, which is a pure-ish module a gate can drive without a server. This file
|
| 6 |
does auth, shape and status codes.
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
rather than admitting everyone. A "no token configured means no check" default is how an internal
|
| 12 |
-
trigger becomes a public one — the same class of mistake as an empty-200 permission answer.
|
| 13 |
"""
|
| 14 |
import os
|
| 15 |
import re
|
|
@@ -1878,10 +1876,10 @@ def run_rows(auto_id: str, session: Session = Depends(_GATE)):
|
|
| 1878 |
# The loop also SLEEPS FIRST (`engine.scheduler_loop`) — defence in depth, proven in
|
| 1879 |
# verify_automation.py section T rather than assumed.
|
| 1880 |
#
|
| 1881 |
-
#
|
| 1882 |
-
#
|
| 1883 |
-
#
|
| 1884 |
-
engine.start_scheduler()
|
| 1885 |
|
| 1886 |
# C3 (wave 22): register the trigger listener onto the platform's row-event seam. THIS module
|
| 1887 |
# is where the registration belongs — it is the one place that already imports both sides, so
|
|
|
|
| 5 |
in `automation_engine`, which is a pure-ish module a gate can drive without a server. This file
|
| 6 |
does auth, shape and status codes.
|
| 7 |
|
| 8 |
+
The former unauthenticated tick endpoint is permanently retired and returns HTTP 410. Production
|
| 9 |
+
definitions now reconcile exact native schedules through `automation_control`; direct events start
|
| 10 |
+
one finite worker immediately. No shared tick secret or polling clock remains.
|
|
|
|
|
|
|
| 11 |
"""
|
| 12 |
import os
|
| 13 |
import re
|
|
|
|
| 1876 |
# The loop also SLEEPS FIRST (`engine.scheduler_loop`) — defence in depth, proven in
|
| 1877 |
# verify_automation.py section T rather than assumed.
|
| 1878 |
#
|
| 1879 |
+
# Production Pg refuses this resident path even if `AIOS_AUTOMATIONS` drifts on. Exact AWS
|
| 1880 |
+
# schedules and direct dispatch use `automation_control`; this call survives only for isolated
|
| 1881 |
+
# local/HF development fixtures that explicitly opt in.
|
| 1882 |
+
engine.start_scheduler()
|
| 1883 |
|
| 1884 |
# C3 (wave 22): register the trigger listener onto the platform's row-event seam. THIS module
|
| 1885 |
# is where the registration belongs — it is the one place that already imports both sides, so
|
api/routes_platform_admin.py
CHANGED
|
@@ -251,15 +251,18 @@ def _connector_rows(slug, rt):
|
|
| 251 |
|
| 252 |
# ══════════════════════════════════════════════════════════════════════════ automations + cost
|
| 253 |
|
| 254 |
-
#:
|
| 255 |
-
#:
|
| 256 |
-
#:
|
| 257 |
-
#:
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
| 263 |
DAYS_PER_MONTH = 30.4
|
| 264 |
|
| 265 |
|
|
@@ -299,6 +302,7 @@ def _runs_per_day(cron):
|
|
| 299 |
def _automation_rows(slug, rt):
|
| 300 |
"""A tenant's automations, their schedules, and their retained run history."""
|
| 301 |
try:
|
|
|
|
| 302 |
import automation_engine as engine
|
| 303 |
defs = engine.all_definitions(rt) or {}
|
| 304 |
max_runs = int(getattr(engine, "MAX_RUNS", 20))
|
|
@@ -309,18 +313,33 @@ def _automation_rows(slug, rt):
|
|
| 309 |
if not isinstance(d, dict):
|
| 310 |
continue
|
| 311 |
sched = d.get("schedule") or {}
|
|
|
|
| 312 |
status = d.get("status") or {}
|
| 313 |
runs = list(d.get("runs") or [])
|
| 314 |
cron = sched.get("cron") or ""
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
rows.append({
|
| 317 |
"tenant": slug,
|
| 318 |
"id": auto_id,
|
| 319 |
"name": d.get("name") or auto_id,
|
| 320 |
"kind": d.get("kind") or "",
|
| 321 |
-
"enabled": bool(
|
| 322 |
"cron": cron,
|
| 323 |
"runsPerDay": round(per_day, 2) if per_day is not None else None,
|
|
|
|
|
|
|
| 324 |
"state": status.get("state") or "idle",
|
| 325 |
"lastRunAt": status.get("lastRunAt") or "",
|
| 326 |
"lastSummary": status.get("lastSummary") or "",
|
|
@@ -334,40 +353,34 @@ def _automation_rows(slug, rt):
|
|
| 334 |
|
| 335 |
|
| 336 |
def _automation_cost(auto_rows):
|
| 337 |
-
"""
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
CADENCE alone — the fleet below adds work inside the API container, which is already paid for.
|
| 344 |
-
|
| 345 |
-
WHAT IS NOT COMPUTED HERE, deliberately: Lambda GB-seconds. That needs the real average
|
| 346 |
-
duration of the function, which only CloudWatch knows; assuming one would be inventing the
|
| 347 |
-
larger half of the free-tier calculation. `/aws` reports the measured figure when credentials
|
| 348 |
-
are available, and this block says so rather than filling the gap with a plausible number.
|
| 349 |
"""
|
| 350 |
-
invocations = TICK_PER_DAY * DAYS_PER_MONTH
|
| 351 |
fleet_runs = sum(r["runsPerDay"] or 0 for r in auto_rows if r.get("enabled"))
|
| 352 |
unknown_cadence = sum(1 for r in auto_rows if r.get("enabled") and r.get("runsPerDay") is None)
|
|
|
|
|
|
|
|
|
|
| 353 |
return {
|
| 354 |
-
"
|
|
|
|
|
|
|
| 355 |
"invocationsPerMonth": int(round(invocations)),
|
| 356 |
-
"
|
| 357 |
-
"
|
| 358 |
-
"lambdaMb": LAMBDA_MB,
|
| 359 |
-
"usd": 0.0,
|
| 360 |
"fleetRunsPerDay": round(fleet_runs, 2),
|
| 361 |
"unknownCadence": unknown_cadence,
|
| 362 |
"basis": (
|
| 363 |
-
f"
|
| 364 |
-
f"
|
| 365 |
-
f"
|
| 366 |
-
f"{
|
| 367 |
-
f"
|
| 368 |
-
f"
|
| 369 |
-
f"Compute (GB-seconds) depends on measured durations and is NOT estimated here — "
|
| 370 |
-
f"the AWS report reads the real figure when credentials are available."
|
| 371 |
),
|
| 372 |
}
|
| 373 |
|
|
@@ -581,18 +594,24 @@ def platform_automations(tenant: str = "", session: Session = Depends(padmin_gat
|
|
| 581 |
continue
|
| 582 |
retained = max_runs
|
| 583 |
out += rows
|
| 584 |
-
|
|
|
|
|
|
|
| 585 |
return {"automations": out, "count": len(out),
|
| 586 |
"enabled": sum(1 for a in out if a["enabled"]),
|
| 587 |
"historyRetained": retained,
|
| 588 |
"cost": _automation_cost(out), "errors": errors,
|
| 589 |
-
"tickEnabled":
|
| 590 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
|
| 592 |
|
| 593 |
@router.get("/aws")
|
| 594 |
def platform_aws(days: int = 7, session: Session = Depends(padmin_gate)):
|
| 595 |
-
"""
|
| 596 |
days = max(1, min(int(days or 7), 90))
|
| 597 |
return {"days": days, "report": _aws_report(days)}
|
| 598 |
|
|
|
|
| 251 |
|
| 252 |
# ══════════════════════════════════════════════════════════════════════════ automations + cost
|
| 253 |
|
| 254 |
+
#: 2026-08-21 public us-east-2 Linux/x86 rates for the deployed 0.25-vCPU / 1-GiB task.
|
| 255 |
+
#: This is a recurring-run FLOOR, not an invoice: Linux Fargate has a 60-second minimum and the
|
| 256 |
+
#: task receives one public IPv4 address while it runs. The measured `/aws` report is authoritative.
|
| 257 |
+
#: Sources: https://aws.amazon.com/fargate/pricing/ and https://aws.amazon.com/vpc/pricing/
|
| 258 |
+
FARGATE_VCPU_USD_HOUR = 0.04048
|
| 259 |
+
FARGATE_GB_USD_HOUR = 0.004445
|
| 260 |
+
PUBLIC_IPV4_USD_HOUR = 0.005
|
| 261 |
+
TASK_VCPU = 0.25
|
| 262 |
+
TASK_GB = 1.0
|
| 263 |
+
MIN_BILLED_SECONDS = 60
|
| 264 |
+
MIN_RUN_USD = ((TASK_VCPU * FARGATE_VCPU_USD_HOUR + TASK_GB * FARGATE_GB_USD_HOUR
|
| 265 |
+
+ PUBLIC_IPV4_USD_HOUR) * MIN_BILLED_SECONDS / 3600.0)
|
| 266 |
DAYS_PER_MONTH = 30.4
|
| 267 |
|
| 268 |
|
|
|
|
| 302 |
def _automation_rows(slug, rt):
|
| 303 |
"""A tenant's automations, their schedules, and their retained run history."""
|
| 304 |
try:
|
| 305 |
+
import automation_control as control
|
| 306 |
import automation_engine as engine
|
| 307 |
defs = engine.all_definitions(rt) or {}
|
| 308 |
max_runs = int(getattr(engine, "MAX_RUNS", 20))
|
|
|
|
| 313 |
if not isinstance(d, dict):
|
| 314 |
continue
|
| 315 |
sched = d.get("schedule") or {}
|
| 316 |
+
trigger = d.get("trigger") or {}
|
| 317 |
status = d.get("status") or {}
|
| 318 |
runs = list(d.get("runs") or [])
|
| 319 |
cron = sched.get("cron") or ""
|
| 320 |
+
schedule_per_day = _runs_per_day(cron) if sched.get("enabled") else 0.0
|
| 321 |
+
email_enabled = (trigger.get("key") == "email" and trigger.get("enabled", True)
|
| 322 |
+
and not trigger.get("paused") and trigger.get("configured", True))
|
| 323 |
+
per_day = (None if schedule_per_day is None
|
| 324 |
+
else schedule_per_day + (96.0 if email_enabled else 0.0))
|
| 325 |
+
specs_error = False
|
| 326 |
+
try:
|
| 327 |
+
specs = control.recurring_specs(slug, d)
|
| 328 |
+
except Exception:
|
| 329 |
+
# A stored legacy/custom cron must read as unknown, never as zero cost.
|
| 330 |
+
specs = []
|
| 331 |
+
specs_error = True
|
| 332 |
+
per_day = None
|
| 333 |
rows.append({
|
| 334 |
"tenant": slug,
|
| 335 |
"id": auto_id,
|
| 336 |
"name": d.get("name") or auto_id,
|
| 337 |
"kind": d.get("kind") or "",
|
| 338 |
+
"enabled": bool(specs) or specs_error,
|
| 339 |
"cron": cron,
|
| 340 |
"runsPerDay": round(per_day, 2) if per_day is not None else None,
|
| 341 |
+
"nativeSchedules": None if specs_error else len(specs),
|
| 342 |
+
"scheduleModes": sorted({str(s.get("mode") or "") for s in specs}),
|
| 343 |
"state": status.get("state") or "idle",
|
| 344 |
"lastRunAt": status.get("lastRunAt") or "",
|
| 345 |
"lastSummary": status.get("lastSummary") or "",
|
|
|
|
| 353 |
|
| 354 |
|
| 355 |
def _automation_cost(auto_rows):
|
| 356 |
+
"""Minimum scheduled-run estimate for the exact-schedule, finite-worker architecture.
|
| 357 |
+
|
| 358 |
+
It includes the 60-second Fargate floor plus one temporary public IPv4 allocation. It excludes
|
| 359 |
+
unknown direct/manual events, one-shot vendor collections, Step Functions transitions above
|
| 360 |
+
its free allowance, task runtime beyond 60 seconds, and Neon compute/transfer. `/aws` is the
|
| 361 |
+
measured source of truth; this is only a transparent planning floor.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
"""
|
|
|
|
| 363 |
fleet_runs = sum(r["runsPerDay"] or 0 for r in auto_rows if r.get("enabled"))
|
| 364 |
unknown_cadence = sum(1 for r in auto_rows if r.get("enabled") and r.get("runsPerDay") is None)
|
| 365 |
+
native_schedules = sum(int(r.get("nativeSchedules") or 0) for r in auto_rows)
|
| 366 |
+
invocations = fleet_runs * DAYS_PER_MONTH
|
| 367 |
+
minimum_usd = invocations * MIN_RUN_USD
|
| 368 |
return {
|
| 369 |
+
"mode": "exact-schedules-fargate",
|
| 370 |
+
"cadence": "per automation",
|
| 371 |
+
"nativeSchedules": native_schedules,
|
| 372 |
"invocationsPerMonth": int(round(invocations)),
|
| 373 |
+
"perRunMinimumUsd": round(MIN_RUN_USD, 8),
|
| 374 |
+
"usd": round(minimum_usd, 4),
|
|
|
|
|
|
|
| 375 |
"fleetRunsPerDay": round(fleet_runs, 2),
|
| 376 |
"unknownCadence": unknown_cadence,
|
| 377 |
"basis": (
|
| 378 |
+
f"{native_schedules} exact native schedule(s) imply about "
|
| 379 |
+
f"{int(round(invocations)):,} finite run(s)/month. At the 60-second Fargate plus "
|
| 380 |
+
f"public-IPv4 minimum (${MIN_RUN_USD:.8f}/run), the recurring floor is "
|
| 381 |
+
f"about ${minimum_usd:.4f}/month. There is no resident ECS service. Direct/manual "
|
| 382 |
+
f"runs, one-shot vendor collection, longer tasks, paid Step Functions transitions "
|
| 383 |
+
f"and Neon are excluded; the AWS report shows measured cost."
|
|
|
|
|
|
|
| 384 |
),
|
| 385 |
}
|
| 386 |
|
|
|
|
| 594 |
continue
|
| 595 |
retained = max_runs
|
| 596 |
out += rows
|
| 597 |
+
import automation_control as control
|
| 598 |
+
resident = engine.scheduler_status()
|
| 599 |
+
exact_enabled = control.configured()
|
| 600 |
return {"automations": out, "count": len(out),
|
| 601 |
"enabled": sum(1 for a in out if a["enabled"]),
|
| 602 |
"historyRetained": retained,
|
| 603 |
"cost": _automation_cost(out), "errors": errors,
|
| 604 |
+
"tickEnabled": False,
|
| 605 |
+
"controlEnabled": exact_enabled,
|
| 606 |
+
"executionMode": "exact-aws" if exact_enabled else "local-disabled",
|
| 607 |
+
"scheduler": {"enabled": exact_enabled,
|
| 608 |
+
"source": "exact-aws" if exact_enabled else "",
|
| 609 |
+
"resident": resident}}
|
| 610 |
|
| 611 |
|
| 612 |
@router.get("/aws")
|
| 613 |
def platform_aws(days: int = 7, session: Session = Depends(padmin_gate)):
|
| 614 |
+
"""AWS automation usage, verbatim, or an honest note explaining its absence."""
|
| 615 |
days = max(1, min(int(days or 7), 90))
|
| 616 |
return {"days": days, "report": _aws_report(days)}
|
| 617 |
|
web/src/settings/AdminPane.tsx
CHANGED
|
@@ -200,10 +200,10 @@ export function AdminPane({ user }: { user: { username: string; name: string; ro
|
|
| 200 |
<Total label="People" value={int(ov.totals.users)} />
|
| 201 |
<Total label="Databases" value={int(ov.totals.databases)} />
|
| 202 |
<Total label="Records" value={int(ov.totals.rows)} />
|
| 203 |
-
<Total
|
| 204 |
-
label="Automation
|
| 205 |
-
value={fleet ? `$${fleet.cost.usd.toFixed(2)}` : "—"}
|
| 206 |
-
hint={fleet?.cost.basis}
|
| 207 |
/>
|
| 208 |
</div>
|
| 209 |
{ov.totals.unknownTenants > 0 ? (
|
|
@@ -329,8 +329,9 @@ export function AdminPane({ user }: { user: { username: string; name: string; ro
|
|
| 329 |
table that is deliberately not here. */}
|
| 330 |
<h4 className="padmin-h4">Automation cost</h4>
|
| 331 |
<p className="set-help">
|
| 332 |
-
{fleet.rows.filter((a) => a.enabled).length}
|
| 333 |
-
{fleet.cost.
|
|
|
|
| 334 |
? `, about ${fleet.cost.fleetRunsPerDay} runs a day`
|
| 335 |
: ""}
|
| 336 |
{fleet.cost.unknownCadence
|
|
|
|
| 200 |
<Total label="People" value={int(ov.totals.users)} />
|
| 201 |
<Total label="Databases" value={int(ov.totals.databases)} />
|
| 202 |
<Total label="Records" value={int(ov.totals.rows)} />
|
| 203 |
+
<Total
|
| 204 |
+
label="Automation floor"
|
| 205 |
+
value={fleet ? (fleet.cost.usd === 0 ? "$0.00 idle" : `~$${fleet.cost.usd.toFixed(2)}`) : "—"}
|
| 206 |
+
hint={fleet?.cost.basis}
|
| 207 |
/>
|
| 208 |
</div>
|
| 209 |
{ov.totals.unknownTenants > 0 ? (
|
|
|
|
| 329 |
table that is deliberately not here. */}
|
| 330 |
<h4 className="padmin-h4">Automation cost</h4>
|
| 331 |
<p className="set-help">
|
| 332 |
+
{fleet.rows.filter((a) => a.enabled).length} recurring of {fleet.rows.length}
|
| 333 |
+
{`, ${fleet.cost.nativeSchedules} exact schedule${fleet.cost.nativeSchedules === 1 ? "" : "s"}`}
|
| 334 |
+
{fleet.cost.fleetRunsPerDay
|
| 335 |
? `, about ${fleet.cost.fleetRunsPerDay} runs a day`
|
| 336 |
: ""}
|
| 337 |
{fleet.cost.unknownCadence
|
web/src/settings/platformAdminApi.ts
CHANGED
|
@@ -136,6 +136,8 @@ export interface AutomationRow {
|
|
| 136 |
cron: string;
|
| 137 |
/** null = a cadence the server would not parse; shown as "custom", never as a number. */
|
| 138 |
runsPerDay: number | null;
|
|
|
|
|
|
|
| 139 |
state: string;
|
| 140 |
lastRunAt: string;
|
| 141 |
lastSummary: string;
|
|
@@ -146,11 +148,11 @@ export interface AutomationRow {
|
|
| 146 |
}
|
| 147 |
|
| 148 |
export interface FleetCost {
|
|
|
|
| 149 |
cadence: string;
|
|
|
|
| 150 |
invocationsPerMonth: number;
|
| 151 |
-
|
| 152 |
-
freeSchedulerPct: number;
|
| 153 |
-
lambdaMb: number;
|
| 154 |
usd: number;
|
| 155 |
fleetRunsPerDay: number;
|
| 156 |
unknownCadence: number;
|
|
@@ -214,6 +216,8 @@ export function getAutomations(
|
|
| 214 |
cost: FleetCost;
|
| 215 |
errors: Record<string, string>;
|
| 216 |
tickEnabled: boolean;
|
|
|
|
|
|
|
| 217 |
}>
|
| 218 |
> {
|
| 219 |
return call(`/automations${q(tenant)}`);
|
|
|
|
| 136 |
cron: string;
|
| 137 |
/** null = a cadence the server would not parse; shown as "custom", never as a number. */
|
| 138 |
runsPerDay: number | null;
|
| 139 |
+
nativeSchedules: number | null;
|
| 140 |
+
scheduleModes: string[];
|
| 141 |
state: string;
|
| 142 |
lastRunAt: string;
|
| 143 |
lastSummary: string;
|
|
|
|
| 148 |
}
|
| 149 |
|
| 150 |
export interface FleetCost {
|
| 151 |
+
mode: "exact-schedules-fargate";
|
| 152 |
cadence: string;
|
| 153 |
+
nativeSchedules: number;
|
| 154 |
invocationsPerMonth: number;
|
| 155 |
+
perRunMinimumUsd: number;
|
|
|
|
|
|
|
| 156 |
usd: number;
|
| 157 |
fleetRunsPerDay: number;
|
| 158 |
unknownCadence: number;
|
|
|
|
| 216 |
cost: FleetCost;
|
| 217 |
errors: Record<string, string>;
|
| 218 |
tickEnabled: boolean;
|
| 219 |
+
controlEnabled: boolean;
|
| 220 |
+
executionMode: "exact-aws" | "local-disabled";
|
| 221 |
}>
|
| 222 |
> {
|
| 223 |
return call(`/automations${q(tenant)}`);
|