fsanyoto commited on
Commit
257feb8
·
verified ·
1 Parent(s): 740ecde

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "be8fb2f",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "e8852c1",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- be8fb2f
 
1
+ e8852c1
api/main.py CHANGED
@@ -792,8 +792,12 @@ def _pull_meta(why):
792
  return False
793
 
794
 
795
- def _pull_amazon(why):
796
- """Produce Amazon rows in this container before projecting them, on the caller's thread."""
 
 
 
 
797
  try:
798
  from harness import amazon_store as _amazon
799
  from harness import runtime as _runtime
@@ -828,6 +832,9 @@ def _pull_amazon(why):
828
  print(f"[aios-api] amazon sync ({why}): first load "
829
  + ("queued on the sync desk" if receipt.get("accepted") else "already queued or running"))
830
  return True
 
 
 
831
  rep = _amazon.sync(tenant_key, rt=rt, scheduled=True,
832
  log=lambda message: print(f"[aios-api] amazon sync ({why}): {message}"))
833
  _rot.invalidate_sources()
@@ -950,6 +957,7 @@ def _run_sync_requests(outcome=None):
950
  provider, tenant = receipt["provider"], receipt["tenant"]
951
  ok, detail = False, ""
952
  first_load_progress, continuing = None, False
 
953
  try:
954
  from harness import runtime, datastore
955
  rt = runtime.get_runtime(tenant)
@@ -1016,6 +1024,9 @@ def _run_sync_requests(outcome=None):
1016
  from connectors_amazon import assert_safe_status
1017
  first_load_progress = assert_safe_status(report.get("firstLoad"))
1018
  continuing = report.get("state") == "partial"
 
 
 
1019
  problems = list(report.get("problems") or []) + list(report.get("audit_problems") or [])
1020
  tables = report.get("tables") or {}
1021
  if not problems and not tables and not continuing:
@@ -1055,7 +1066,19 @@ def _run_sync_requests(outcome=None):
1055
  connector_sync.finish_sync_request(provider, tenant, ok=ok, detail=detail)
1056
  if outcome is not None:
1057
  outcome[provider] = "continuing" if (continuing and ok) else ("done" if ok else "failed")
1058
- if continuing and ok:
 
 
 
 
 
 
 
 
 
 
 
 
1059
  # Finish first: the desk refuses a second in-flight intent. The resident loop claims
1060
  # the continuation as a DESK-ONLY wake; the Odoo pass keeps its own cadence.
1061
  connector_sync.request_sync("amazon_sp", tenant, requested_by="first load")
@@ -1523,7 +1546,11 @@ def _rebuild_odoo_relational(why, previous_meta_fingerprint=None, meta_state_out
1523
 
1524
  # D-780: fetched rows include an idempotent cursor overlap. Only mirror content compared with
1525
  # the last successful apply proves equality; scalar backfills need not move write_date.
1526
- _RESYNC_REBUILD_MAX_AGE_SECONDS = 24 * 60 * 60
 
 
 
 
1527
 
1528
 
1529
  # Dependencies of odoo_relational.plan/read_* and the two read-through table specs. Customers
@@ -1537,6 +1564,12 @@ _RESYNC_ENTITY_TABLE_KEYS = {
1537
  "account_account": ("ut_odoo_accounts",),
1538
  "sale_order_line": ("ut_odoo_order_lines",),
1539
  "account_move_line": ("ut_odoo_gl_lines",),
 
 
 
 
 
 
1540
  }
1541
 
1542
 
@@ -1614,26 +1647,33 @@ def _resync_rebuild_reason(sync_report, delete_report, last_success_at, now,
1614
  return "source-change"
1615
  except (TypeError, ValueError):
1616
  return "sync-unconfirmed"
 
1617
  if delete_report is not None:
1618
  if not isinstance(delete_report, dict):
1619
  return "sync-unconfirmed"
1620
  try:
1621
- if any(int(count or 0) > 0 for count in delete_report.values()):
1622
- return "delete-change"
1623
  except (TypeError, ValueError):
1624
  return "sync-unconfirmed"
 
 
 
 
 
1625
  if current_fingerprints is not None:
1626
  if not isinstance(current_fingerprints, dict) or not current_fingerprints:
1627
  return "fingerprint-unconfirmed"
1628
  if not isinstance(previous_fingerprints, dict) or not previous_fingerprints:
1629
  return "no-fingerprint"
1630
  if last_success_at is None or now - last_success_at >= _RESYNC_REBUILD_MAX_AGE_SECONDS:
1631
- return "daily-recovery"
1632
  if current_fingerprints is not None:
1633
  # Kept inline so the pure decision can still be AST-extracted on its own by old gates.
1634
- changed = sorted(entity for entity in set(previous_fingerprints) | set(current_fingerprints)
1635
- if entity not in previous_fingerprints or entity not in current_fingerprints
1636
- or previous_fingerprints[entity] != current_fingerprints[entity])
 
1637
  if changed:
1638
  return "source-change: " + ",".join(changed)
1639
  return None
@@ -1650,7 +1690,7 @@ def _meta_rebuild_force_reason(pull_confirmed, last_fingerprint, last_applied_at
1650
  if not isinstance(last_fingerprint, str) or not last_fingerprint:
1651
  return "meta-first"
1652
  if last_applied_at is None or now - last_applied_at >= _RESYNC_REBUILD_MAX_AGE_SECONDS:
1653
- return "meta-daily"
1654
  return None
1655
 
1656
 
@@ -1690,8 +1730,10 @@ _RESYNC_NOTICE = [None]
1690
  #: The fail-safe cadence when nothing is readable, and the floor any cadence is clamped to. Both
1691
  #: predate this ticket; they are named here so the env door cannot be a second, softer limit
1692
  #: [[limit-with-no-enforcer]].
1693
- _RESYNC_DEFAULT_SECONDS = 1800
1694
- _RESYNC_FLOOR_SECONDS = 60
 
 
1695
 
1696
 
1697
  def _resync_env_seconds():
@@ -1828,14 +1870,14 @@ def _resync_mirror_pass(manual, passes):
1828
  if manual:
1829
  return None, None, None
1830
  sync_report = _ds.sync_all(log=lambda *a, **k: None)
1831
- delete_report = None
1832
- # Wave 21 — every 4th pass: purge hard-deleted rows the cursor sync cannot see (the boot
1833
- # pass's comment has the measured case). Cheap id-sweep per entity; without it deleted
1834
- # Odoo lines inflate every sum on the mirror FOREVER.
1835
  # ⚠ INSIDE the non-manual branch: a reconcile is a pass over the mirror this loop was
1836
  # just told not to advance.
1837
- if passes % 4 == 0:
1838
- delete_report = _ds.reconcile_deletes(log=lambda *a, **k: None)
 
 
1839
  return sync_report, delete_report, None
1840
  except Exception as e: # noqa: BLE001
1841
  # A partial report must never be mistaken for a confirmed zero-change pass.
@@ -1900,6 +1942,56 @@ def _project_desk(outcome, tenant):
1900
  print(f"[aios-api] sync now projection failed: {type(e).__name__}: {e}")
1901
 
1902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1903
  def _store_resync_loop():
1904
  """Keep the analytical mirror current — the API-process stand-in for the re-sync the
1905
  Streamlit app piggybacks on page renders. Measure memos key on the pool stamp, so a
@@ -1907,8 +1999,16 @@ def _store_resync_loop():
1907
  import time as _t
1908
  from core import connector_sync
1909
  passes = 0
1910
- last_relational_success_at = None
1911
- last_source_fingerprints = None
 
 
 
 
 
 
 
 
1912
  last_meta_fingerprint = None
1913
  last_meta_applied_at = None
1914
  # ⚠ AMAZON KEEPS ITS OWN FINGERPRINT, never sharing Meta's. Two connectors whose plans change
@@ -1917,7 +2017,6 @@ def _store_resync_loop():
1917
  # codebase already names. Unknown is never carried forward as equality evidence.
1918
  last_amzn_fingerprint = None
1919
  last_full_pass_at = _t.time()
1920
- last_pass_was_full = True
1921
  # The least time between two desk-only passes of an Amazon first-load continuation.
1922
  desk_min_spacing_seconds = 30.0
1923
  while True:
@@ -1990,12 +2089,21 @@ def _store_resync_loop():
1990
  # The wait is now interruptible so an administrator's Sync now wakes this writer.
1991
  _woken = False
1992
  if passes:
1993
- # After a full pass the wait is the whole cadence; after a desk-only pass it is what
1994
- # remains of it, so continuations can never postpone the scheduled pass.
 
 
 
1995
  _woken = bool(connector_sync.sync_wake_event().wait(
1996
- _every if last_pass_was_full
1997
- else max(0.0, _every - (_t.time() - last_full_pass_at))))
1998
  connector_sync.sync_wake_event().clear()
 
 
 
 
 
 
 
1999
  # ⛔⛔ HOTFIX 2026-09-24 — A DESK WAKE IS NOT A SCHEDULED PASS.
2000
  # An Amazon first load requeues itself after every bounded chunk, and each requeue SETS the
2001
  # wake event. This loop used to answer every wake with the whole scheduled pass: an Odoo
@@ -2012,14 +2120,12 @@ def _store_resync_loop():
2012
  if "continuing" in _desk.values():
2013
  # A floor between continuations, so a chunk that returns at once cannot spin.
2014
  _t.sleep(max(0.0, desk_min_spacing_seconds - (_t.time() - _desk_started)))
2015
- last_pass_was_full = False
2016
  continue
2017
  _odoo_requested = True
2018
  else:
2019
  _odoo_requested = None
2020
  passes += 1
2021
  last_full_pass_at = _t.time()
2022
- last_pass_was_full = True
2023
  RESYNC_STATE["passes"] = passes
2024
  if _odoo_requested is None:
2025
  _odoo_requested = _run_sync_requests()
@@ -2039,6 +2145,15 @@ def _store_resync_loop():
2039
  print(f"[aios-api] store resync failed ({_err['kind']}, "
2040
  f"{RESYNC_STATE['consecutiveFailures']} in a row): "
2041
  f"{_err['type']}: {_err['message']}")
 
 
 
 
 
 
 
 
 
2042
  # ⭐ WAVE 27 item 17 (E's ASK ->A, resolved): whenever the Odoo RELATIONAL tables need
2043
  # refreshing, they run AFTER the mirror they derive from. A confirmed zero-change report
2044
  # is the W39 exception; deriving before a changed mirror advances would publish a one-cycle
@@ -2076,18 +2191,39 @@ def _store_resync_loop():
2076
  _meta_pull_confirmed, last_meta_fingerprint, last_meta_applied_at, _meta_now)
2077
  _meta_previous = last_meta_fingerprint if _meta_reason is None else None
2078
  _amzn_previous = last_amzn_fingerprint if _meta_reason is None else None
2079
- _reason = _resync_rebuild_reason(sync_report, delete_report,
 
 
 
 
 
 
 
2080
  last_relational_success_at, _meta_now,
2081
  last_source_fingerprints, source_fingerprints)
2082
- # The scheduled pass may now be quiet because Sync now just advanced this mirror.
2083
- # Its zero-change report cannot suppress projection of the explicit Odoo pull.
2084
- if _odoo_requested:
2085
- _reason = "sync now"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2086
  _meta_state = {}
 
2087
  if _reason is not None:
2088
- _table_keys = (_resync_table_keys(_resync_changed_entities(
2089
- last_source_fingerprints, source_fingerprints))
2090
- if _reason.startswith("source-change:") else None)
2091
  print(f"[aios-api] odoo relational rebuild required ({_reason}); "
2092
  f"table_keys={_table_keys if _table_keys is not None else 'all'}")
2093
  # Test/recovery harnesses replace the rebuild seam with its historical three-argument
@@ -2111,8 +2247,13 @@ def _store_resync_loop():
2111
  # A prior successful projection no longer proves the changed mirror was applied.
2112
  # Keep recovery due on the next cadence even when that sync has no new rows.
2113
  last_relational_success_at = None
 
2114
  else:
2115
  print("[aios-api] odoo relational rebuild skipped (unchanged)")
 
 
 
 
2116
  # A zero Odoo report says nothing about Meta. Its exact-plan fingerprint decides
2117
  # whether this cadence may skip both the full-document write and relation pass.
2118
  try:
@@ -2135,6 +2276,11 @@ def _store_resync_loop():
2135
  # Unknown is never carried forward as equality evidence.
2136
  last_meta_fingerprint = None
2137
  last_meta_applied_at = None
 
 
 
 
 
2138
 
2139
 
2140
  def _prewarm():
 
792
  return False
793
 
794
 
795
+ def _pull_amazon(why, vendor=True):
796
+ """Produce Amazon rows in this container before projecting them, on the caller's thread.
797
+
798
+ `vendor=False` (HOTFIX 2026-09-29, the boot catch-up inside the daily window) restores the
799
+ saved mirror and republishes its registry, and calls Amazon for nothing but an unfinished
800
+ first load."""
801
  try:
802
  from harness import amazon_store as _amazon
803
  from harness import runtime as _runtime
 
832
  print(f"[aios-api] amazon sync ({why}): first load "
833
  + ("queued on the sync desk" if receipt.get("accepted") else "already queued or running"))
834
  return True
835
+ if not vendor:
836
+ print(f"[aios-api] amazon mirror restored ({why}); the daily sync is not due yet")
837
+ return True
838
  rep = _amazon.sync(tenant_key, rt=rt, scheduled=True,
839
  log=lambda message: print(f"[aios-api] amazon sync ({why}): {message}"))
840
  _rot.invalidate_sources()
 
957
  provider, tenant = receipt["provider"], receipt["tenant"]
958
  ok, detail = False, ""
959
  first_load_progress, continuing = None, False
960
+ floor_wait = None
961
  try:
962
  from harness import runtime, datastore
963
  rt = runtime.get_runtime(tenant)
 
1024
  from connectors_amazon import assert_safe_status
1025
  first_load_progress = assert_safe_status(report.get("firstLoad"))
1026
  continuing = report.get("state") == "partial"
1027
+ # HOTFIX 2026-09-29: a continuation that landed nothing only met refresh floors.
1028
+ if continuing and report.get("landedTasks") == 0 and report.get("nextDueSeconds"):
1029
+ floor_wait = float(report["nextDueSeconds"])
1030
  problems = list(report.get("problems") or []) + list(report.get("audit_problems") or [])
1031
  tables = report.get("tables") or {}
1032
  if not problems and not tables and not continuing:
 
1066
  connector_sync.finish_sync_request(provider, tenant, ok=ok, detail=detail)
1067
  if outcome is not None:
1068
  outcome[provider] = "continuing" if (continuing and ok) else ("done" if ok else "failed")
1069
+ if continuing and ok and floor_wait:
1070
+ # ⛔ HOTFIX 2026-09-29: NOT every 30 seconds. A pass that landed nothing can only defer
1071
+ # again until Amazon's next report floor opens, and each of those passes republished
1072
+ # the mirror's state to the store. Wait for the floor, then continue.
1073
+ import threading as _threading_desk
1074
+ delay = min(max(floor_wait + 5.0, 60.0), 86400.0)
1075
+ timer = _threading_desk.Timer(delay, connector_sync.request_sync,
1076
+ args=("amazon_sp", tenant),
1077
+ kwargs={"requested_by": "first load"})
1078
+ timer.daemon = True
1079
+ timer.start()
1080
+ print(f"[aios-api] amazon first load waits {int(delay)}s for the next report floor")
1081
+ elif continuing and ok:
1082
  # Finish first: the desk refuses a second in-flight intent. The resident loop claims
1083
  # the continuation as a DESK-ONLY wake; the Odoo pass keeps its own cadence.
1084
  connector_sync.request_sync("amazon_sp", tenant, requested_by="first load")
 
1546
 
1547
  # D-780: fetched rows include an idempotent cursor overlap. Only mirror content compared with
1548
  # the last successful apply proves equality; scalar backfills need not move write_date.
1549
+ # ⛔ HOTFIX 2026-09-29: WEEKLY, NOT DAILY. The owner capped every sync at once a day, and at a
1550
+ # 24-hour cadence a 24-hour recovery age made EVERY pass a full rebuild, which is exactly the
1551
+ # "loading all records" the ruling forbids. The fingerprints are the equality proof; this is only
1552
+ # the safety net for what they cannot see (derived cells, a new connection, schema drift).
1553
+ _RESYNC_REBUILD_MAX_AGE_SECONDS = 7 * 24 * 60 * 60
1554
 
1555
 
1556
  # Dependencies of odoo_relational.plan/read_* and the two read-through table specs. Customers
 
1564
  "account_account": ("ut_odoo_accounts",),
1565
  "sale_order_line": ("ut_odoo_order_lines",),
1566
  "account_move_line": ("ut_odoo_gl_lines",),
1567
+ # HOTFIX 2026-09-29: mirrored for the dashboards (DuckDB), read by NO stored `ut_odoo_*` table
1568
+ # (only the retired `read_products` read `product_product`). An EMPTY tuple says so: a change
1569
+ # here needs no store rebuild, where an absent key forced a full one on every product edit.
1570
+ "product_product": (),
1571
+ "stock_move": (),
1572
+ "stock_location": (),
1573
  }
1574
 
1575
 
 
1647
  return "source-change"
1648
  except (TypeError, ValueError):
1649
  return "sync-unconfirmed"
1650
+ deleted = []
1651
  if delete_report is not None:
1652
  if not isinstance(delete_report, dict):
1653
  return "sync-unconfirmed"
1654
  try:
1655
+ deleted = sorted(entity for entity, count in delete_report.items()
1656
+ if int(count or 0) > 0)
1657
  except (TypeError, ValueError):
1658
  return "sync-unconfirmed"
1659
+ # HOTFIX 2026-09-29: with fingerprints a deletion is an ordinary source change of the
1660
+ # entity it came from (it moves that entity's count and checksum), so it selects that
1661
+ # entity's tables instead of a full rebuild. The legacy caller keeps the old answer.
1662
+ if deleted and current_fingerprints is None:
1663
+ return "delete-change"
1664
  if current_fingerprints is not None:
1665
  if not isinstance(current_fingerprints, dict) or not current_fingerprints:
1666
  return "fingerprint-unconfirmed"
1667
  if not isinstance(previous_fingerprints, dict) or not previous_fingerprints:
1668
  return "no-fingerprint"
1669
  if last_success_at is None or now - last_success_at >= _RESYNC_REBUILD_MAX_AGE_SECONDS:
1670
+ return "weekly-recovery"
1671
  if current_fingerprints is not None:
1672
  # Kept inline so the pure decision can still be AST-extracted on its own by old gates.
1673
+ changed = sorted(set(deleted) | {
1674
+ entity for entity in set(previous_fingerprints) | set(current_fingerprints)
1675
+ if entity not in previous_fingerprints or entity not in current_fingerprints
1676
+ or previous_fingerprints[entity] != current_fingerprints[entity]})
1677
  if changed:
1678
  return "source-change: " + ",".join(changed)
1679
  return None
 
1690
  if not isinstance(last_fingerprint, str) or not last_fingerprint:
1691
  return "meta-first"
1692
  if last_applied_at is None or now - last_applied_at >= _RESYNC_REBUILD_MAX_AGE_SECONDS:
1693
+ return "meta-weekly"
1694
  return None
1695
 
1696
 
 
1730
  #: The fail-safe cadence when nothing is readable, and the floor any cadence is clamped to. Both
1731
  #: predate this ticket; they are named here so the env door cannot be a second, softer limit
1732
  #: [[limit-with-no-enforcer]].
1733
+ #: ⛔⛔ HOTFIX 2026-09-29 (owner): *"We should only sync daily at the fastest."* The floor is a
1734
+ #: DAY and it is enforced HERE, in code, so no Space secret or tenant preset can ask for more.
1735
+ _RESYNC_DEFAULT_SECONDS = 86400
1736
+ _RESYNC_FLOOR_SECONDS = 86400
1737
 
1738
 
1739
  def _resync_env_seconds():
 
1870
  if manual:
1871
  return None, None, None
1872
  sync_report = _ds.sync_all(log=lambda *a, **k: None)
1873
+ # Wave 21: purge hard-deleted rows the cursor sync cannot see (the boot pass's comment has
1874
+ # the measured case); without it deleted Odoo lines inflate every sum on the mirror FOREVER.
 
 
1875
  # ⚠ INSIDE the non-manual branch: a reconcile is a pass over the mirror this loop was
1876
  # just told not to advance.
1877
+ # HOTFIX 2026-09-29: EVERY pass, not every fourth. At a daily cadence a fourth pass is four
1878
+ # days, and the first pass after a reseed never reconciled at all. `reconcile_deletes`
1879
+ # compares counts first and walks ids only for an entity whose count moved.
1880
+ delete_report = _ds.reconcile_deletes(log=lambda *a, **k: None)
1881
  return sync_report, delete_report, None
1882
  except Exception as e: # noqa: BLE001
1883
  # A partial report must never be mistaken for a confirmed zero-change pass.
 
1942
  print(f"[aios-api] sync now projection failed: {type(e).__name__}: {e}")
1943
 
1944
 
1945
+ def _resync_boot_recent(last_pass_at, now, every):
1946
+ """Did the last scheduled pass finish less than one cadence ago? Pure; None means no."""
1947
+ try:
1948
+ return last_pass_at is not None and 0 <= float(now) - float(last_pass_at) < float(every)
1949
+ except (TypeError, ValueError):
1950
+ return False
1951
+
1952
+
1953
+ def _resync_memory_read():
1954
+ """HOTFIX 2026-09-29: what the previous container's loop persisted, or {}. Never raises."""
1955
+ try:
1956
+ import odoo_relational as _rel_memory
1957
+ from harness import runtime as _runtime_memory
1958
+ return _rel_memory.read_resync_memory(
1959
+ _runtime_memory.get_runtime(_resync_tenant()[0]))
1960
+ except Exception as e: # noqa: BLE001
1961
+ print(f"[aios-api] store resync memory unreadable ({type(e).__name__}); "
1962
+ "the first scheduled pass rebuilds in full")
1963
+ return {}
1964
+
1965
+
1966
+ def _resync_memory_write(pass_at, full_rebuild_at, fingerprints):
1967
+ """Persist the loop's restart memory. Best effort: a failed write only costs a rebuild."""
1968
+ try:
1969
+ import odoo_relational as _rel_memory
1970
+ from harness import runtime as _runtime_memory
1971
+ _rel_memory.record_resync_memory(
1972
+ _runtime_memory.get_runtime(_resync_tenant()[0]), pass_at=pass_at,
1973
+ full_rebuild_at=full_rebuild_at, fingerprints=fingerprints)
1974
+ except Exception as e: # noqa: BLE001
1975
+ print(f"[aios-api] store resync memory not saved ({type(e).__name__}); "
1976
+ "the next restart rebuilds in full")
1977
+
1978
+
1979
+ def _resync_confirm_fresh(tenant, cadence_seconds):
1980
+ """A pass that proved the mirror equals the last apply is a good sync: stamp both freshness
1981
+ readers (the connector's `lastGoodSyncAt` and the per-database health), in two writes."""
1982
+ try:
1983
+ import odoo_relational as _rel_fresh
1984
+ import routes_connectors as _rc_fresh
1985
+ from harness import runtime as _runtime_fresh
1986
+ rt = _runtime_fresh.get_runtime(tenant or "royal-imports")
1987
+ stamp = _rel_fresh.record_sync_outcome(rt, ok=True)
1988
+ _rc_fresh.record_odoo_freshness_confirmed(
1989
+ rt, _rc_fresh._odoo_connection_slot(rt, None), at=stamp,
1990
+ cadence_seconds=cadence_seconds)
1991
+ except Exception as e: # noqa: BLE001
1992
+ print(f"[aios-api] odoo freshness stamp not saved ({type(e).__name__}: {e})")
1993
+
1994
+
1995
  def _store_resync_loop():
1996
  """Keep the analytical mirror current — the API-process stand-in for the re-sync the
1997
  Streamlit app piggybacks on page renders. Measure memos key on the pool stamp, so a
 
1999
  import time as _t
2000
  from core import connector_sync
2001
  passes = 0
2002
+ # ⛔⛔ HOTFIX 2026-09-29 — A RESTART NO LONGER FORGETS. These lived in memory only, so every
2003
+ # deploy began with `no-fingerprint` and rebuilt every Odoo table whole (live 2026-09-29
2004
+ # 11:26Z: `table_keys=all`, every table `added 0, updated 0, removed 0`), and every boot ran
2005
+ # the whole scheduled pass however recently the last one had finished. They come back from
2006
+ # the connector config and are written after every scheduled pass. Unknown stays unknown:
2007
+ # a missing or unreadable map is a full rebuild, never equality.
2008
+ _memory = _resync_memory_read()
2009
+ last_relational_success_at = _memory.get("fullRebuildAt")
2010
+ last_source_fingerprints = _memory.get("fingerprints")
2011
+ last_good_pass_at = _memory.get("passAt") or _memory.get("lastGoodSyncAt")
2012
  last_meta_fingerprint = None
2013
  last_meta_applied_at = None
2014
  # ⚠ AMAZON KEEPS ITS OWN FINGERPRINT, never sharing Meta's. Two connectors whose plans change
 
2017
  # codebase already names. Unknown is never carried forward as equality evidence.
2018
  last_amzn_fingerprint = None
2019
  last_full_pass_at = _t.time()
 
2020
  # The least time between two desk-only passes of an Amazon first-load continuation.
2021
  desk_min_spacing_seconds = 30.0
2022
  while True:
 
2089
  # The wait is now interruptible so an administrator's Sync now wakes this writer.
2090
  _woken = False
2091
  if passes:
2092
+ # The wait is what remains of the cadence since the last scheduled pass STARTED, so
2093
+ # continuations can never postpone the scheduled pass. HOTFIX 2026-09-29: after a
2094
+ # full pass too, so passes start a day apart however long the pass ran (a daily pass
2095
+ # that also refreshes every Amazon table can run an hour, and a wait counted from its
2096
+ # END drifted later every day and past the 26-hour stale line).
2097
  _woken = bool(connector_sync.sync_wake_event().wait(
2098
+ max(0.0, _every - (_t.time() - last_full_pass_at))))
 
2099
  connector_sync.sync_wake_event().clear()
2100
+ # ⛔⛔ HOTFIX 2026-09-29 — A RESTART INSIDE THE DAILY WINDOW IS NOT A SYNC. The owner
2101
+ # capped syncing at once a day, and a deploy is not a reason to sync again. So the first
2102
+ # pass after a boot that lands within one cadence of the last scheduled pass only catches
2103
+ # the disposable DuckDB mirror up (Odoo reads, no store; the dashboards read it, W58) and
2104
+ # restores Amazon's saved mirror. The store-touching half (Meta and Amazon vendor pulls,
2105
+ # the relational rebuild) waits for the pass that is actually due.
2106
+ _boot_catch_up = not passes and _resync_boot_recent(last_good_pass_at, _t.time(), _every)
2107
  # ⛔⛔ HOTFIX 2026-09-24 — A DESK WAKE IS NOT A SCHEDULED PASS.
2108
  # An Amazon first load requeues itself after every bounded chunk, and each requeue SETS the
2109
  # wake event. This loop used to answer every wake with the whole scheduled pass: an Odoo
 
2120
  if "continuing" in _desk.values():
2121
  # A floor between continuations, so a chunk that returns at once cannot spin.
2122
  _t.sleep(max(0.0, desk_min_spacing_seconds - (_t.time() - _desk_started)))
 
2123
  continue
2124
  _odoo_requested = True
2125
  else:
2126
  _odoo_requested = None
2127
  passes += 1
2128
  last_full_pass_at = _t.time()
 
2129
  RESYNC_STATE["passes"] = passes
2130
  if _odoo_requested is None:
2131
  _odoo_requested = _run_sync_requests()
 
2145
  print(f"[aios-api] store resync failed ({_err['kind']}, "
2146
  f"{RESYNC_STATE['consecutiveFailures']} in a row): "
2147
  f"{_err['type']}: {_err['message']}")
2148
+ if _boot_catch_up and not _odoo_requested:
2149
+ # Restore only: the saved Amazon mirror and its read-through registry, no vendor call.
2150
+ _pull_amazon("boot", False)
2151
+ _age = max(0, int(_t.time() - last_good_pass_at))
2152
+ print(f"[aios-api] store resync: restarted {_age}s after the last scheduled pass, so "
2153
+ f"only the local mirror was caught up and no store table was rewritten; the "
2154
+ f"next scheduled pass is due in {max(0, _every - _age)}s")
2155
+ last_full_pass_at = last_good_pass_at
2156
+ continue
2157
  # ⭐ WAVE 27 item 17 (E's ASK ->A, resolved): whenever the Odoo RELATIONAL tables need
2158
  # refreshing, they run AFTER the mirror they derive from. A confirmed zero-change report
2159
  # is the W39 exception; deriving before a changed mirror advances would publish a one-cycle
 
2191
  _meta_pull_confirmed, last_meta_fingerprint, last_meta_applied_at, _meta_now)
2192
  _meta_previous = last_meta_fingerprint if _meta_reason is None else None
2193
  _amzn_previous = last_amzn_fingerprint if _meta_reason is None else None
2194
+ # HOTFIX 2026-09-29: `manual` pulls nothing, so only the mirror's fingerprints can show a
2195
+ # change (a Sync now under manual still moves it). This used to read as `sync-unconfirmed`
2196
+ # and rebuilt every table in full on every cadence with nothing new to write.
2197
+ _decision_report = sync_report
2198
+ if _manual and _err is None and sync_report is None and source_fingerprints:
2199
+ _decision_report = {entity: {"phase": "live", "pulled": 0}
2200
+ for entity in source_fingerprints}
2201
+ _reason = _resync_rebuild_reason(_decision_report, delete_report,
2202
  last_relational_success_at, _meta_now,
2203
  last_source_fingerprints, source_fingerprints)
2204
+ # ⛔ HOTFIX 2026-09-29 — SYNC NOW IS INCREMENTAL (owner ruling). It used to force
2205
+ # `table_keys=all`. The fingerprints are compared with the last APPLY, not with this
2206
+ # pass's quiet report, so they already see whatever the Sync now pull changed; an unknown
2207
+ # baseline still rebuilds in full.
2208
+ if _odoo_requested and _reason is None:
2209
+ print("[aios-api] odoo sync now: nothing changed since the last applied sync, "
2210
+ "so no table was rewritten")
2211
+ _table_keys = None
2212
+ if _reason is not None and _reason.startswith("source-change:"):
2213
+ _table_keys = _resync_table_keys(sorted(
2214
+ set(_resync_changed_entities(last_source_fingerprints, source_fingerprints))
2215
+ | {entity.strip() for entity in _reason.split(":", 1)[1].split(",")
2216
+ if entity.strip()}))
2217
+ if _table_keys == []:
2218
+ # Every changed entity feeds no stored table (products, stock): the dashboards
2219
+ # already read the caught-up mirror, and the store has nothing to rewrite.
2220
+ print(f"[aios-api] odoo relational rebuild skipped ({_reason}); "
2221
+ "those entities feed no stored table")
2222
+ last_source_fingerprints = source_fingerprints or None
2223
+ _reason = None
2224
  _meta_state = {}
2225
+ _rebuild_ok = True
2226
  if _reason is not None:
 
 
 
2227
  print(f"[aios-api] odoo relational rebuild required ({_reason}); "
2228
  f"table_keys={_table_keys if _table_keys is not None else 'all'}")
2229
  # Test/recovery harnesses replace the rebuild seam with its historical three-argument
 
2247
  # A prior successful projection no longer proves the changed mirror was applied.
2248
  # Keep recovery due on the next cadence even when that sync has no new rows.
2249
  last_relational_success_at = None
2250
+ _rebuild_ok = False
2251
  else:
2252
  print("[aios-api] odoo relational rebuild skipped (unchanged)")
2253
+ # HOTFIX 2026-09-29: a pass that PROVED nothing changed is a good sync. Without this
2254
+ # stamp an unchanged connector would read stale after 26 hours.
2255
+ if not _manual and _err is None:
2256
+ _resync_confirm_fresh(_cad["tenant"], _every)
2257
  # A zero Odoo report says nothing about Meta. Its exact-plan fingerprint decides
2258
  # whether this cadence may skip both the full-document write and relation pass.
2259
  try:
 
2276
  # Unknown is never carried forward as equality evidence.
2277
  last_meta_fingerprint = None
2278
  last_meta_applied_at = None
2279
+ # HOTFIX 2026-09-29: remember this pass for the next container (see the top of the loop).
2280
+ if _err is None and _rebuild_ok:
2281
+ last_good_pass_at = _meta_now
2282
+ _resync_memory_write(last_good_pass_at, last_relational_success_at,
2283
+ last_source_fingerprints)
2284
 
2285
 
2286
  def _prewarm():
api/odoo_relational.py CHANGED
@@ -3516,9 +3516,14 @@ CONFIG_KEY = "odoo_connector_config"
3516
  #: ⚠ `manual` is not "very slow" — it is NO scheduled sync at all, which is why it maps to None
3517
  #: rather than to a large number. A caller that treats None as a duration gets a TypeError rather
3518
  #: than a silent once-a-century schedule.
3519
- SYNC_PRESETS = {"30m": 1800, "1h": 3600, "4h": 14400, "daily": 86400, "manual": None}
3520
- SYNC_FLOOR_SECONDS = 1800
3521
- DEFAULT_SYNC = "30m"
 
 
 
 
 
3522
 
3523
 
3524
  def read_config(rt):
@@ -3661,6 +3666,95 @@ def record_sync_outcome(rt, ok, at=None):
3661
  return stamp
3662
 
3663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3664
  def _effective_sync_seconds(preset):
3665
  """The interval a sync can actually keep: the tenant's preset, floored, and never faster than
3666
  the deployment's own resync floor (`AIOS_STORE_RESYNC_SECONDS`), which `main.py` applies with
 
3516
  #: ⚠ `manual` is not "very slow" — it is NO scheduled sync at all, which is why it maps to None
3517
  #: rather than to a large number. A caller that treats None as a duration gets a TypeError rather
3518
  #: than a silent once-a-century schedule.
3519
+ #: ⛔⛔ HOTFIX 2026-09-29 (owner): *"We should only sync daily at the fastest."* The floor is now a
3520
+ #: DAY, so `30m`/`1h`/`4h` are gone from the offer. A stored legacy value reads back as `daily`
3521
+ #: (`read_config` defaults anything outside this dict), and a door that is sent one CLAMPS it to
3522
+ #: `daily` and says so. Every automatic pass also skips when nothing changed (`main.py` D-780
3523
+ #: fingerprints, persisted by `record_resync_memory` so a restart does not re-pull everything).
3524
+ SYNC_PRESETS = {"daily": 86400, "manual": None}
3525
+ SYNC_FLOOR_SECONDS = 86400
3526
+ DEFAULT_SYNC = "daily"
3527
 
3528
 
3529
  def read_config(rt):
 
3666
  return stamp
3667
 
3668
 
3669
+ #: HOTFIX 2026-09-29: what the resident resync loop must remember across a RESTART, kept on this
3670
+ #: config document under one field. Before it, `main.py` held all three in memory only, so every
3671
+ #: deploy began with `no-fingerprint` and rebuilt every Odoo table whole (live log 2026-09-29
3672
+ #: 11:26Z: `table_keys=all`, every table `added 0 updated 0 removed 0`), and every boot ran the
3673
+ #: whole scheduled pass however recently the last one had finished.
3674
+ #: * `passAt` the last scheduled pass that completed without a mirror error (ISO);
3675
+ #: * `fullRebuildAt` the last FULL relational rebuild that succeeded (ISO), for the weekly recovery;
3676
+ #: * `fingerprints` `{entity: [count, hash]}` as the last successful apply saw the mirror.
3677
+ #: ⚠ The two numbers are STRINGS: `bit_xor(hash())` is an unsigned 64-bit value, and a JSON reader
3678
+ #: that is not Python may round it. `read_resync_memory` turns them back into the int TUPLES the
3679
+ #: loop compares, because a list never equals a tuple and every pass would read as changed.
3680
+ RESYNC_MEMORY_FIELD = "resync"
3681
+
3682
+
3683
+ def _memory_epoch(value):
3684
+ at = _parse_iso(value)
3685
+ return at.timestamp() if at is not None else None
3686
+
3687
+
3688
+ def encode_fingerprints(fingerprints):
3689
+ """`{entity: (count, hash) | None}` -> the stored shape, or None when there is nothing known."""
3690
+ if not isinstance(fingerprints, dict) or not fingerprints:
3691
+ return None
3692
+ out = {}
3693
+ for entity, value in fingerprints.items():
3694
+ if value is None:
3695
+ out[str(entity)] = None
3696
+ else:
3697
+ out[str(entity)] = [str(int(part)) for part in value]
3698
+ return out
3699
+
3700
+
3701
+ def decode_fingerprints(stored):
3702
+ """The stored shape -> `{entity: (int, int) | None}`, or None when ANY entry is unreadable.
3703
+
3704
+ None means "unknown", which the loop answers with a full rebuild; a partly readable map must
3705
+ never be mistaken for equality.
3706
+ """
3707
+ if not isinstance(stored, dict) or not stored:
3708
+ return None
3709
+ out = {}
3710
+ try:
3711
+ for entity, value in stored.items():
3712
+ if value is None:
3713
+ out[str(entity)] = None
3714
+ elif isinstance(value, (list, tuple)) and len(value) == 2:
3715
+ out[str(entity)] = tuple(int(str(part)) for part in value)
3716
+ else:
3717
+ return None
3718
+ except (TypeError, ValueError):
3719
+ return None
3720
+ return out
3721
+
3722
+
3723
+ def read_resync_memory(rt):
3724
+ """What the last container's resync loop knew, or empty values. Never raises."""
3725
+ empty = {"passAt": None, "fullRebuildAt": None, "fingerprints": None, "lastGoodSyncAt": None}
3726
+ try:
3727
+ cur = rt.get(CONFIG_KEY) if rt is not None else None
3728
+ except Exception: # noqa: BLE001
3729
+ return empty
3730
+ cur = cur if isinstance(cur, dict) else {}
3731
+ memory = cur.get(RESYNC_MEMORY_FIELD)
3732
+ memory = memory if isinstance(memory, dict) else {}
3733
+ return {"passAt": _memory_epoch(memory.get("passAt")),
3734
+ "fullRebuildAt": _memory_epoch(memory.get("fullRebuildAt")),
3735
+ "fingerprints": decode_fingerprints(memory.get("fingerprints")),
3736
+ "lastGoodSyncAt": _memory_epoch(cur.get("lastGoodSyncAt"))}
3737
+
3738
+
3739
+ def record_resync_memory(rt, *, pass_at, full_rebuild_at, fingerprints):
3740
+ """Persist the loop's three facts exactly as it now holds them (None clears one)."""
3741
+ def _iso(epoch):
3742
+ if epoch is None:
3743
+ return None
3744
+ return _dt.datetime.fromtimestamp(float(epoch), _dt.timezone.utc).isoformat()
3745
+
3746
+ memory = {"passAt": _iso(pass_at), "fullRebuildAt": _iso(full_rebuild_at),
3747
+ "fingerprints": encode_fingerprints(fingerprints)}
3748
+
3749
+ def _up(cur):
3750
+ cur = dict(cur) if isinstance(cur, dict) else {}
3751
+ cur[RESYNC_MEMORY_FIELD] = memory
3752
+ return cur
3753
+
3754
+ rt.update(CONFIG_KEY, _up, flush="sync")
3755
+ return memory
3756
+
3757
+
3758
  def _effective_sync_seconds(preset):
3759
  """The interval a sync can actually keep: the tenant's preset, floored, and never faster than
3760
  the deployment's own resync floor (`AIOS_STORE_RESYNC_SECONDS`), which `main.py` applies with
api/routes_connectors.py CHANGED
@@ -1544,6 +1544,57 @@ def record_odoo_stage(rt, connection_id, stage, state, *, database_key=None, row
1544
  return odoo_health_receipt(rt, cid)
1545
 
1546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1547
  def _lag_seconds(stamp, now=None):
1548
  if not stamp:
1549
  return None
 
1544
  return odoo_health_receipt(rt, cid)
1545
 
1546
 
1547
+ def record_odoo_freshness_confirmed(rt, connection_id, *, at=None, cadence_seconds=None):
1548
+ """HOTFIX 2026-09-29: a scheduled pass PROVED the mirror equals the last apply, so every
1549
+ database of this connection that is not failing is as fresh as that proof.
1550
+
1551
+ ONE write for the whole connection, where `record_odoo_stage` would be one per database: the
1552
+ point of a skipped pass is that it does not rewrite the store. A failing stage keeps its
1553
+ failure, and a connection with nothing recorded yet is left alone (nothing to confirm).
1554
+ """
1555
+ cid = _odoo_connection_slot(rt, connection_id)
1556
+ stamp = str(at or datetime.now(timezone.utc).isoformat())
1557
+
1558
+ def _fresh(stages):
1559
+ stages = dict(stages or {})
1560
+ row = dict(stages.get("freshness") or {})
1561
+ if row.get("state") == "failed":
1562
+ return stages, False
1563
+ stages["freshness"] = {**row, "state": "ready", "at": stamp, "finishedAt": stamp,
1564
+ "lastSuccess": stamp, "failure": None}
1565
+ return stages, True
1566
+
1567
+ def _update(current):
1568
+ document = dict(current or {})
1569
+ connections = dict(document.get("connections") or {})
1570
+ connection = dict(connections.get(cid) or {})
1571
+ if not connection:
1572
+ return document
1573
+ stages, ok = _fresh(connection.get("stages"))
1574
+ connection["stages"] = stages
1575
+ connection["lastAttempt"] = stamp
1576
+ if ok:
1577
+ connection["lastSuccess"] = stamp
1578
+ if cadence_seconds is not None:
1579
+ connection["cadenceSeconds"] = int(cadence_seconds)
1580
+ databases = dict(connection.get("databases") or {})
1581
+ for key, database in list(databases.items()):
1582
+ database = dict(database or {})
1583
+ db_stages, ok = _fresh(database.get("stages"))
1584
+ if ok:
1585
+ database.update({"stages": db_stages, "lastSuccess": stamp,
1586
+ "lastAttempt": stamp})
1587
+ databases[key] = database
1588
+ if databases:
1589
+ connection["databases"] = databases
1590
+ connections[cid] = connection
1591
+ document["connections"] = connections
1592
+ return document
1593
+
1594
+ rt.update(_ODOO_HEALTH_STATUS, _update, flush="sync")
1595
+ return stamp
1596
+
1597
+
1598
  def _lag_seconds(stamp, now=None):
1599
  if not stamp:
1600
  return None
api/routes_keychain.py CHANGED
@@ -1442,9 +1442,10 @@ def odoo_config_put(body: dict = Body(default=None),
1442
  # and never silently ignored either, because a control that discards your answer
1443
  # without a word is how a limit becomes invisible.
1444
  clean_every = rel.DEFAULT_SYNC
1445
- notes.append(f"{every!r} is not an interval this connector offers, and anything under "
1446
- f"{rel.SYNC_FLOOR_SECONDS // 60} minutes is not available at all; the "
1447
- f"sync interval was set to the {rel.DEFAULT_SYNC} floor instead")
 
1448
 
1449
  server_db = body.get("serverDb")
1450
  if server_db is not None:
 
1442
  # and never silently ignored either, because a control that discards your answer
1443
  # without a word is how a limit becomes invisible.
1444
  clean_every = rel.DEFAULT_SYNC
1445
+ # HOTFIX 2026-09-29: the floor is a day, so the sentence names it in words.
1446
+ notes.append(f"{every!r} is not an interval this connector offers, and syncing more "
1447
+ f"often than once a day is not available at all; the sync interval was "
1448
+ f"set to once a day instead")
1449
 
1450
  server_db = body.get("serverDb")
1451
  if server_db is not None:
api/test_odoo_rank_refresh.py CHANGED
@@ -472,6 +472,155 @@ class RankRefreshTests(unittest.TestCase):
472
  with self.assertRaises(AssertionError):
473
  self.test_rank_change_behind_cursor_reaches_customer_reader()
474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  def test_pause_never_opens_mirror_or_source(self):
476
  with patch.object(ds, 'source_paused', return_value=True), \
477
  patch.object(ds, 'connect') as connect:
 
472
  with self.assertRaises(AssertionError):
473
  self.test_rank_change_behind_cursor_reaches_customer_reader()
474
 
475
+ # ── HOTFIX 2026-09-29 (owner): "only sync daily at the fastest", and only what changed ──────
476
+ def run_daily_loop(self, memory, current, *, now=10_000.0, cadence=86400, manual=False):
477
+ """Drive the real loop for ONE pass with a persisted memory; stop at its first wait."""
478
+ source = ast.parse(Path(__file__).with_name('main.py').read_text(encoding='utf-8'))
479
+ functions = {'_store_resync_loop', '_resync_rebuild_reason',
480
+ '_meta_rebuild_force_reason', '_resync_boot_recent'}
481
+ nodes = [node for node in source.body
482
+ if isinstance(node, ast.FunctionDef) and node.name in functions
483
+ or isinstance(node, ast.Assign) and any(
484
+ isinstance(target, ast.Name)
485
+ and target.id in ('_RESYNC_REBUILD_MAX_AGE_SECONDS', '_RESYNC_ENTITY_TABLE_KEYS')
486
+ for target in node.targets)]
487
+ events, sleeps = [], []
488
+
489
+ def sleep(seconds):
490
+ sleeps.append(seconds)
491
+ raise StopIteration('bounded synthetic resident loop')
492
+
493
+ def sync(manual_flag, passes):
494
+ events.append(('sync', passes))
495
+ return (None if manual_flag else {'res_partner': {'phase': 'live', 'pulled': 0}},
496
+ None if manual_flag else {}, None)
497
+
498
+ def rebuild(why, previous, meta_state, **scope):
499
+ events.append(('rebuild', scope.get('table_keys')))
500
+ return True
501
+
502
+ clock = SimpleNamespace(sleep=sleep, time=lambda: now,
503
+ strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
504
+ ns = dict(RESYNC_STATE={}, _RESYNC_NOTICE=[None],
505
+ _resolve_resync_cadence=lambda: dict(
506
+ resolvedSeconds=cadence, manual=manual, tenant='synthetic',
507
+ tenantSource='test', tenantSeconds=cadence, envSeconds=cadence,
508
+ disagreement=None),
509
+ _resync_memory_read=lambda: dict(memory),
510
+ _resync_memory_write=lambda *a: events.append(('memory',) + a),
511
+ _resync_mirror_pass=sync,
512
+ _resync_source_fingerprints=lambda *_: dict(current),
513
+ _pull_meta=lambda *a: events.append(('meta',) + a) or True,
514
+ _pull_amazon=lambda *a: events.append(('amazon',) + a) or True,
515
+ _rebuild_odoo_relational=rebuild,
516
+ _rebuild_meta_relational=lambda *_a, **_k: {},
517
+ _rebuild_amazon_relational=lambda *_a, **_k: {},
518
+ _resync_confirm_fresh=lambda *a: events.append(('fresh',) + a))
519
+ nodes = _with_collaborators(source, nodes, ns)
520
+ exec(compile(ast.Module(body=nodes, type_ignores=[]), 'main.py:daily-loop', 'exec'), ns)
521
+ runtime = SimpleNamespace(get_runtime=lambda *_: object())
522
+ import harness
523
+ from core import connector_sync
524
+ wake = SimpleNamespace(wait=sleep, clear=lambda: None)
525
+ with patch.dict(sys.modules, {'time': clock, 'harness.runtime': runtime}), \
526
+ patch.object(harness, 'runtime', runtime, create=True), \
527
+ patch.object(connector_sync, 'sync_wake_event', return_value=wake), \
528
+ patch.object(connector_sync, 'take_sync_requests', return_value=[]), \
529
+ redirect_stdout(io.StringIO()):
530
+ with self.assertRaisesRegex(StopIteration, 'bounded synthetic'):
531
+ ns['_store_resync_loop']()
532
+ self.net.assert_not_called()
533
+ return events, sleeps
534
+
535
+ def test_restart_inside_the_day_only_catches_the_mirror_up(self):
536
+ fps = {'res_partner': (3, 7)}
537
+ events, sleeps = self.run_daily_loop(
538
+ {'passAt': 10_000.0 - 3600, 'fullRebuildAt': 10_000.0 - 3600, 'fingerprints': fps},
539
+ {'res_partner': (4, 9)})
540
+ # No rebuild, no Meta pull, no Amazon vendor pull: only the mirror and Amazon's restore.
541
+ self.assertEqual(events, [('sync', 1), ('amazon', 'boot', False)])
542
+ self.assertEqual(sleeps, [86400 - 3600])
543
+
544
+ def test_restart_after_the_day_runs_the_scheduled_pass(self):
545
+ fps = {'res_partner': (3, 7)}
546
+ events, _ = self.run_daily_loop(
547
+ {'passAt': 10_000.0 - 90_000, 'fullRebuildAt': 10_000.0 - 90_000,
548
+ 'fingerprints': fps}, fps)
549
+ self.assertEqual([e[0] for e in events], ['sync', 'meta', 'amazon', 'fresh', 'memory'])
550
+ self.assertEqual(events[2], ('amazon', 'resync'))
551
+ self.assertEqual(events[-1], ('memory', 10_000.0, 10_000.0 - 90_000, fps))
552
+
553
+ def test_persisted_fingerprints_skip_the_rebuild_after_a_restart(self):
554
+ fps = {'res_partner': (3, 7)}
555
+ events, _ = self.run_daily_loop(
556
+ {'passAt': None, 'fullRebuildAt': 10_000.0 - 600, 'fingerprints': fps}, fps)
557
+ self.assertNotIn('rebuild', [e[0] for e in events])
558
+ self.assertIn(('fresh', 'synthetic', 86400), events)
559
+
560
+ def test_no_persisted_fingerprints_still_rebuilds_in_full(self):
561
+ events, _ = self.run_daily_loop(
562
+ {'passAt': None, 'fullRebuildAt': None, 'fingerprints': None},
563
+ {'res_partner': (3, 7)})
564
+ self.assertIn(('rebuild', None), events)
565
+ self.assertNotIn('fresh', [e[0] for e in events])
566
+
567
+ def test_a_changed_entity_rebuilds_only_its_tables(self):
568
+ events, _ = self.run_daily_loop(
569
+ {'passAt': None, 'fullRebuildAt': 10_000.0 - 600,
570
+ 'fingerprints': {'res_partner': (3, 7), 'product_product': (1, 1)}},
571
+ {'res_partner': (3, 8), 'product_product': (1, 1)})
572
+ rebuilds = [e for e in events if e[0] == 'rebuild']
573
+ self.assertEqual(len(rebuilds), 1)
574
+ self.assertIsNotNone(rebuilds[0][1])
575
+ self.assertIn('ut_odoo_orders', rebuilds[0][1])
576
+
577
+ def test_a_change_no_stored_table_reads_skips_the_rebuild(self):
578
+ events, _ = self.run_daily_loop(
579
+ {'passAt': None, 'fullRebuildAt': 10_000.0 - 600,
580
+ 'fingerprints': {'res_partner': (3, 7), 'product_product': (1, 1)}},
581
+ {'res_partner': (3, 7), 'product_product': (2, 5)})
582
+ self.assertNotIn('rebuild', [e[0] for e in events])
583
+ memory = [e for e in events if e[0] == 'memory'][-1]
584
+ self.assertEqual(memory[3], {'res_partner': (3, 7), 'product_product': (2, 5)})
585
+
586
+ def test_manual_with_unchanged_fingerprints_no_longer_rebuilds_every_cadence(self):
587
+ fps = {'res_partner': (3, 7)}
588
+ events, _ = self.run_daily_loop(
589
+ {'passAt': None, 'fullRebuildAt': 10_000.0 - 600, 'fingerprints': fps}, fps,
590
+ manual=True)
591
+ self.assertNotIn('rebuild', [e[0] for e in events])
592
+
593
+ def test_resync_memory_round_trip_compares_equal(self):
594
+ import json
595
+ import odoo_relational as rel
596
+
597
+ class Store:
598
+ def __init__(self):
599
+ self.docs = {}
600
+
601
+ def get(self, key):
602
+ return self.docs.get(key)
603
+
604
+ def update(self, key, fn, flush=None):
605
+ self.docs[key] = fn(self.docs.get(key))
606
+
607
+ fps = {'sale_order': (12, 18446744073709551615), 'stock_move': None}
608
+ stored = json.loads(json.dumps(rel.encode_fingerprints(fps)))
609
+ self.assertEqual(rel.decode_fingerprints(stored), fps)
610
+ self.assertIsInstance(rel.decode_fingerprints(stored)['sale_order'], tuple)
611
+ # Unknown is never equality: any unreadable entry makes the whole map unknown.
612
+ self.assertIsNone(rel.decode_fingerprints({'sale_order': ['x', '1']}))
613
+ self.assertIsNone(rel.decode_fingerprints({'sale_order': [1]}))
614
+ self.assertIsNone(rel.decode_fingerprints('not a map'))
615
+ rt = Store()
616
+ rt.docs[rel.CONFIG_KEY] = {'syncEvery': 'daily', 'lastGoodSyncAt': '2026-09-29T00:00:00+00:00'}
617
+ rel.record_resync_memory(rt, pass_at=1_000.0, full_rebuild_at=None, fingerprints=fps)
618
+ memory = rel.read_resync_memory(rt)
619
+ self.assertEqual((memory['passAt'], memory['fullRebuildAt'], memory['fingerprints']),
620
+ (1_000.0, None, fps))
621
+ self.assertEqual(rt.docs[rel.CONFIG_KEY]['syncEvery'], 'daily')
622
+ self.assertIsNotNone(memory['lastGoodSyncAt'])
623
+
624
  def test_pause_never_opens_mirror_or_source(self):
625
  with patch.object(ds, 'source_paused', return_value=True), \
626
  patch.object(ds, 'connect') as connect:
platform/harness/amazon_store.py CHANGED
@@ -109,12 +109,23 @@ def read_database_enablement(rt):
109
  return {"available": True, "databases": {key: stored.get(key, True) for key in keys}}
110
 
111
 
 
 
 
 
 
 
 
 
112
  def sync_plan(states, tables=None, *, now=None):
113
- """Pure cadence decision: one oldest due table per tick, with no stagger sleep.
114
 
115
  Attempt markers survive in the tenant's saved mirror. Failed tables rotate behind peers.
116
  Settlement LIST discovery runs separately on every resync and consumes no report slot.
117
- The client still owns pacing/retries within a table; this spreads tables across caller ticks.
 
 
 
118
  """
119
  from harness.amazon_client import REPORT_STAGGER_SECONDS
120
  now = _utc(now)
@@ -123,23 +134,24 @@ def sync_plan(states, tables=None, *, now=None):
123
  if state and table != "settlements"}
124
  deferred = {}
125
  due = []
 
126
  for table in want:
127
  if table == "settlements":
128
  continue
129
- if (reason := _interval_reason(table, states.get(table), now)):
130
  deferred[table] = reason
131
  else:
132
  due.append(table)
133
  # Boot and the resident first pass can be adjacent. Report the delay instead of sleeping.
134
  recent = max(stamps.values()) if stamps else None
135
  ready = recent is None or (now - recent).total_seconds() >= REPORT_STAGGER_SECONDS
136
- selected = min(due, key=lambda table: stamps.get(
137
- table, datetime.min.replace(tzinfo=timezone.utc))) if due and ready else None
138
- for table in due:
139
- if table != selected:
140
  deferred[table] = ("table stagger: waiting for a later cadence tick; "
141
  f"minimum spacing {REPORT_STAGGER_SECONDS:g}s")
142
- return {"tables": ([selected] if selected else []) + (["settlements"] if "settlements" in want else []),
143
  "deferred": deferred}
144
 
145
 
@@ -155,14 +167,30 @@ def _readable_duration(seconds):
155
  return f"{seconds} seconds"
156
 
157
 
158
- def _interval_reason(table, state, now):
159
- seconds = (_client().REPORT_TYPES.get(table) or {}).get("min_interval_s")
 
 
 
 
 
160
  if seconds and state and state["state"] == "done":
161
  due = _utc(state["updated_at"]) + timedelta(seconds=seconds)
162
- if _utc(now) < due:
163
- return (f"Amazon allows this report at most once every {_readable_duration(seconds)}; "
164
- f"next due {_iso(due)}")
165
- return None
 
 
 
 
 
 
 
 
 
 
 
166
 
167
  #: Durable proof that the two non-report role operations actually ran. A report-backed table can
168
  #: contain rows while one of these role grants is still missing, so table presence alone is not
@@ -2500,7 +2528,19 @@ def needs_first_load(tenant_key, rt=None):
2500
  # boot. Its refusal is on screen; the scheduled rotation retries it.
2501
  refused = {table for table in added
2502
  if (_read_state(con, entity_key(table)) or {}).get("state") == "refused"}
2503
- return (bool(load and load["state"] != "done")
 
 
 
 
 
 
 
 
 
 
 
 
2504
  or not any(read_watermark(con, table) for table in TABLES)
2505
  or any(not read_watermark(con, table) for table in added if table not in refused))
2506
  finally:
@@ -2854,7 +2894,14 @@ def _sync_margin_window(con, table, fields, w0, w1, *, max_wait, log):
2854
  kwargs["options"] = options
2855
  text, meta = cx.report_document(fields, spec["report"], **kwargs, max_wait=max_wait, log=log)
2856
  parser_args = {"document_id": meta.get("reportDocumentId"), "report_type": spec["report"]}
2857
- if spec.get("json_root"):
 
 
 
 
 
 
 
2858
  columns, rows = parse_json_report(text, spec["json_root"], **parser_args)
2859
  if spec.get("json_extra_roots"):
2860
  for row in rows:
@@ -2887,9 +2934,11 @@ def _sync_margin_window(con, table, fields, w0, w1, *, max_wait, log):
2887
  row.get("fulfillment_center_id") or
2888
  row.get("fulfilment_center") or "all")
2889
  columns = sorted(set(columns) | {k for row in rows for k in row})
 
 
 
2890
  marker = {"start": period, "end": _iso(w1) if column == "_period_start" else period,
2891
- "column": column, "count": document_row_count(
2892
- text, (spec["json_root"], *spec.get("json_extra_roots", ())) if spec.get("json_root") else ())}
2893
  return _replace_period(con, table, rows, columns, column, period, marker=marker,
2894
  snapshot=bool(spec.get("snapshot")))
2895
 
@@ -3100,12 +3149,15 @@ def sync(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None
3100
  if scheduled and load and load["state"] != "done":
3101
  # The pinned inline producer still calls sync(scheduled=True). Do not let it start an
3102
  # unbounded history pull between the resident writer's bounded first-load passes.
 
 
 
3103
  for table in want:
3104
- if table == "settlements":
3105
  continue
3106
  report["tables"][table] = {"state": "deferred", "reason":
3107
  "The first load is continuing in bounded passes on the resident sync thread."}
3108
- want = [table for table in want if table == "settlements"]
3109
  if scheduled:
3110
  plan = sync_plan({table: _read_state(con, entity_key("sync_tick_" + table))
3111
  for table in TABLES}, want, now=end)
@@ -3233,10 +3285,14 @@ def sync(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None
3233
  or table in PERIOD_TABLES or table in LEGACY_SNAPSHOT_TABLES)):
3234
  break
3235
  if first_load and table in GROUP_A_TABLES:
3236
- reason = _interval_reason(table, _read_state(con, entity_key("sync_tick_" + table)),
3237
- datetime.now(timezone.utc))
3238
  if reason:
3239
  report["tables"][table] = {"state": "deferred", "reason": reason}
 
 
 
 
3240
  continue
3241
  if table in handled:
3242
  continue
@@ -3638,6 +3694,9 @@ def sync(tenant_key="royal-imports", tables=None, since=None, log=print, rt=None
3638
  wait = (max(0, floor - (datetime.now(timezone.utc) - _utc(tick["updated_at"])).total_seconds())
3639
  if tick and tick["state"] == "done" else 0)
3640
  floor_eta = max(floor_eta, int(wait + max(0, count - 1) * floor + 0.999))
 
 
 
3641
  progress = {"state": state, "remaining": remaining,
3642
  "etaSeconds": max(first_load_eta(remaining, burst=0), floor_eta),
3643
  "cause": first_load_eta_cause(remaining), "backfillDays": DEFAULT_BACKFILL_DAYS}
@@ -4380,7 +4439,9 @@ def margin_selftest(log=print, check=None):
4380
  rejects(lambda: cx._create_report("fixture", spec["report"], ["MKT"], start=_iso(start))))
4381
  states = {table: {"state": "done", "updated_at": _iso(end-timedelta(hours=1))}}
4382
  probe = lambda: table in sync_plan(states, [table], now=end)["deferred"]
4383
- with patch.dict(spec, {"min_interval_s": 0}):
 
 
4384
  red = not probe()
4385
  result = sync_plan(states, [table], now=end)
4386
  ck(f"margin {table} refresh floor defers with a reason", red and probe()
@@ -4949,6 +5010,20 @@ def group_a_selftest(log=print, check=None):
4949
  ck("an empty restatement deletes stale period rows and stays unproven",
4950
  con.execute("SELECT COUNT(*) FROM amzn_reimbursements").fetchone()[0] == 0
4951
  and _validate_margin(con, "reimbursements")["state"] == "unproven")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4952
  finally:
4953
  con.close()
4954
 
@@ -5003,6 +5078,19 @@ def group_a_selftest(log=print, check=None):
5003
  and all(read_watermark(con, table) for table in selected)
5004
  and all(checked[table]["state"] == "ok" for table in selected)
5005
  and not needs_first_load(rt.key, rt))
 
 
 
 
 
 
 
 
 
 
 
 
 
5006
  finally:
5007
  con.close()
5008
 
 
109
  return {"available": True, "databases": {key: stored.get(key, True) for key in keys}}
110
 
111
 
112
+ #: ⛔⛔ HOTFIX 2026-09-29 (owner): *"We should only sync daily at the fastest."* A scheduled pass
113
+ #: refreshes each table at most once a day. The two hours of grace keep a table stamped late in
114
+ #: yesterday's pass from sliding to 48 hours because today's pass reached it a little earlier.
115
+ #: An operator's Sync now keeps only Amazon's own report floors (owner ruling, same day).
116
+ SCHEDULED_FLOOR_SECONDS = 86400
117
+ SCHEDULED_FLOOR_GRACE_SECONDS = 2 * 3600
118
+
119
+
120
  def sync_plan(states, tables=None, *, now=None):
121
+ """Pure cadence decision: EVERY due table, oldest first, with no stagger sleep.
122
 
123
  Attempt markers survive in the tenant's saved mirror. Failed tables rotate behind peers.
124
  Settlement LIST discovery runs separately on every resync and consumes no report slot.
125
+ The client still owns pacing/retries within a table.
126
+ ⛔ HOTFIX 2026-09-29: this picked ONE table per tick. At a once-a-day cadence that is one
127
+ table a day, about seven weeks between two refreshes of the same table, so a scheduled pass
128
+ now takes every table whose daily floor (and Amazon's own floor) has passed.
129
  """
130
  from harness.amazon_client import REPORT_STAGGER_SECONDS
131
  now = _utc(now)
 
134
  if state and table != "settlements"}
135
  deferred = {}
136
  due = []
137
+ floor = SCHEDULED_FLOOR_SECONDS - SCHEDULED_FLOOR_GRACE_SECONDS
138
  for table in want:
139
  if table == "settlements":
140
  continue
141
+ if (reason := _interval_reason(table, states.get(table), now, floor_s=floor)):
142
  deferred[table] = reason
143
  else:
144
  due.append(table)
145
  # Boot and the resident first pass can be adjacent. Report the delay instead of sleeping.
146
  recent = max(stamps.values()) if stamps else None
147
  ready = recent is None or (now - recent).total_seconds() >= REPORT_STAGGER_SECONDS
148
+ oldest = datetime.min.replace(tzinfo=timezone.utc)
149
+ selected = sorted(due, key=lambda table: (stamps.get(table, oldest), want.index(table))) if ready else []
150
+ if not ready:
151
+ for table in due:
152
  deferred[table] = ("table stagger: waiting for a later cadence tick; "
153
  f"minimum spacing {REPORT_STAGGER_SECONDS:g}s")
154
+ return {"tables": selected + (["settlements"] if "settlements" in want else []),
155
  "deferred": deferred}
156
 
157
 
 
167
  return f"{seconds} seconds"
168
 
169
 
170
+ def _interval_wait(table, state, now, floor_s=None):
171
+ """Seconds until `table` may be requested again (0 when due) and which floor decides it.
172
+
173
+ `floor_s` is the scheduled daily floor; Amazon's own `min_interval_s` always applies too.
174
+ """
175
+ vendor = (_client().REPORT_TYPES.get(table) or {}).get("min_interval_s") or 0
176
+ seconds = max(int(vendor), int(floor_s or 0))
177
  if seconds and state and state["state"] == "done":
178
  due = _utc(state["updated_at"]) + timedelta(seconds=seconds)
179
+ wait = (due - _utc(now)).total_seconds()
180
+ if wait > 0:
181
+ return wait, due, seconds, seconds > int(vendor)
182
+ return 0, None, seconds, False
183
+
184
+
185
+ def _interval_reason(table, state, now, floor_s=None):
186
+ wait, due, seconds, daily = _interval_wait(table, state, now, floor_s=floor_s)
187
+ if wait <= 0:
188
+ return None
189
+ if daily:
190
+ return (f"Scheduled syncs refresh each Amazon table at most once a day; "
191
+ f"next due {_iso(due)}")
192
+ return (f"Amazon allows this report at most once every {_readable_duration(seconds)}; "
193
+ f"next due {_iso(due)}")
194
 
195
  #: Durable proof that the two non-report role operations actually ran. A report-backed table can
196
  #: contain rows while one of these role grants is still missing, so table presence alone is not
 
2528
  # boot. Its refusal is on screen; the scheduled rotation retries it.
2529
  refused = {table for table in added
2530
  if (_read_state(con, entity_key(table)) or {}).get("state") == "refused"}
2531
+ # ⛔ HOTFIX 2026-09-29 (D-3496): the same rule for a load that STOPPED. A load left
2532
+ # "failed" only because Amazon refused a report (a 403 for a report it does not offer this
2533
+ # seller) stayed "not done" forever, so every restart queued it again AND the scheduled
2534
+ # producer deferred every table to it: live's Amazon tables stopped refreshing. A stopped
2535
+ # load is still owed only while an enabled table has no watermark and was not refused; a
2536
+ # load still CONTINUING ("partial") is owed until a pass closes it.
2537
+ missing = [table for table in TABLES
2538
+ if enabled.get(amazon_schema.DATABASE_PREFIX + table)
2539
+ and not read_watermark(con, table)
2540
+ and (_read_state(con, entity_key(table)) or {}).get("state") != "refused"]
2541
+ owed = bool(load and load["state"] != "done"
2542
+ and (load["state"] != "failed" or missing))
2543
+ return (owed
2544
  or not any(read_watermark(con, table) for table in TABLES)
2545
  or any(not read_watermark(con, table) for table in added if table not in refused))
2546
  finally:
 
2894
  kwargs["options"] = options
2895
  text, meta = cx.report_document(fields, spec["report"], **kwargs, max_wait=max_wait, log=log)
2896
  parser_args = {"document_id": meta.get("reportDocumentId"), "report_type": spec["report"]}
2897
+ if spec.get("json_root") and meta.get("cancelled") and not str(text or "").strip():
2898
+ # ⛔ HOTFIX 2026-09-29 (D-3496): CANCELLED is Amazon's "no data" (the client already
2899
+ # returns an empty document for it, S66-T42), but the JSON parser read "" as a document
2900
+ # with no row root and REFUSED it. So the two B2B opportunity reports never earned a
2901
+ # watermark, the first load never finished, and every restart queued it again. An empty
2902
+ # period is a landed period; a real payload without its root is still refused below.
2903
+ columns, rows = [], []
2904
+ elif spec.get("json_root"):
2905
  columns, rows = parse_json_report(text, spec["json_root"], **parser_args)
2906
  if spec.get("json_extra_roots"):
2907
  for row in rows:
 
2934
  row.get("fulfillment_center_id") or
2935
  row.get("fulfilment_center") or "all")
2936
  columns = sorted(set(columns) | {k for row in rows for k in row})
2937
+ roots = (spec["json_root"], *spec.get("json_extra_roots", ())) if spec.get("json_root") else ()
2938
+ # HOTFIX 2026-09-29: a CANCELLED JSON report is an empty document with no roots to count.
2939
+ empty = bool(roots) and meta.get("cancelled") and not str(text or "").strip()
2940
  marker = {"start": period, "end": _iso(w1) if column == "_period_start" else period,
2941
+ "column": column, "count": 0 if empty else document_row_count(text, roots)}
 
2942
  return _replace_period(con, table, rows, columns, column, period, marker=marker,
2943
  snapshot=bool(spec.get("snapshot")))
2944
 
 
3149
  if scheduled and load and load["state"] != "done":
3150
  # The pinned inline producer still calls sync(scheduled=True). Do not let it start an
3151
  # unbounded history pull between the resident writer's bounded first-load passes.
3152
+ # HOTFIX 2026-09-29 (D-3496): only a table WITHOUT a watermark belongs to the first load.
3153
+ # A watermark is written when a table's history is complete, so its next window is
3154
+ # bounded; deferring it too froze every loaded table behind one refused report.
3155
  for table in want:
3156
+ if table == "settlements" or read_watermark(con, table):
3157
  continue
3158
  report["tables"][table] = {"state": "deferred", "reason":
3159
  "The first load is continuing in bounded passes on the resident sync thread."}
3160
+ want = [table for table in want if table == "settlements" or read_watermark(con, table)]
3161
  if scheduled:
3162
  plan = sync_plan({table: _read_state(con, entity_key("sync_tick_" + table))
3163
  for table in TABLES}, want, now=end)
 
3285
  or table in PERIOD_TABLES or table in LEGACY_SNAPSHOT_TABLES)):
3286
  break
3287
  if first_load and table in GROUP_A_TABLES:
3288
+ tick = _read_state(con, entity_key("sync_tick_" + table))
3289
+ reason = _interval_reason(table, tick, datetime.now(timezone.utc))
3290
  if reason:
3291
  report["tables"][table] = {"state": "deferred", "reason": reason}
3292
+ # HOTFIX 2026-09-29: when the next floor opens, so the desk can wait for it
3293
+ # instead of re-queuing a pass that can only defer again.
3294
+ wait = _interval_wait(table, tick, datetime.now(timezone.utc))[0]
3295
+ report["nextDueSeconds"] = min(report.get("nextDueSeconds") or wait, wait)
3296
  continue
3297
  if table in handled:
3298
  continue
 
3694
  wait = (max(0, floor - (datetime.now(timezone.utc) - _utc(tick["updated_at"])).total_seconds())
3695
  if tick and tick["state"] == "done" else 0)
3696
  floor_eta = max(floor_eta, int(wait + max(0, count - 1) * floor + 0.999))
3697
+ # HOTFIX 2026-09-29: whether this pass FETCHED anything. A continuation that only met
3698
+ # refresh floors must not re-queue itself every 30 seconds; the daily pass resumes it.
3699
+ report["landedTasks"] = len(landed)
3700
  progress = {"state": state, "remaining": remaining,
3701
  "etaSeconds": max(first_load_eta(remaining, burst=0), floor_eta),
3702
  "cause": first_load_eta_cause(remaining), "backfillDays": DEFAULT_BACKFILL_DAYS}
 
4439
  rejects(lambda: cx._create_report("fixture", spec["report"], ["MKT"], start=_iso(start))))
4440
  states = {table: {"state": "done", "updated_at": _iso(end-timedelta(hours=1))}}
4441
  probe = lambda: table in sync_plan(states, [table], now=end)["deferred"]
4442
+ with patch.dict(spec, {"min_interval_s": 0}), \
4443
+ patch.object(sys.modules[__name__], "SCHEDULED_FLOOR_SECONDS",
4444
+ SCHEDULED_FLOOR_GRACE_SECONDS):
4445
  red = not probe()
4446
  result = sync_plan(states, [table], now=end)
4447
  ck(f"margin {table} refresh floor defers with a reason", red and probe()
 
5010
  ck("an empty restatement deletes stale period rows and stays unproven",
5011
  con.execute("SELECT COUNT(*) FROM amzn_reimbursements").fetchone()[0] == 0
5012
  and _validate_margin(con, "reimbursements")["state"] == "unproven")
5013
+ # HOTFIX 2026-09-29 (D-3496): CANCELLED is Amazon's "no data" for a JSON report too.
5014
+ with patch.object(cx, "report_document", return_value=(
5015
+ "", {"reportId": "cancelled", "reportDocumentId": None, "cancelled": True,
5016
+ "createdTime": _iso(end)})):
5017
+ _sync_margin_window(con, "b2b_recommended", {}, None, None, max_wait=1,
5018
+ log=lambda *_: None)
5019
+ ck("a CANCELLED JSON report lands as an empty snapshot instead of a refusal",
5020
+ con.execute("SELECT COUNT(*) FROM amzn_b2b_recommended").fetchone()[0] == 0)
5021
+ try:
5022
+ parse_json_report("", "recommendations")
5023
+ still_strict = False
5024
+ except ValueError:
5025
+ still_strict = True
5026
+ ck("NC: an empty JSON body that Amazon did NOT cancel is still refused", still_strict)
5027
  finally:
5028
  con.close()
5029
 
 
5078
  and all(read_watermark(con, table) for table in selected)
5079
  and all(checked[table]["state"] == "ok" for table in selected)
5080
  and not needs_first_load(rt.key, rt))
5081
+ # HOTFIX 2026-09-29 (D-3496): a load left unfinished ONLY by a report Amazon refused is
5082
+ # no longer owed, so a restart stops queueing it and the scheduled producer stops
5083
+ # deferring every loaded table to it. The refused table is still retried by a pass.
5084
+ refused_table = "account_health"
5085
+ con.execute("DELETE FROM _sync_state WHERE entity=?",
5086
+ [entity_key(WATERMARK_PREFIX + refused_table)])
5087
+ _record_state(con, entity_key(refused_table), "refused", 0, "fixture refusal")
5088
+ _record_state(con, entity_key(FIRST_LOAD_END_KEY), "failed", detail=_iso(end))
5089
+ ck("a load left unfinished only by a refused report is no longer owed",
5090
+ not needs_first_load(rt.key, rt))
5091
+ con.execute("DELETE FROM _sync_state WHERE entity=?", [entity_key(refused_table)])
5092
+ ck("NC: the same table never refused (no watermark) still owes a first load",
5093
+ needs_first_load(rt.key, rt))
5094
  finally:
5095
  con.close()
5096
 
platform/harness/datastore.py CHANGED
@@ -1314,6 +1314,18 @@ def reconcile_deletes(entities=None, log=print):
1314
  out = {}
1315
  for key in (entities or list(ENTITIES)):
1316
  spec = ENTITIES[key]
 
 
 
 
 
 
 
 
 
 
 
 
1317
  live_ids, last = set(), 0
1318
  while True:
1319
  recs = O.search_read(spec["model"], _base_domain(spec) + [("id", ">", last)],
 
1314
  out = {}
1315
  for key in (entities or list(ENTITIES)):
1316
  spec = ENTITIES[key]
1317
+ # HOTFIX 2026-09-29: DETECT FIRST, then walk. The cursor sync has already pulled every
1318
+ # created row, so the mirror can only hold MORE rows than the source when something
1319
+ # was deleted: equal counts prove there is nothing to purge, and the full id walk
1320
+ # (1M+ ids for account_move_line) runs only for an entity whose count moved.
1321
+ try:
1322
+ source_n = O.get_odoo().search_count(spec["model"], _base_domain(spec))
1323
+ mirror_n = con.execute(f"SELECT count(*) FROM {key}").fetchone()[0]
1324
+ except Exception: # noqa: BLE001
1325
+ source_n, mirror_n = None, None
1326
+ if source_n is not None and int(source_n) == int(mirror_n):
1327
+ out[key] = 0
1328
+ continue
1329
  live_ids, last = set(), 0
1330
  while True:
1331
  recs = O.search_read(spec["model"], _base_domain(spec) + [("id", ">", last)],
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 05d11938555edd577bf1917f6498fcf0262ee61376961b071dfecde3c1e21802
 
1
+ 783906963e28be2e53b4e253baf4a2f3398b22bb7888a14a7fad040bd5a17cbe
web/src/connectors/OdooConfig.tsx CHANGED
@@ -164,6 +164,13 @@ const EVERY_LABEL: Record<string, string> = {
164
  };
165
  export const everyLabel = (k: string): string => EVERY_LABEL[k] || k;
166
 
 
 
 
 
 
 
 
167
  /** What the connection is, in one line, for the header of the panel. */
168
  export function sourceLine(cfg: OdooConfig): string {
169
  if (cfg.frozen) return "Disconnected. These databases are frozen as static data.";
@@ -291,9 +298,7 @@ export default function OdooConfigPanel({
291
  ))}
292
  </select>
293
  {cfg.syncFloorSeconds ? (
294
- <span className="conn-cadence-floor">
295
- Minimum {Math.ceil(cfg.syncFloorSeconds / 60)} minutes
296
- </span>
297
  ) : null}
298
  </div>
299
 
 
164
  };
165
  export const everyLabel = (k: string): string => EVERY_LABEL[k] || k;
166
 
167
+ /** The server's sync floor in words. Hotfix 2026-09-29: the floor is a day, not minutes. */
168
+ export function floorLabel(seconds: number): string {
169
+ if (seconds >= 86400) return "At most once a day";
170
+ if (seconds >= 3600) return `Minimum ${Math.ceil(seconds / 3600)} hours`;
171
+ return `Minimum ${Math.ceil(seconds / 60)} minutes`;
172
+ }
173
+
174
  /** What the connection is, in one line, for the header of the panel. */
175
  export function sourceLine(cfg: OdooConfig): string {
176
  if (cfg.frozen) return "Disconnected. These databases are frozen as static data.";
 
298
  ))}
299
  </select>
300
  {cfg.syncFloorSeconds ? (
301
+ <span className="conn-cadence-floor">{floorLabel(cfg.syncFloorSeconds)}</span>
 
 
302
  ) : null}
303
  </div>
304