fsanyoto commited on
Commit
ffcfecb
·
verified ·
1 Parent(s): 500275b

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "b7770dd4d587",
3
  "releases": [
4
  {
5
  "version": "v86",
 
1
  {
2
+ "current": "fde25a93ec56",
3
  "releases": [
4
  {
5
  "version": "v86",
VERSION CHANGED
@@ -1 +1 @@
1
- b7770dd4d587
 
1
+ fde25a93ec56
api/main.py CHANGED
@@ -1411,7 +1411,7 @@ def _sync_now_detail(provider, tenant, *, ok, detail="", cause=None):
1411
  return sentence + suffix
1412
 
1413
 
1414
- def _run_sync_requests(outcome=None, *, during_odoo=False):
1415
  """Drain Sync now intents on the resident resync thread, the mirror's single writer.
1416
 
1417
  D-29 / intake F6: HTTP handlers only queue intents. Provider calls stay here, before the
@@ -1493,9 +1493,12 @@ def _run_sync_requests(outcome=None, *, during_odoo=False):
1493
  return log, lines
1494
 
1495
  odoo_requested = False
 
 
1496
  # Claim only work this turn executes. A later provider remains queued with an honest wait.
1497
  pending = connector_sync.take_sync_requests(limit=1, exclude_providers=("odoo",) if during_odoo else (),
1498
- refresh_remote=True)
 
1499
  while True:
1500
  receipt = next((row for row in pending
1501
  if not during_odoo or row["provider"] != "odoo"), None)
@@ -3005,6 +3008,14 @@ def _store_resync_loop():
3005
  # H73: a tenant with a daily wall-clock slot reads Odoo only when that slot is due.
3006
  # Looked up by name so loop fixtures that list main.py defs by hand keep running slotless.
3007
  _slot = (globals().get("_resolve_resync_slot") or (lambda: None))()
 
 
 
 
 
 
 
 
3008
  _woken = False
3009
  if passes and _slot is None:
3010
  # The wait is what remains of the cadence since the last scheduled pass STARTED, so
@@ -3065,7 +3076,7 @@ def _store_resync_loop():
3065
  if _woken and (_t.time() - last_full_pass_at < _every if _slot is None else not _slot_due):
3066
  _desk = {}
3067
  _desk_started = _t.time()
3068
- if not _run_sync_requests(_desk):
3069
  _project_desk(_desk, _cad["tenant"])
3070
  if "continuing" in _desk.values():
3071
  # A floor between continuations, so a chunk that returns at once cannot spin.
@@ -3081,7 +3092,7 @@ def _store_resync_loop():
3081
  if _slot is not None and not _slot_due and _odoo_requested is None and not _continuation:
3082
  # H73: outside the slot no Odoo call is made. Serve the stored mirror, drain the desk.
3083
  _desk = {}
3084
- if _run_sync_requests(_desk):
3085
  _odoo_requested = True
3086
  else:
3087
  _project_desk(_desk, _cad["tenant"])
@@ -3105,7 +3116,7 @@ def _store_resync_loop():
3105
  last_slot_pass_at = last_full_pass_at
3106
  _slot_write(last_full_pass_at)
3107
  if _odoo_requested is None:
3108
- _odoo_requested = _run_sync_requests()
3109
  _warm_generation = _sheet_warm_generation()
3110
  _backfill_before = _backfill_read(_cad["tenant"]) if _backfill_read else None
3111
  try:
@@ -3113,6 +3124,8 @@ def _store_resync_loop():
3113
  sync_report, delete_report, _err = _resync_mirror_pass(_manual, passes, selected_entities)
3114
  except Exception as exc:
3115
  sync_report, delete_report, _err = None, None, _classify_resync_error(exc)
 
 
3116
  if _err is None and sync_report:
3117
  RESYNC_STATE["passes"] = RESYNC_STATE.get("passes", 0) + 1
3118
  _held_check = globals().get("_resync_publication_held")
 
1411
  return sentence + suffix
1412
 
1413
 
1414
+ def _run_sync_requests(outcome=None, *, during_odoo=False, hold_first_load=None):
1415
  """Drain Sync now intents on the resident resync thread, the mirror's single writer.
1416
 
1417
  D-29 / intake F6: HTTP handlers only queue intents. Provider calls stay here, before the
 
1493
  return log, lines
1494
 
1495
  odoo_requested = False
1496
+ # A first-load continuation never runs inside an Odoo pass: it requeues itself without end.
1497
+ hold = during_odoo if hold_first_load is None else hold_first_load
1498
  # Claim only work this turn executes. A later provider remains queued with an honest wait.
1499
  pending = connector_sync.take_sync_requests(limit=1, exclude_providers=("odoo",) if during_odoo else (),
1500
+ refresh_remote=True,
1501
+ exclude_requested_by=("first load",) if hold else ())
1502
  while True:
1503
  receipt = next((row for row in pending
1504
  if not during_odoo or row["provider"] != "odoo"), None)
 
3008
  # H73: a tenant with a daily wall-clock slot reads Odoo only when that slot is due.
3009
  # Looked up by name so loop fixtures that list main.py defs by hand keep running slotless.
3010
  _slot = (globals().get("_resolve_resync_slot") or (lambda: None))()
3011
+
3012
+ def _near_slot():
3013
+ # A first-load continuation does not start this close to the next Odoo slot.
3014
+ if _slot is None:
3015
+ return False
3016
+ import odoo_relational as _rel_near
3017
+ return _rel_near.slot_near(_t.time(), _slot)
3018
+
3019
  _woken = False
3020
  if passes and _slot is None:
3021
  # The wait is what remains of the cadence since the last scheduled pass STARTED, so
 
3076
  if _woken and (_t.time() - last_full_pass_at < _every if _slot is None else not _slot_due):
3077
  _desk = {}
3078
  _desk_started = _t.time()
3079
+ if not _run_sync_requests(_desk, hold_first_load=_near_slot()):
3080
  _project_desk(_desk, _cad["tenant"])
3081
  if "continuing" in _desk.values():
3082
  # A floor between continuations, so a chunk that returns at once cannot spin.
 
3092
  if _slot is not None and not _slot_due and _odoo_requested is None and not _continuation:
3093
  # H73: outside the slot no Odoo call is made. Serve the stored mirror, drain the desk.
3094
  _desk = {}
3095
+ if _run_sync_requests(_desk, hold_first_load=_near_slot()):
3096
  _odoo_requested = True
3097
  else:
3098
  _project_desk(_desk, _cad["tenant"])
 
3116
  last_slot_pass_at = last_full_pass_at
3117
  _slot_write(last_full_pass_at)
3118
  if _odoo_requested is None:
3119
+ _odoo_requested = _run_sync_requests(hold_first_load=True)
3120
  _warm_generation = _sheet_warm_generation()
3121
  _backfill_before = _backfill_read(_cad["tenant"]) if _backfill_read else None
3122
  try:
 
3124
  sync_report, delete_report, _err = _resync_mirror_pass(_manual, passes, selected_entities)
3125
  except Exception as exc:
3126
  sync_report, delete_report, _err = None, None, _classify_resync_error(exc)
3127
+ # The Odoo pull is over: the continuations it held run on the next loop turn.
3128
+ connector_sync.resume_held_requests()
3129
  if _err is None and sync_report:
3130
  RESYNC_STATE["passes"] = RESYNC_STATE.get("passes", 0) + 1
3131
  _held_check = globals().get("_resync_publication_held")
api/odoo_relational.py CHANGED
@@ -5608,6 +5608,18 @@ def slot_after(now, slot):
5608
  raise ValueError("no slot occurrence found")
5609
 
5610
 
 
 
 
 
 
 
 
 
 
 
 
 
5611
  def slot_due(now, slot, last_pass_at):
5612
  """True when no pass has started since the latest slot occurrence."""
5613
  return last_pass_at is None or float(last_pass_at) < slot_before(now, slot)
@@ -5918,6 +5930,18 @@ def sync_freshness(rt, now=None):
5918
  if allowed is not None and not cfg["frozen"]:
5919
  good_at = _parse_iso(last_good)
5920
  stale = good_at is None or (now - good_at).total_seconds() > allowed
 
 
 
 
 
 
 
 
 
 
 
 
5921
  failure = None
5922
  errors = status.get("errors") if isinstance(status.get("errors"), list) else []
5923
  if phase == "error" and errors:
@@ -5937,6 +5961,7 @@ def sync_freshness(rt, now=None):
5937
  for name in ("key", "label", "code", "message", "stage", "at")
5938
  + (("cause",) if item.get("cause") else ())})
5939
  return {"stale": bool(stale), "lastGoodSyncAt": last_good,
 
5940
  "failedDatabases": failed_databases,
5941
  "schedule": cfg["syncEvery"], "staleAfterSeconds": allowed,
5942
  "lastRunAt": status.get("lastRun") or None, "phase": phase,
 
5608
  raise ValueError("no slot occurrence found")
5609
 
5610
 
5611
+ #: A first-load continuation does not start this close to the next slot, so it cannot delay the slot.
5612
+ FIRST_LOAD_SLOT_QUIET_SECONDS = 2 * 3600
5613
+
5614
+ #: A slot whose pass has not ended good this long after it is LATE, and the watchdog alerts.
5615
+ SLOT_LATE_SECONDS = 90 * 60
5616
+
5617
+
5618
+ def slot_near(now, slot, seconds=FIRST_LOAD_SLOT_QUIET_SECONDS):
5619
+ """True when the next slot occurrence is at most `seconds` after epoch `now`."""
5620
+ return slot is not None and slot_after(now, slot) - float(now) <= seconds
5621
+
5622
+
5623
  def slot_due(now, slot, last_pass_at):
5624
  """True when no pass has started since the latest slot occurrence."""
5625
  return last_pass_at is None or float(last_pass_at) < slot_before(now, slot)
 
5930
  if allowed is not None and not cfg["frozen"]:
5931
  good_at = _parse_iso(last_good)
5932
  stale = good_at is None or (now - good_at).total_seconds() > allowed
5933
+ # A daily slot that passed SLOT_LATE_SECONDS ago with no good sync since is late, not fresh.
5934
+ late_slot = None
5935
+ slot = sync_slot(cfg)
5936
+ if slot is not None and not cfg["frozen"] and not stale:
5937
+ try:
5938
+ due = slot_before(now.timestamp(), slot)
5939
+ except Exception: # noqa: BLE001
5940
+ due = None
5941
+ good_at = _parse_iso(last_good)
5942
+ if (due is not None and now.timestamp() - due > SLOT_LATE_SECONDS
5943
+ and (good_at is None or good_at.timestamp() < due)):
5944
+ late_slot = slot_iso(due)
5945
  failure = None
5946
  errors = status.get("errors") if isinstance(status.get("errors"), list) else []
5947
  if phase == "error" and errors:
 
5961
  for name in ("key", "label", "code", "message", "stage", "at")
5962
  + (("cause",) if item.get("cause") else ())})
5963
  return {"stale": bool(stale), "lastGoodSyncAt": last_good,
5964
+ "late": late_slot is not None, "lateSlotAt": late_slot,
5965
  "failedDatabases": failed_databases,
5966
  "schedule": cfg["syncEvery"], "staleAfterSeconds": allowed,
5967
  "lastRunAt": status.get("lastRun") or None, "phase": phase,
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):
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'))
@@ -828,7 +828,8 @@ class RankRefreshTests(unittest.TestCase):
828
  with patch.dict(sys.modules, {'time': clock, 'harness.runtime': runtime}), \
829
  patch.object(harness, 'runtime', runtime, create=True), \
830
  patch.object(connector_sync, 'sync_wake_event', return_value=wake), \
831
- patch.object(connector_sync, 'take_sync_requests', return_value=[]), \
 
832
  redirect_stdout(out):
833
  with self.assertRaisesRegex(StopIteration, 'bounded synthetic'):
834
  ns['_store_resync_loop']()
@@ -967,6 +968,69 @@ class RankRefreshTests(unittest.TestCase):
967
  tzinfo=timezone.utc))['nextSyncAt'],
968
  '2026-10-25T07:30:00Z')
969
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
970
 
971
  def test_h1_a_held_backfill_that_moved_queues_one_odoo_only_pass(self):
972
  """H1: a held backfill that moved runs again 60s later, Odoo only and unstamped; no progress stops"""
 
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'))
 
828
  with patch.dict(sys.modules, {'time': clock, 'harness.runtime': runtime}), \
829
  patch.object(harness, 'runtime', runtime, create=True), \
830
  patch.object(connector_sync, 'sync_wake_event', return_value=wake), \
831
+ patch.object(connector_sync, 'take_sync_requests',
832
+ **({'new': take} if take else {'return_value': []})), \
833
  redirect_stdout(out):
834
  with self.assertRaisesRegex(StopIteration, 'bounded synthetic'):
835
  ns['_store_resync_loop']()
 
968
  tzinfo=timezone.utc))['nextSyncAt'],
969
  '2026-10-25T07:30:00Z')
970
 
971
+ def test_first_load_never_runs_at_the_slot_claim_or_in_the_quiet_window(self):
972
+ """Live 10-29: an Amazon first-load chunk held the 06:00Z slot to 08:12Z. It is held near and at the slot"""
973
+ last = self.utc('2026-10-23T06:05:00Z')
974
+ held = []
975
+ take = lambda **kwargs: held.append(tuple(kwargs.get('exclude_requested_by') or ())) or []
976
+ _events, _sleeps, odoo = self.run_slot_loop(
977
+ {'passAt': last, 'fullRebuildAt': last, 'fingerprints': {'res_partner': (3, 7)}},
978
+ boot=self.utc('2026-10-24T04:30:00Z'), max_sleeps=2, take=take)
979
+ self.assertTrue(odoo, 'the slot pass ran')
980
+ # Boot 90 min before the slot: the drain outside the slot holds first load, and so does the claim.
981
+ self.assertTrue(len(held) >= 2 and all(h == ('first load',) for h in held), held)
982
+
983
+ def test_first_load_runs_far_from_the_slot(self):
984
+ """A first-load continuation keeps running when the next slot is more than two hours away"""
985
+ last = self.utc('2026-10-23T06:05:00Z')
986
+ held = []
987
+ take = lambda **kwargs: held.append(tuple(kwargs.get('exclude_requested_by') or ())) or []
988
+ self.run_slot_loop({'passAt': last, 'fullRebuildAt': last, 'fingerprints': {'res_partner': (3, 7)}},
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
995
+ import odoo_relational as rel
996
+ slot = rel.sync_slot(rel.read_config(self.SlotStore('royal-imports')))
997
+ self.assertTrue(rel.slot_near(self.utc('2026-10-24T04:00:00Z'), slot))
998
+ self.assertFalse(rel.slot_near(self.utc('2026-10-24T03:59:00Z'), slot))
999
+ self.assertFalse(rel.slot_near(self.utc('2026-10-24T06:00:01Z'), slot))
1000
+ live = self.SlotStore('royal-imports', {rel.CONFIG_KEY: {'lastGoodSyncAt': '2026-10-28T19:44:42+00:00'}})
1001
+ at = lambda h, m: datetime(2026, 10, 29, h, m, tzinfo=timezone.utc)
1002
+ self.assertFalse(rel.sync_freshness(live, now=at(7, 29))['late'])
1003
+ late = rel.sync_freshness(live, now=at(7, 31))
1004
+ self.assertEqual((late['late'], late['lateSlotAt'], late['stale']), (True, '2026-10-29T06:00:00Z', False))
1005
+ done = self.SlotStore('royal-imports', {rel.CONFIG_KEY: {'lastGoodSyncAt': '2026-10-29T06:38:05+00:00'}})
1006
+ self.assertFalse(rel.sync_freshness(done, now=at(8, 30))['late'])
1007
+ frozen = self.SlotStore('royal-imports', {rel.CONFIG_KEY: {'lastGoodSyncAt': '2026-10-28T19:44:42+00:00',
1008
+ 'frozen': True}})
1009
+ self.assertFalse(rel.sync_freshness(frozen, now=at(8, 30))['late'])
1010
+
1011
+ def test_a_held_first_load_stays_queued_and_wakes_nobody(self):
1012
+ """The desk leaves a held first load queued, claims a click, and wakes the loop only on resume"""
1013
+ from core import connector_sync as desk
1014
+ saved = dict(desk._SYNC_REQUESTS)
1015
+ desk._SYNC_REQUESTS.clear()
1016
+ desk._SYNC_WAKE.clear()
1017
+ try:
1018
+ with patch.dict(desk._PROVIDERS, {'amazon_sp': desk._PROVIDERS.get('amazon_sp', {}),
1019
+ 'meta_ads': desk._PROVIDERS.get('meta_ads', {})}):
1020
+ desk.request_sync('amazon_sp', 't-hold', requested_by='first load', now=100)
1021
+ desk.request_sync('meta_ads', 't-hold', requested_by='admin', now=101)
1022
+ desk._SYNC_WAKE.clear()
1023
+ claimed = desk.take_sync_requests(now=200, exclude_requested_by=('first load',))
1024
+ self.assertEqual([r['provider'] for r in claimed], ['meta_ads'])
1025
+ self.assertEqual(desk.sync_request('amazon_sp', 't-hold')['state'], 'queued')
1026
+ self.assertFalse(desk.sync_wake_event().is_set())
1027
+ desk.resume_held_requests(now=300)
1028
+ self.assertTrue(desk.sync_wake_event().is_set())
1029
+ self.assertEqual([r['provider'] for r in desk.take_sync_requests(now=300)], ['amazon_sp'])
1030
+ finally:
1031
+ desk._SYNC_REQUESTS.clear()
1032
+ desk._SYNC_REQUESTS.update(saved)
1033
+ desk._SYNC_WAKE.clear()
1034
 
1035
  def test_h1_a_held_backfill_that_moved_queues_one_odoo_only_pass(self):
1036
  """H1: a held backfill that moved runs again 60s later, Odoo only and unstamped; no progress stops"""
platform/core/connector_sync.py CHANGED
@@ -79,13 +79,20 @@ def _cache_sync_requests(rt, document):
79
  _SYNC_REQUEST_RUNTIMES[rt.key] = rt
80
 
81
 
82
- def _wake_sync_requests(stamp):
83
  _arm_sync_wake(stamp)
84
  if any(row["state"] == "queued" and (row.get("notBefore") or 0) <= stamp
 
85
  for row in _SYNC_REQUESTS.values()):
86
  _SYNC_WAKE.set()
87
 
88
 
 
 
 
 
 
 
89
  def restore_sync_requests(rt, *, now=None, requeue=True):
90
  """Restore durable events and requeue claims abandoned by a previous process.
91
 
@@ -273,8 +280,12 @@ def sync_request(provider, tenant):
273
  return {**_request_wait(receipt), "accepted": False}
274
 
275
 
276
- def take_sync_requests(*, now=None, limit=None, exclude_providers=(), refresh_remote=False):
277
- """Claim manual work first, preserving provider floors, tenant claims and event siblings."""
 
 
 
 
278
  if refresh_remote:
279
  with _SYNC_REQUEST_LOCK:
280
  runtimes = list(_SYNC_REQUEST_RUNTIMES.values())
@@ -294,6 +305,7 @@ def take_sync_requests(*, now=None, limit=None, exclude_providers=(), refresh_re
294
  break
295
  pair = (receipt["provider"], receipt["tenant"])
296
  if (receipt["provider"] in exclude_providers or pair in busy or receipt["state"] != "queued"
 
297
  or max(receipt.get("notBefore") or 0, _SYNC_NOT_BEFORE.get(pair, 0)) > stamp):
298
  continue
299
  if receipt.get("tables") is not None:
@@ -325,7 +337,7 @@ def take_sync_requests(*, now=None, limit=None, exclude_providers=(), refresh_re
325
  receipt["detail"] = ""
326
  claimed.append(deepcopy(receipt))
327
  busy.add(pair)
328
- _wake_sync_requests(stamp)
329
  return claimed
330
 
331
 
 
79
  _SYNC_REQUEST_RUNTIMES[rt.key] = rt
80
 
81
 
82
+ def _wake_sync_requests(stamp, held=()):
83
  _arm_sync_wake(stamp)
84
  if any(row["state"] == "queued" and (row.get("notBefore") or 0) <= stamp
85
+ and row.get("requestedBy") not in held
86
  for row in _SYNC_REQUESTS.values()):
87
  _SYNC_WAKE.set()
88
 
89
 
90
+ def resume_held_requests(now=None):
91
+ """Wake the resident loop for queued work a hold left waiting."""
92
+ with _SYNC_REQUEST_LOCK:
93
+ _wake_sync_requests(time.time() if now is None else now)
94
+
95
+
96
  def restore_sync_requests(rt, *, now=None, requeue=True):
97
  """Restore durable events and requeue claims abandoned by a previous process.
98
 
 
280
  return {**_request_wait(receipt), "accepted": False}
281
 
282
 
283
+ def take_sync_requests(*, now=None, limit=None, exclude_providers=(), refresh_remote=False,
284
+ exclude_requested_by=()):
285
+ """Claim manual work first, preserving provider floors, tenant claims and event siblings.
286
+
287
+ `exclude_requested_by` leaves those receipts queued and does not wake the loop for them.
288
+ """
289
  if refresh_remote:
290
  with _SYNC_REQUEST_LOCK:
291
  runtimes = list(_SYNC_REQUEST_RUNTIMES.values())
 
305
  break
306
  pair = (receipt["provider"], receipt["tenant"])
307
  if (receipt["provider"] in exclude_providers or pair in busy or receipt["state"] != "queued"
308
+ or receipt.get("requestedBy") in exclude_requested_by
309
  or max(receipt.get("notBefore") or 0, _SYNC_NOT_BEFORE.get(pair, 0)) > stamp):
310
  continue
311
  if receipt.get("tables") is not None:
 
337
  receipt["detail"] = ""
338
  claimed.append(deepcopy(receipt))
339
  busy.add(pair)
340
+ _wake_sync_requests(stamp, exclude_requested_by)
341
  return claimed
342
 
343
 
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 45c6e82285ea1f609ec00848a159373540039d93b30340c79ae8b05cb83de8e5
 
1
+ d8f35831618f4a501f88d7e9ea9acf318ce9f938d4c039544d8fd176d6930217