Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/main.py +8 -3
- api/sync_alerts.py +44 -5
- api/test_odoo_rank_refresh.py +22 -2
- platform/harness/amazon_client.py +9 -1
- platform/harness/amazon_store.py +22 -11
- 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": "4acf74bcc1bb (4acf74bcc1bb)",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v86",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
4acf74bcc1bb (4acf74bcc1bb)
|
api/main.py
CHANGED
|
@@ -1108,7 +1108,7 @@ def _pull_amazon(why, vendor=True):
|
|
| 1108 |
return True
|
| 1109 |
from harness import mirror_store
|
| 1110 |
rep = mirror_store.tracked_sync("amazon", rt, lambda: _amazon.sync(tenant_key, rt=rt, scheduled=True,
|
| 1111 |
-
refresh_loaded=first_load_needed,
|
| 1112 |
log=lambda message: print(f"[aios-api] amazon sync ({why}): {message}")))
|
| 1113 |
_rot.invalidate_sources()
|
| 1114 |
_rot._sources()
|
|
@@ -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"))
|
|
@@ -3257,7 +3257,12 @@ def _store_resync_loop():
|
|
| 3257 |
if _resumed.get("amazon"):
|
| 3258 |
_pull_amazon("boot", False)
|
| 3259 |
else:
|
| 3260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3261 |
_pulls["amazon"] = _t.time()
|
| 3262 |
_resync_memory_write(last_good_pass_at, last_relational_success_at,
|
| 3263 |
last_source_fingerprints, dict(_pulls))
|
|
|
|
| 1108 |
return True
|
| 1109 |
from harness import mirror_store
|
| 1110 |
rep = mirror_store.tracked_sync("amazon", rt, lambda: _amazon.sync(tenant_key, rt=rt, scheduled=True,
|
| 1111 |
+
refresh_loaded=first_load_needed, slot_pass=bool(RESYNC_STATE.get("slotPass")),
|
| 1112 |
log=lambda message: print(f"[aios-api] amazon sync ({why}): {message}")))
|
| 1113 |
_rot.invalidate_sources()
|
| 1114 |
_rot._sources()
|
|
|
|
| 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"))
|
|
|
|
| 3257 |
if _resumed.get("amazon"):
|
| 3258 |
_pull_amazon("boot", False)
|
| 3259 |
else:
|
| 3260 |
+
# The daily slot pass refreshes every Amazon table: a late extra pass yesterday must not defer it.
|
| 3261 |
+
RESYNC_STATE["slotPass"] = _slot_claimed
|
| 3262 |
+
try:
|
| 3263 |
+
_pull_amazon("resync")
|
| 3264 |
+
finally:
|
| 3265 |
+
RESYNC_STATE["slotPass"] = False
|
| 3266 |
_pulls["amazon"] = _t.time()
|
| 3267 |
_resync_memory_write(last_good_pass_at, last_relational_success_at,
|
| 3268 |
last_source_fingerprints, dict(_pulls))
|
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")
|
api/test_odoo_rank_refresh.py
CHANGED
|
@@ -765,7 +765,7 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 765 |
return datetime.fromisoformat(text.replace('Z', '+00:00')).timestamp()
|
| 766 |
|
| 767 |
def run_slot_loop(self, memory, *, boot, max_sleeps, tenant='royal-imports', config=None,
|
| 768 |
-
reports=None, checkpoints=None, take=None):
|
| 769 |
"""Drive the real loop and its real slot resolver on a clock that advances at each wait."""
|
| 770 |
import odoo_relational as rel
|
| 771 |
source = ast.parse(Path(__file__).with_name('main.py').read_text(encoding='utf-8'))
|
|
@@ -779,6 +779,7 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 779 |
and target.id in ('_RESYNC_REBUILD_MAX_AGE_SECONDS', '_RESYNC_ENTITY_TABLE_KEYS')
|
| 780 |
for target in node.targets)]
|
| 781 |
now, events, sleeps = [float(boot)], [], []
|
|
|
|
| 782 |
|
| 783 |
def wait(seconds):
|
| 784 |
sleeps.append(seconds)
|
|
@@ -809,7 +810,9 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 809 |
_capture_resync_source_counts=lambda *_: events.append(('counts', now[0])),
|
| 810 |
_resync_source_fingerprints=lambda *_: {'res_partner': (3, 7)},
|
| 811 |
_pull_meta=lambda *a: events.append(('meta', now[0])) or True,
|
| 812 |
-
_pull_amazon=lambda *a:
|
|
|
|
|
|
|
| 813 |
_rebuild_odoo_relational=lambda *a, **k: events.append(('rebuild', now[0])) or True,
|
| 814 |
_rebuild_meta_relational=lambda *_a, **_k: {},
|
| 815 |
_rebuild_amazon_relational=lambda *_a, **_k: {},
|
|
@@ -818,6 +821,7 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 818 |
# H1: the held candidate's unfinished checkpoints, one answer per read.
|
| 819 |
ns['_odoo_backfill_checkpoints'] = lambda *_: checkpoints.pop(0)
|
| 820 |
nodes = _with_collaborators(source, nodes, ns)
|
|
|
|
| 821 |
exec(compile(ast.Module(body=nodes, type_ignores=[]), 'main.py:slot-loop', 'exec'), ns)
|
| 822 |
runtime = SimpleNamespace(get_runtime=lambda *_: store, tenant_for_store_path=lambda: tenant,
|
| 823 |
known_tenants=lambda: ())
|
|
@@ -989,6 +993,22 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 989 |
boot=self.utc('2026-10-24T02:30:00Z'), max_sleeps=1, take=take)
|
| 990 |
self.assertEqual(held[0], ())
|
| 991 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 992 |
def test_slot_near_and_late(self):
|
| 993 |
"""The quiet window is two hours before the slot; a slot with no good sync 90 min after it is late"""
|
| 994 |
from datetime import datetime, timezone
|
|
|
|
| 765 |
return datetime.fromisoformat(text.replace('Z', '+00:00')).timestamp()
|
| 766 |
|
| 767 |
def run_slot_loop(self, memory, *, boot, max_sleeps, tenant='royal-imports', config=None,
|
| 768 |
+
reports=None, checkpoints=None, take=None, slot_flags=None):
|
| 769 |
"""Drive the real loop and its real slot resolver on a clock that advances at each wait."""
|
| 770 |
import odoo_relational as rel
|
| 771 |
source = ast.parse(Path(__file__).with_name('main.py').read_text(encoding='utf-8'))
|
|
|
|
| 779 |
and target.id in ('_RESYNC_REBUILD_MAX_AGE_SECONDS', '_RESYNC_ENTITY_TABLE_KEYS')
|
| 780 |
for target in node.targets)]
|
| 781 |
now, events, sleeps = [float(boot)], [], []
|
| 782 |
+
state = {}
|
| 783 |
|
| 784 |
def wait(seconds):
|
| 785 |
sleeps.append(seconds)
|
|
|
|
| 810 |
_capture_resync_source_counts=lambda *_: events.append(('counts', now[0])),
|
| 811 |
_resync_source_fingerprints=lambda *_: {'res_partner': (3, 7)},
|
| 812 |
_pull_meta=lambda *a: events.append(('meta', now[0])) or True,
|
| 813 |
+
_pull_amazon=lambda *a: (slot_flags.append((a, state['ns']['RESYNC_STATE'].get('slotPass')))
|
| 814 |
+
if slot_flags is not None else None)
|
| 815 |
+
or events.append(('amazon', now[0]) + a) or True,
|
| 816 |
_rebuild_odoo_relational=lambda *a, **k: events.append(('rebuild', now[0])) or True,
|
| 817 |
_rebuild_meta_relational=lambda *_a, **_k: {},
|
| 818 |
_rebuild_amazon_relational=lambda *_a, **_k: {},
|
|
|
|
| 821 |
# H1: the held candidate's unfinished checkpoints, one answer per read.
|
| 822 |
ns['_odoo_backfill_checkpoints'] = lambda *_: checkpoints.pop(0)
|
| 823 |
nodes = _with_collaborators(source, nodes, ns)
|
| 824 |
+
state['ns'] = ns
|
| 825 |
exec(compile(ast.Module(body=nodes, type_ignores=[]), 'main.py:slot-loop', 'exec'), ns)
|
| 826 |
runtime = SimpleNamespace(get_runtime=lambda *_: store, tenant_for_store_path=lambda: tenant,
|
| 827 |
known_tenants=lambda: ())
|
|
|
|
| 993 |
boot=self.utc('2026-10-24T02:30:00Z'), max_sleeps=1, take=take)
|
| 994 |
self.assertEqual(held[0], ())
|
| 995 |
|
| 996 |
+
def test_the_slot_pass_refreshes_every_amazon_table(self):
|
| 997 |
+
"""Live 10-29: orders pulled at 16:20Z by a late pass were deferred by the next day's 06:00Z slot"""
|
| 998 |
+
last = self.utc('2026-10-23T06:05:00Z')
|
| 999 |
+
flags = []
|
| 1000 |
+
self.run_slot_loop({'passAt': last, 'fullRebuildAt': last, 'fingerprints': {'res_partner': (3, 7)}},
|
| 1001 |
+
boot=self.utc('2026-10-24T02:30:00Z'), max_sleeps=2, slot_flags=flags)
|
| 1002 |
+
resync = [flag for args, flag in flags if args[:1] == ('resync',)]
|
| 1003 |
+
self.assertEqual(resync, [True])
|
| 1004 |
+
self.assertTrue(all(not flag for args, flag in flags if args[:1] != ('resync',)), flags)
|
| 1005 |
+
from harness import amazon_store as az
|
| 1006 |
+
from datetime import datetime, timezone
|
| 1007 |
+
now = datetime(2026, 10, 29, 10, 16, tzinfo=timezone.utc)
|
| 1008 |
+
ticks = {'orders': {'state': 'done', 'updated_at': '2026-10-28T18:20:03+00:00'}}
|
| 1009 |
+
self.assertIn('orders', az.sync_plan(ticks, ['orders'], now=now)['deferred'])
|
| 1010 |
+
self.assertEqual(az.sync_plan(ticks, ['orders'], now=now, slot_pass=True)['tables'], ['orders'])
|
| 1011 |
+
|
| 1012 |
def test_slot_near_and_late(self):
|
| 1013 |
"""The quiet window is two hours before the slot; a slot with no good sync 90 min after it is late"""
|
| 1014 |
from datetime import datetime, timezone
|
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
|
@@ -464,9 +464,12 @@ SCHEDULED_FLOOR_SECONDS = 86400
|
|
| 464 |
SCHEDULED_FLOOR_GRACE_SECONDS = 2 * 3600
|
| 465 |
|
| 466 |
|
| 467 |
-
def sync_plan(states, tables=None, *, now=None):
|
| 468 |
"""Pure cadence decision: EVERY due table, oldest first, with no stagger sleep.
|
| 469 |
|
|
|
|
|
|
|
|
|
|
| 470 |
Attempt markers survive in the tenant's saved mirror. Failed tables rotate behind peers.
|
| 471 |
Settlement LIST discovery runs separately on every resync and consumes no report slot.
|
| 472 |
The client still owns pacing/retries within a table.
|
|
@@ -481,7 +484,7 @@ def sync_plan(states, tables=None, *, now=None):
|
|
| 481 |
if state and table != "settlements"}
|
| 482 |
deferred = {}
|
| 483 |
due = []
|
| 484 |
-
floor = SCHEDULED_FLOOR_SECONDS - SCHEDULED_FLOOR_GRACE_SECONDS
|
| 485 |
for table in want:
|
| 486 |
if table == "settlements":
|
| 487 |
continue
|
|
@@ -5218,7 +5221,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 +5239,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 +5249,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 |
|
|
@@ -5813,7 +5821,8 @@ def _totals_match(expected, actual):
|
|
| 5813 |
|
| 5814 |
|
| 5815 |
def sync(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None,
|
| 5816 |
-
max_wait=900, *, scheduled=False, first_load=False, report_budget=None, refresh_loaded=False
|
|
|
|
| 5817 |
"""Publish a whole Amazon source after its requested work completes."""
|
| 5818 |
rt = rt if rt is not None else _runtime_for(tenant_key)
|
| 5819 |
entries = account_entries(tenant_key, rt)
|
|
@@ -5833,7 +5842,7 @@ def sync(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None
|
|
| 5833 |
tables = None if tables is None else list(tables)
|
| 5834 |
options = dict(tables=tables, since=since, log=log, rt=rt, max_wait=max_wait,
|
| 5835 |
scheduled=scheduled, first_load=first_load, report_budget=report_budget,
|
| 5836 |
-
refresh_loaded=refresh_loaded)
|
| 5837 |
if getattr(datastore._SYNC_TLS, "candidate", None) is not None:
|
| 5838 |
return _sync_accounts_candidate(tenant_key, **options)
|
| 5839 |
report = {}
|
|
@@ -5976,7 +5985,8 @@ def _completed_account_tables(con, result, tables):
|
|
| 5976 |
|
| 5977 |
|
| 5978 |
def _sync_accounts_candidate(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None,
|
| 5979 |
-
max_wait=900, *, scheduled=False, first_load=False, report_budget=None, refresh_loaded=False
|
|
|
|
| 5980 |
"""Attempt every admitted account before publishing one combined source."""
|
| 5981 |
rt = rt if rt is not None else _runtime_for(tenant_key)
|
| 5982 |
entries = account_entries(tenant_key, rt)
|
|
@@ -5993,7 +6003,7 @@ def _sync_accounts_candidate(tenant_key="royal-imports", tables=None, since=None
|
|
| 5993 |
_sync_credential(tenant_key, rt, connection_id=cid)
|
| 5994 |
result = _sync_candidate(tenant_key, tables=tables, since=since, log=log, rt=rt,
|
| 5995 |
max_wait=max_wait, scheduled=scheduled, first_load=first_load,
|
| 5996 |
-
report_budget=report_budget, refresh_loaded=refresh_loaded)
|
| 5997 |
if first_load:
|
| 5998 |
_completed_account_tables(scope["root"], result, tables)
|
| 5999 |
_refuse_unreconciled(tenant_key, rt, result, log)
|
|
@@ -6045,7 +6055,8 @@ def _sync_accounts_candidate(tenant_key="royal-imports", tables=None, since=None
|
|
| 6045 |
|
| 6046 |
|
| 6047 |
def _sync_candidate(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None,
|
| 6048 |
-
max_wait=900, *, scheduled=False, first_load=False, report_budget=None, refresh_loaded=False
|
|
|
|
| 6049 |
"""Pull into private progress; refresh loaded tables before bounded history and waits."""
|
| 6050 |
rt = rt if rt is not None else _runtime_for(tenant_key)
|
| 6051 |
fields = _sync_credential(tenant_key, rt)
|
|
@@ -6107,7 +6118,7 @@ def _sync_candidate(tenant_key="royal-imports", tables=None, since=None, log=pri
|
|
| 6107 |
# Refreshes use their own floors; the history partition retains its bounded budget.
|
| 6108 |
con.close()
|
| 6109 |
refreshed = _sync_candidate(tenant_key, tables=loaded, log=log, rt=rt, max_wait=max_wait,
|
| 6110 |
-
scheduled=scheduled, refresh_loaded=True)
|
| 6111 |
report["tables"].update(refreshed.get("tables") or {})
|
| 6112 |
for key in ("problems", "audit_problems"):
|
| 6113 |
report[key].extend(refreshed.get(key) or [])
|
|
@@ -6153,7 +6164,7 @@ def _sync_candidate(tenant_key="royal-imports", tables=None, since=None, log=pri
|
|
| 6153 |
if (tick and tick["state"] == "done" and queued_resync(con, table) is not None
|
| 6154 |
and read_watermark(con, table) and not _interval_reason(table, tick, end)):
|
| 6155 |
ticks[table] = {**tick, "state": "resync"}
|
| 6156 |
-
plan = sync_plan(ticks, want, now=end)
|
| 6157 |
want = plan["tables"]
|
| 6158 |
for table, reason in plan["deferred"].items():
|
| 6159 |
report["tables"][table] = {"state": "deferred", "reason": reason,
|
|
|
|
| 464 |
SCHEDULED_FLOOR_GRACE_SECONDS = 2 * 3600
|
| 465 |
|
| 466 |
|
| 467 |
+
def sync_plan(states, tables=None, *, now=None, slot_pass=False):
|
| 468 |
"""Pure cadence decision: EVERY due table, oldest first, with no stagger sleep.
|
| 469 |
|
| 470 |
+
`slot_pass` is the tenant's daily slot pass: it IS the once-a-day sync, so only Amazon's own
|
| 471 |
+
report floors defer a table. Any other scheduled pass keeps the daily floor.
|
| 472 |
+
|
| 473 |
Attempt markers survive in the tenant's saved mirror. Failed tables rotate behind peers.
|
| 474 |
Settlement LIST discovery runs separately on every resync and consumes no report slot.
|
| 475 |
The client still owns pacing/retries within a table.
|
|
|
|
| 484 |
if state and table != "settlements"}
|
| 485 |
deferred = {}
|
| 486 |
due = []
|
| 487 |
+
floor = 0 if slot_pass else SCHEDULED_FLOOR_SECONDS - SCHEDULED_FLOOR_GRACE_SECONDS
|
| 488 |
for table in want:
|
| 489 |
if table == "settlements":
|
| 490 |
continue
|
|
|
|
| 5221 |
columns = _columns_of(con, "amzn_listing_items")
|
| 5222 |
if not {"sku", "offers", "fulfillment_availability"} <= columns:
|
| 5223 |
raise ValueError("Fee estimates need listing offer prices and fulfillment methods. Sync Amazon listing status and issues first.")
|
| 5224 |
+
requests, unpriced = {}, 0
|
| 5225 |
for sku, raw_offers, raw_fulfillment in con.execute(
|
| 5226 |
"SELECT sku, offers, fulfillment_availability FROM amzn_listing_items").fetchall():
|
| 5227 |
offers = json.loads(raw_offers or "[]")
|
|
|
|
| 5239 |
raise ValueError(f"Amazon listing SKU {sku} has no supported fulfillment method for fee estimates")
|
| 5240 |
priced = [offer for offer in offers if offer.get("marketplaceId") == marketplace]
|
| 5241 |
if not methods or not priced:
|
| 5242 |
+
# An inactive listing has no price here, so Amazon has no fee to estimate for it.
|
| 5243 |
+
unpriced += 1
|
| 5244 |
+
continue
|
| 5245 |
for offer in priced:
|
| 5246 |
price = offer.get("price") or {}
|
| 5247 |
for fulfilled in sorted(methods):
|
|
|
|
| 5249 |
"CurrencyCode": price.get("currencyCode")}, "is_amazon_fulfilled": fulfilled}
|
| 5250 |
identity = cx.fee_estimate_request(estimate, marketplace)["FeesEstimateRequest"]["Identifier"]
|
| 5251 |
requests[identity] = estimate
|
| 5252 |
+
if unpriced and not requests:
|
| 5253 |
+
raise ValueError(f"No Amazon listing has a price or fulfillment method for this marketplace "
|
| 5254 |
+
f"({unpriced} listings). No partial fee snapshot was stored.")
|
| 5255 |
return list(requests.values())
|
| 5256 |
|
| 5257 |
|
|
|
|
| 5821 |
|
| 5822 |
|
| 5823 |
def sync(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None,
|
| 5824 |
+
max_wait=900, *, scheduled=False, first_load=False, report_budget=None, refresh_loaded=False,
|
| 5825 |
+
slot_pass=False):
|
| 5826 |
"""Publish a whole Amazon source after its requested work completes."""
|
| 5827 |
rt = rt if rt is not None else _runtime_for(tenant_key)
|
| 5828 |
entries = account_entries(tenant_key, rt)
|
|
|
|
| 5842 |
tables = None if tables is None else list(tables)
|
| 5843 |
options = dict(tables=tables, since=since, log=log, rt=rt, max_wait=max_wait,
|
| 5844 |
scheduled=scheduled, first_load=first_load, report_budget=report_budget,
|
| 5845 |
+
refresh_loaded=refresh_loaded, slot_pass=slot_pass)
|
| 5846 |
if getattr(datastore._SYNC_TLS, "candidate", None) is not None:
|
| 5847 |
return _sync_accounts_candidate(tenant_key, **options)
|
| 5848 |
report = {}
|
|
|
|
| 5985 |
|
| 5986 |
|
| 5987 |
def _sync_accounts_candidate(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None,
|
| 5988 |
+
max_wait=900, *, scheduled=False, first_load=False, report_budget=None, refresh_loaded=False,
|
| 5989 |
+
slot_pass=False):
|
| 5990 |
"""Attempt every admitted account before publishing one combined source."""
|
| 5991 |
rt = rt if rt is not None else _runtime_for(tenant_key)
|
| 5992 |
entries = account_entries(tenant_key, rt)
|
|
|
|
| 6003 |
_sync_credential(tenant_key, rt, connection_id=cid)
|
| 6004 |
result = _sync_candidate(tenant_key, tables=tables, since=since, log=log, rt=rt,
|
| 6005 |
max_wait=max_wait, scheduled=scheduled, first_load=first_load,
|
| 6006 |
+
report_budget=report_budget, refresh_loaded=refresh_loaded, slot_pass=slot_pass)
|
| 6007 |
if first_load:
|
| 6008 |
_completed_account_tables(scope["root"], result, tables)
|
| 6009 |
_refuse_unreconciled(tenant_key, rt, result, log)
|
|
|
|
| 6055 |
|
| 6056 |
|
| 6057 |
def _sync_candidate(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None,
|
| 6058 |
+
max_wait=900, *, scheduled=False, first_load=False, report_budget=None, refresh_loaded=False,
|
| 6059 |
+
slot_pass=False):
|
| 6060 |
"""Pull into private progress; refresh loaded tables before bounded history and waits."""
|
| 6061 |
rt = rt if rt is not None else _runtime_for(tenant_key)
|
| 6062 |
fields = _sync_credential(tenant_key, rt)
|
|
|
|
| 6118 |
# Refreshes use their own floors; the history partition retains its bounded budget.
|
| 6119 |
con.close()
|
| 6120 |
refreshed = _sync_candidate(tenant_key, tables=loaded, log=log, rt=rt, max_wait=max_wait,
|
| 6121 |
+
scheduled=scheduled, refresh_loaded=True, slot_pass=slot_pass)
|
| 6122 |
report["tables"].update(refreshed.get("tables") or {})
|
| 6123 |
for key in ("problems", "audit_problems"):
|
| 6124 |
report[key].extend(refreshed.get(key) or [])
|
|
|
|
| 6164 |
if (tick and tick["state"] == "done" and queued_resync(con, table) is not None
|
| 6165 |
and read_watermark(con, table) and not _interval_reason(table, tick, end)):
|
| 6166 |
ticks[table] = {**tick, "state": "resync"}
|
| 6167 |
+
plan = sync_plan(ticks, want, now=end, slot_pass=slot_pass)
|
| 6168 |
want = plan["tables"]
|
| 6169 |
for table, reason in plan["deferred"].items():
|
| 6170 |
report["tables"][table] = {"state": "deferred", "reason": reason,
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
cb34dadae3c566048dd3097218bb3af990a15405fef324c0a02fccf2dca23551
|