Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/main.py +1 -1
- api/sync_alerts.py +44 -5
- platform/harness/amazon_client.py +9 -1
- platform/harness/amazon_store.py +7 -2
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v86",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "2494cba9ad86",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v86",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
2494cba9ad86
|
api/main.py
CHANGED
|
@@ -1121,7 +1121,7 @@ def _pull_amazon(why, vendor=True):
|
|
| 1121 |
try:
|
| 1122 |
import sync_alerts as _sa
|
| 1123 |
_sa.notify(tenant_key, "amazon", _sa.amazon_failures(rep), observed=_sa.amazon_observed(rep),
|
| 1124 |
-
store=rt)
|
| 1125 |
except Exception: # noqa: BLE001
|
| 1126 |
pass
|
| 1127 |
return not bool(rep.get("problems"))
|
|
|
|
| 1121 |
try:
|
| 1122 |
import sync_alerts as _sa
|
| 1123 |
_sa.notify(tenant_key, "amazon", _sa.amazon_failures(rep), observed=_sa.amazon_observed(rep),
|
| 1124 |
+
store=rt, quiet=_sa.amazon_standing(rep))
|
| 1125 |
except Exception: # noqa: BLE001
|
| 1126 |
pass
|
| 1127 |
return not bool(rep.get("problems"))
|
api/sync_alerts.py
CHANGED
|
@@ -20,6 +20,13 @@ _OK_CAP = 200
|
|
| 20 |
AMAZON_FAILED = frozenset({"refused", "failed", "error"})
|
| 21 |
AMAZON_GOOD = frozenset({"done"})
|
| 22 |
SYNC_KEY = "sync"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def utc_now():
|
|
@@ -150,7 +157,11 @@ def amazon_failures(report):
|
|
| 150 |
if state in AMAZON_FAILED:
|
| 151 |
covered.add(str(table))
|
| 152 |
# `reason` is the plain sentence; `diagnostic` carries raw exception text.
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
for problem in report.get("problems") or []:
|
| 155 |
text = str(problem)
|
| 156 |
head = re.match(r"([A-Za-z0-9_]+):\s", text)
|
|
@@ -158,13 +169,22 @@ def amazon_failures(report):
|
|
| 158 |
if name in covered:
|
| 159 |
continue
|
| 160 |
if name in tables:
|
| 161 |
-
|
|
|
|
| 162 |
else:
|
| 163 |
add(SYNC_KEY, "Amazon sync", "problem", text)
|
| 164 |
return [{"key": e["key"], "label": e["label"], "code": e["code"],
|
| 165 |
"cause": scrub(" / ".join(e["causes"]) or e["code"])} for e in merged.values()]
|
| 166 |
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
def amazon_observed(report):
|
| 169 |
"""The keys this Amazon pass proved healthy or failing; any other key keeps its alert."""
|
| 170 |
report = report if isinstance(report, dict) else {}
|
|
@@ -190,14 +210,18 @@ def _scope(tenant, connector):
|
|
| 190 |
def _due(alert, now):
|
| 191 |
"""The dedupe rule: what one alert needs this pass, or None."""
|
| 192 |
if not alert.get("sent_at"):
|
|
|
|
|
|
|
| 193 |
return "failed"
|
|
|
|
|
|
|
| 194 |
last = _parse(alert.get("reminded_at") or alert.get("sent_at"))
|
| 195 |
if last is None or now - last >= REMIND_AFTER:
|
| 196 |
return "reminder"
|
| 197 |
return None
|
| 198 |
|
| 199 |
|
| 200 |
-
def _reconcile(document, tenant, connector, current, observed, now, claim):
|
| 201 |
"""Fold this pass into the document; return the plan of what this pass must send."""
|
| 202 |
document = document if isinstance(document, dict) else {}
|
| 203 |
alerts = document.setdefault("alerts", {})
|
|
@@ -210,12 +234,22 @@ def _reconcile(document, tenant, connector, current, observed, now, claim):
|
|
| 210 |
last_full = state.get("last_full") or {}
|
| 211 |
stamp = now.isoformat()
|
| 212 |
failing_keys = {f["key"] for f in current.values()}
|
|
|
|
| 213 |
|
| 214 |
for alert_id, failure in current.items():
|
| 215 |
alert = alerts.get(alert_id)
|
|
|
|
|
|
|
| 216 |
if alert is None and alert_id in recovered:
|
| 217 |
# Failing again before its RECOVERED went out: the owner never heard it cleared.
|
| 218 |
alert = {k: v for k, v in recovered.pop(alert_id).items() if k != "cleared_at"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
if alert is None:
|
| 220 |
last_good = failure["last_good"]
|
| 221 |
if not last_good:
|
|
@@ -233,6 +267,10 @@ def _reconcile(document, tenant, connector, current, observed, now, claim):
|
|
| 233 |
for alert_id in [a for a, v in alerts.items()
|
| 234 |
if v.get("tenant") == tenant and v.get("connector") == connector and a not in current]:
|
| 235 |
key = alerts[alert_id].get("key")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
if observed is not None and key not in observed:
|
| 237 |
continue
|
| 238 |
alert = alerts.pop(alert_id)
|
|
@@ -329,7 +367,7 @@ def _mark(document, tenant, connector, plan, now, claim, delivered):
|
|
| 329 |
|
| 330 |
# ---- entry point ----------------------------------------------------------------------------
|
| 331 |
|
| 332 |
-
def notify(tenant, connector, failures, *, observed=None, now=None, sender=None, store=None):
|
| 333 |
"""Record this pass's failures and send at most one Telegram line; never raises.
|
| 334 |
|
| 335 |
`failures` is the full current list for the tenant and connector; [] means healthy.
|
|
@@ -348,8 +386,9 @@ def notify(tenant, connector, failures, *, observed=None, now=None, sender=None,
|
|
| 348 |
observed = None if observed is None else {str(key) for key in observed}
|
| 349 |
claim = uuid4().hex
|
| 350 |
# Save first, so a delivery marker from a past pass is never re-sent.
|
|
|
|
| 351 |
document = store.update(DOCUMENT, lambda doc: _reconcile(
|
| 352 |
-
doc, tenant, connector, current, observed, now, claim))
|
| 353 |
plan = _plan_of(document or {}, tenant, connector, now, claim)
|
| 354 |
if plan is None or not any(plan.values()):
|
| 355 |
result.update(ok=True, cause=None if plan is not None else "another pass is sending")
|
|
|
|
| 20 |
AMAZON_FAILED = frozenset({"refused", "failed", "error"})
|
| 21 |
AMAZON_GOOD = frozenset({"done"})
|
| 22 |
SYNC_KEY = "sync"
|
| 23 |
+
# Owner 2026-10-29: alert only on real breakage. A report Amazon does not offer this seller never alerts.
|
| 24 |
+
AMAZON_NOT_OFFERED = "Amazon does not offer this report to this seller account"
|
| 25 |
+
AMAZON_ROLE = re.compile(r"has not granted access|access to requested resource is denied", re.I)
|
| 26 |
+
# A missing role is a standing account fact: it alerts once and never reminds.
|
| 27 |
+
ONCE_CODES = frozenset({"role"})
|
| 28 |
+
# A throttle alerts only when it repeats on this many passes in a row.
|
| 29 |
+
REPEAT_CODES = {"throttled": 2}
|
| 30 |
|
| 31 |
|
| 32 |
def utc_now():
|
|
|
|
| 157 |
if state in AMAZON_FAILED:
|
| 158 |
covered.add(str(table))
|
| 159 |
# `reason` is the plain sentence; `diagnostic` carries raw exception text.
|
| 160 |
+
reason = str(row.get("reason") or state)
|
| 161 |
+
if reason.startswith(AMAZON_NOT_OFFERED):
|
| 162 |
+
continue
|
| 163 |
+
code = "role" if AMAZON_ROLE.search(reason + " " + str(row.get("diagnostic") or "")) else state
|
| 164 |
+
add(str(table), str(table), code, reason)
|
| 165 |
for problem in report.get("problems") or []:
|
| 166 |
text = str(problem)
|
| 167 |
head = re.match(r"([A-Za-z0-9_]+):\s", text)
|
|
|
|
| 169 |
if name in covered:
|
| 170 |
continue
|
| 171 |
if name in tables:
|
| 172 |
+
throttled = re.search(r"\bTHROTTLED\b|\b429\b", text)
|
| 173 |
+
add(name, name, "throttled" if throttled else "problem", text[head.end():])
|
| 174 |
else:
|
| 175 |
add(SYNC_KEY, "Amazon sync", "problem", text)
|
| 176 |
return [{"key": e["key"], "label": e["label"], "code": e["code"],
|
| 177 |
"cause": scrub(" / ".join(e["causes"]) or e["code"])} for e in merged.values()]
|
| 178 |
|
| 179 |
|
| 180 |
+
def amazon_standing(report):
|
| 181 |
+
"""The tables Amazon does not offer this seller: their alerts clear without a RECOVERED line."""
|
| 182 |
+
report = report if isinstance(report, dict) else {}
|
| 183 |
+
tables = report.get("tables") if isinstance(report.get("tables"), dict) else {}
|
| 184 |
+
return {str(table) for table, row in tables.items() if isinstance(row, dict)
|
| 185 |
+
and str(row.get("reason") or "").startswith(AMAZON_NOT_OFFERED)}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
def amazon_observed(report):
|
| 189 |
"""The keys this Amazon pass proved healthy or failing; any other key keeps its alert."""
|
| 190 |
report = report if isinstance(report, dict) else {}
|
|
|
|
| 210 |
def _due(alert, now):
|
| 211 |
"""The dedupe rule: what one alert needs this pass, or None."""
|
| 212 |
if not alert.get("sent_at"):
|
| 213 |
+
if int(alert.get("passes") or 1) < REPEAT_CODES.get(alert.get("code"), 1):
|
| 214 |
+
return None
|
| 215 |
return "failed"
|
| 216 |
+
if alert.get("code") in ONCE_CODES:
|
| 217 |
+
return None
|
| 218 |
last = _parse(alert.get("reminded_at") or alert.get("sent_at"))
|
| 219 |
if last is None or now - last >= REMIND_AFTER:
|
| 220 |
return "reminder"
|
| 221 |
return None
|
| 222 |
|
| 223 |
|
| 224 |
+
def _reconcile(document, tenant, connector, current, observed, now, claim, quiet=frozenset()):
|
| 225 |
"""Fold this pass into the document; return the plan of what this pass must send."""
|
| 226 |
document = document if isinstance(document, dict) else {}
|
| 227 |
alerts = document.setdefault("alerts", {})
|
|
|
|
| 234 |
last_full = state.get("last_full") or {}
|
| 235 |
stamp = now.isoformat()
|
| 236 |
failing_keys = {f["key"] for f in current.values()}
|
| 237 |
+
mine = {a: v for a, v in alerts.items() if v.get("tenant") == tenant and v.get("connector") == connector}
|
| 238 |
|
| 239 |
for alert_id, failure in current.items():
|
| 240 |
alert = alerts.get(alert_id)
|
| 241 |
+
if alert is not None:
|
| 242 |
+
alert["passes"] = int(alert.get("passes") or 1) + 1
|
| 243 |
if alert is None and alert_id in recovered:
|
| 244 |
# Failing again before its RECOVERED went out: the owner never heard it cleared.
|
| 245 |
alert = {k: v for k, v in recovered.pop(alert_id).items() if k != "cleared_at"}
|
| 246 |
+
if alert is None:
|
| 247 |
+
# The same key under a new code is the same failure: it keeps what the owner was told.
|
| 248 |
+
prior = next((v for a, v in mine.items() if a not in current and v.get("key") == failure["key"]
|
| 249 |
+
and v.get("sent_at")), None)
|
| 250 |
+
if prior is not None:
|
| 251 |
+
alert = {k: prior.get(k) for k in ("tenant", "connector", "first", "last_good",
|
| 252 |
+
"sent_at", "reminded_at")}
|
| 253 |
if alert is None:
|
| 254 |
last_good = failure["last_good"]
|
| 255 |
if not last_good:
|
|
|
|
| 267 |
for alert_id in [a for a, v in alerts.items()
|
| 268 |
if v.get("tenant") == tenant and v.get("connector") == connector and a not in current]:
|
| 269 |
key = alerts[alert_id].get("key")
|
| 270 |
+
if key in failing_keys or key in quiet:
|
| 271 |
+
# A code change, or a standing account fact: cleared without a RECOVERED line.
|
| 272 |
+
alerts.pop(alert_id)
|
| 273 |
+
continue
|
| 274 |
if observed is not None and key not in observed:
|
| 275 |
continue
|
| 276 |
alert = alerts.pop(alert_id)
|
|
|
|
| 367 |
|
| 368 |
# ---- entry point ----------------------------------------------------------------------------
|
| 369 |
|
| 370 |
+
def notify(tenant, connector, failures, *, observed=None, now=None, sender=None, store=None, quiet=None):
|
| 371 |
"""Record this pass's failures and send at most one Telegram line; never raises.
|
| 372 |
|
| 373 |
`failures` is the full current list for the tenant and connector; [] means healthy.
|
|
|
|
| 386 |
observed = None if observed is None else {str(key) for key in observed}
|
| 387 |
claim = uuid4().hex
|
| 388 |
# Save first, so a delivery marker from a past pass is never re-sent.
|
| 389 |
+
quiet = frozenset(str(key) for key in (quiet or ()))
|
| 390 |
document = store.update(DOCUMENT, lambda doc: _reconcile(
|
| 391 |
+
doc, tenant, connector, current, observed, now, claim, quiet))
|
| 392 |
plan = _plan_of(document or {}, tenant, connector, now, claim)
|
| 393 |
if plan is None or not any(plan.values()):
|
| 394 |
result.update(ok=True, cause=None if plan is not None else "another pass is sending")
|
platform/harness/amazon_client.py
CHANGED
|
@@ -1522,6 +1522,8 @@ ENTITY_INTERVALS = {"getOrderMetrics": 2.0, "getInventorySummaries": 0.5,
|
|
| 1522 |
"searchListingsItems": 0.2, "searchCatalogItems": 0.5,
|
| 1523 |
"getMyFeesEstimates": 2.0}
|
| 1524 |
INBOUND_INTERVALS = {"listInboundPlans": 0.5, "getInboundPlan": 0.5, "listShipmentItems": 0.5}
|
|
|
|
|
|
|
| 1525 |
|
| 1526 |
|
| 1527 |
def _require_replenishment_roles():
|
|
@@ -1752,7 +1754,13 @@ def inbound_shipment_items(fields, *, timeout=_TIMEOUT, sleep=time.sleep, now=ti
|
|
| 1752 |
plans[identifier(plan.get("inboundPlanId"))] = None
|
| 1753 |
for plan_id in plans:
|
| 1754 |
target = path + "/" + plan_id
|
| 1755 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1756 |
if plan.get("inboundPlanId") != plan_id or not isinstance(plan.get("status"), str) or not plan["status"]:
|
| 1757 |
raise AmazonError("getInboundPlan returned an incomplete or mismatched plan; no partial inbound snapshot was stored")
|
| 1758 |
# Unconfirmed plans may omit shipments until a placement option is confirmed.
|
|
|
|
| 1522 |
"searchListingsItems": 0.2, "searchCatalogItems": 0.5,
|
| 1523 |
"getMyFeesEstimates": 2.0}
|
| 1524 |
INBOUND_INTERVALS = {"listInboundPlans": 0.5, "getInboundPlan": 0.5, "listShipmentItems": 0.5}
|
| 1525 |
+
#: Amazon's 400 text for an Amazon Warehousing and Distribution plan in the FBA inbound list.
|
| 1526 |
+
AWD_PLAN_REFUSAL = "not supported for Amazon Warehousing and Distribution inbound plans"
|
| 1527 |
|
| 1528 |
|
| 1529 |
def _require_replenishment_roles():
|
|
|
|
| 1754 |
plans[identifier(plan.get("inboundPlanId"))] = None
|
| 1755 |
for plan_id in plans:
|
| 1756 |
target = path + "/" + plan_id
|
| 1757 |
+
try:
|
| 1758 |
+
plan = read(target, "getInboundPlan", {})
|
| 1759 |
+
except AmazonError as exc:
|
| 1760 |
+
# Amazon lists AWD plans here but answers 400 to getInboundPlan for them: they are not FBA plans.
|
| 1761 |
+
if AWD_PLAN_REFUSAL in str(exc):
|
| 1762 |
+
continue
|
| 1763 |
+
raise
|
| 1764 |
if plan.get("inboundPlanId") != plan_id or not isinstance(plan.get("status"), str) or not plan["status"]:
|
| 1765 |
raise AmazonError("getInboundPlan returned an incomplete or mismatched plan; no partial inbound snapshot was stored")
|
| 1766 |
# Unconfirmed plans may omit shipments until a placement option is confirmed.
|
platform/harness/amazon_store.py
CHANGED
|
@@ -5218,7 +5218,7 @@ def _fee_estimate_inputs(con, fields):
|
|
| 5218 |
columns = _columns_of(con, "amzn_listing_items")
|
| 5219 |
if not {"sku", "offers", "fulfillment_availability"} <= columns:
|
| 5220 |
raise ValueError("Fee estimates need listing offer prices and fulfillment methods. Sync Amazon listing status and issues first.")
|
| 5221 |
-
requests = {}
|
| 5222 |
for sku, raw_offers, raw_fulfillment in con.execute(
|
| 5223 |
"SELECT sku, offers, fulfillment_availability FROM amzn_listing_items").fetchall():
|
| 5224 |
offers = json.loads(raw_offers or "[]")
|
|
@@ -5236,7 +5236,9 @@ def _fee_estimate_inputs(con, fields):
|
|
| 5236 |
raise ValueError(f"Amazon listing SKU {sku} has no supported fulfillment method for fee estimates")
|
| 5237 |
priced = [offer for offer in offers if offer.get("marketplaceId") == marketplace]
|
| 5238 |
if not methods or not priced:
|
| 5239 |
-
|
|
|
|
|
|
|
| 5240 |
for offer in priced:
|
| 5241 |
price = offer.get("price") or {}
|
| 5242 |
for fulfilled in sorted(methods):
|
|
@@ -5244,6 +5246,9 @@ def _fee_estimate_inputs(con, fields):
|
|
| 5244 |
"CurrencyCode": price.get("currencyCode")}, "is_amazon_fulfilled": fulfilled}
|
| 5245 |
identity = cx.fee_estimate_request(estimate, marketplace)["FeesEstimateRequest"]["Identifier"]
|
| 5246 |
requests[identity] = estimate
|
|
|
|
|
|
|
|
|
|
| 5247 |
return list(requests.values())
|
| 5248 |
|
| 5249 |
|
|
|
|
| 5218 |
columns = _columns_of(con, "amzn_listing_items")
|
| 5219 |
if not {"sku", "offers", "fulfillment_availability"} <= columns:
|
| 5220 |
raise ValueError("Fee estimates need listing offer prices and fulfillment methods. Sync Amazon listing status and issues first.")
|
| 5221 |
+
requests, unpriced = {}, 0
|
| 5222 |
for sku, raw_offers, raw_fulfillment in con.execute(
|
| 5223 |
"SELECT sku, offers, fulfillment_availability FROM amzn_listing_items").fetchall():
|
| 5224 |
offers = json.loads(raw_offers or "[]")
|
|
|
|
| 5236 |
raise ValueError(f"Amazon listing SKU {sku} has no supported fulfillment method for fee estimates")
|
| 5237 |
priced = [offer for offer in offers if offer.get("marketplaceId") == marketplace]
|
| 5238 |
if not methods or not priced:
|
| 5239 |
+
# An inactive listing has no price here, so Amazon has no fee to estimate for it.
|
| 5240 |
+
unpriced += 1
|
| 5241 |
+
continue
|
| 5242 |
for offer in priced:
|
| 5243 |
price = offer.get("price") or {}
|
| 5244 |
for fulfilled in sorted(methods):
|
|
|
|
| 5246 |
"CurrencyCode": price.get("currencyCode")}, "is_amazon_fulfilled": fulfilled}
|
| 5247 |
identity = cx.fee_estimate_request(estimate, marketplace)["FeesEstimateRequest"]["Identifier"]
|
| 5248 |
requests[identity] = estimate
|
| 5249 |
+
if unpriced and not requests:
|
| 5250 |
+
raise ValueError(f"No Amazon listing has a price or fulfillment method for this marketplace "
|
| 5251 |
+
f"({unpriced} listings). No partial fee snapshot was stored.")
|
| 5252 |
return list(requests.values())
|
| 5253 |
|
| 5254 |
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
946b8c2a8a9e8c042e17ab6bf158de194d2550330f4de1007ddb7a007c25db59
|