fsanyoto commited on
Commit
5007b7e
·
verified ·
1 Parent(s): fafdf95

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "3743bd155",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "90ce47259",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- 3743bd155
 
1
+ 90ce47259
api/main.py CHANGED
@@ -2472,6 +2472,15 @@ def _store_resync_loop():
2472
  RESYNC_STATE["consecutiveFailures"] = 0
2473
  if not _manual:
2474
  RESYNC_STATE["lastSuccessAt"] = RESYNC_STATE["lastPassAt"]
 
 
 
 
 
 
 
 
 
2475
  else:
2476
  RESYNC_STATE["consecutiveFailures"] = int(RESYNC_STATE["consecutiveFailures"]) + 1
2477
  # D-314: the TYPE and the persistent/transient reading, both in the line and in the
 
2472
  RESYNC_STATE["consecutiveFailures"] = 0
2473
  if not _manual:
2474
  RESYNC_STATE["lastSuccessAt"] = RESYNC_STATE["lastPassAt"]
2475
+ # A published pull is the Odoo source stage's success, so the receipt's source stamp follows it.
2476
+ try:
2477
+ from harness import runtime as _source_runtime
2478
+ import routes_connectors as _source_receipts
2479
+ _source_receipts.record_odoo_stage(
2480
+ _source_runtime.get_runtime(_cad["tenant"]), RESYNC_STATE["connectionId"] or "default",
2481
+ "source", "ready", at=RESYNC_STATE["lastPassAt"], cadence_seconds=_every)
2482
+ except Exception: # noqa: BLE001
2483
+ pass # The resident mirror state above still reports this pass.
2484
  else:
2485
  RESYNC_STATE["consecutiveFailures"] = int(RESYNC_STATE["consecutiveFailures"]) + 1
2486
  # D-314: the TYPE and the persistent/transient reading, both in the line and in the
api/routes_connectors.py CHANGED
@@ -3561,13 +3561,69 @@ def _odoo_database_sync_health(raw, enabled=True, *, now=None):
3561
  source_stage = stages.get("source") if isinstance(stages.get("source"), dict) else {}
3562
  material_stage = (stages.get("materialization")
3563
  if isinstance(stages.get("materialization"), dict) else {})
 
 
 
 
3564
  return _database_sync_health(
3565
  enabled=enabled, state=state, last_success=last_success,
3566
- source_timestamp=source_stage.get("lastSuccess"),
3567
  materialized_timestamp=material_stage.get("lastSuccess"),
3568
  row_count=row.get("rowCount"), error=failure, now=now)
3569
 
3570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3571
  def _amazon_database_sync_health(raw, enabled=True, *, now=None, database_key=""):
3572
  if not enabled:
3573
  return _database_sync_health(enabled=False)
@@ -4950,6 +5006,9 @@ def connector_detail(rt, user, uname, is_admin, connector_key, *, databases_offs
4950
  budget.check()
4951
  sync_health = (_odoo_database_sync_health({**rt.odoo_health, "rowCount": None}) if key == "odoo" else
4952
  page.sync_health if page is not None else _databases_sync_health(databases))
 
 
 
4953
  overview = _detail_overview(row, databases, graph, sync_health=sync_health)
4954
  if page is not None and page.total:
4955
  overview["creates"] = page.creates
 
3561
  source_stage = stages.get("source") if isinstance(stages.get("source"), dict) else {}
3562
  material_stage = (stages.get("materialization")
3563
  if isinstance(stages.get("materialization"), dict) else {})
3564
+ pull_stage = stages.get("mirrorPull") if isinstance(stages.get("mirrorPull"), dict) else {}
3565
+ # The source stamp is the last PUBLISHED pull: a held or failed mirror pass never sets lastSuccessAt.
3566
+ pulls = [stamp for stamp in (_sync_stamp(source_stage.get("lastSuccess")),
3567
+ _sync_stamp(pull_stage.get("lastSuccess"))) if stamp]
3568
  return _database_sync_health(
3569
  enabled=enabled, state=state, last_success=last_success,
3570
+ source_timestamp=max(pulls) if pulls else None,
3571
  materialized_timestamp=material_stage.get("lastSuccess"),
3572
  row_count=row.get("rowCount"), error=failure, now=now)
3573
 
3574
 
3575
+ def _odoo_warning_sentence(checks):
3576
+ """Name the published Odoo validation's warning rows in a few plain words, or return None."""
3577
+ parts = []
3578
+ for row in checks if isinstance(checks, (list, tuple)) else ():
3579
+ if not isinstance(row, dict) or row.get("state") != "warning":
3580
+ continue
3581
+ name = row.get("check")
3582
+ diffs = row.get("diffs") if isinstance(row.get("diffs"), (list, tuple)) else []
3583
+ found = []
3584
+ if name == "ledger_balance":
3585
+ for diff in diffs:
3586
+ diff = diff if isinstance(diff, dict) else {}
3587
+ if "missing_columns" in diff or "invalid_ledger_lines" in diff:
3588
+ found.append("Odoo ledger could not be checked")
3589
+ continue
3590
+ try:
3591
+ amount = float(diff.get("difference", diff.get("balance")))
3592
+ except (TypeError, ValueError):
3593
+ amount = None
3594
+ company = diff.get("company_id")
3595
+ place = (f" in company {company}" if isinstance(company, (int, str))
3596
+ and not isinstance(company, bool) and str(company) else "")
3597
+ found.append(f"Odoo ledger is off by {amount:,.2f}{place}" if amount is not None
3598
+ else f"Odoo ledger does not balance{place}")
3599
+ found = found or ["Odoo ledger does not balance"]
3600
+ elif name == "unmapped_accounts":
3601
+ count = len(diffs)
3602
+ found.append(f"Odoo has {count} {'line' if count == 1 else 'lines'} with unmapped accounts"
3603
+ if count else "Odoo has lines with unmapped accounts")
3604
+ elif name == "closed_period_balances":
3605
+ count = len(diffs)
3606
+ found.append(f"Odoo changed {count} closed period {'balance' if count == 1 else 'balances'}"
3607
+ if count else "Odoo changed closed period balances")
3608
+ parts.extend(text for text in found if text not in parts)
3609
+ if not parts:
3610
+ return None
3611
+ more = len(parts) - 1
3612
+ return parts[0] + (f" and {more} more Odoo data {'warning' if more == 1 else 'warnings'}" if more else "")
3613
+
3614
+
3615
+ def _odoo_data_warning(rt):
3616
+ """The published Odoo snapshot's warning sentence; any read failure gives None, never a 500."""
3617
+ try:
3618
+ from harness import mirror_store
3619
+ store_rt = getattr(rt, "runtime", rt)
3620
+ status = mirror_store.publication_status("odoo", getattr(store_rt, "key", None), store_rt)
3621
+ validation = status.get("validation") if isinstance(status, dict) else None
3622
+ return _odoo_warning_sentence(validation.get("checks") if isinstance(validation, dict) else None)
3623
+ except Exception: # noqa: BLE001
3624
+ return None
3625
+
3626
+
3627
  def _amazon_database_sync_health(raw, enabled=True, *, now=None, database_key=""):
3628
  if not enabled:
3629
  return _database_sync_health(enabled=False)
 
5006
  budget.check()
5007
  sync_health = (_odoo_database_sync_health({**rt.odoo_health, "rowCount": None}) if key == "odoo" else
5008
  page.sync_health if page is not None else _databases_sync_health(databases))
5009
+ if key == "odoo":
5010
+ # An Odoo data warning is shown, never a reason to stop the sync. Its amount is for Administrators only.
5011
+ sync_health = {**sync_health, "warning": _odoo_data_warning(rt) if is_admin else None}
5012
  overview = _detail_overview(row, databases, graph, sync_health=sync_health)
5013
  if page is not None and page.total:
5014
  overview["creates"] = page.creates
platform/harness/datastore.py CHANGED
@@ -548,7 +548,9 @@ def check_odoo_snapshot(rt, candidate, published, row_counts):
548
  checks = []
549
 
550
  def record(name, diffs=(), **details):
551
- checks.append({"check": name, "state": "failed" if diffs else "passed",
 
 
552
  "diffs": list(diffs), **details})
553
 
554
  def columns(con, table):
@@ -594,6 +596,19 @@ def check_odoo_snapshot(rt, candidate, published, row_counts):
594
  balance_diffs.append(item)
595
  elif not balanced and company in exceptions:
596
  accepted.append({**item, "reason": exceptions[company]["reason"]})
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  if invalid:
598
  balance_diffs.append({"invalid_ledger_lines": invalid})
599
  record("ledger_balance", balance_diffs, exceptions=accepted)
 
548
  checks = []
549
 
550
  def record(name, diffs=(), **details):
551
+ # A check of Odoo's own ledger reports a warning and never holds a sync. Only our copy's row drop fails.
552
+ found = "failed" if name == "row_count_drop" else "warning"
553
+ checks.append({"check": name, "state": found if diffs else "passed",
554
  "diffs": list(diffs), **details})
555
 
556
  def columns(con, table):
 
596
  balance_diffs.append(item)
597
  elif not balanced and company in exceptions:
598
  accepted.append({**item, "reason": exceptions[company]["reason"]})
599
+ move_cols = ledger & {"move_id", "move_name"}
600
+ if "move_id" in move_cols:
601
+ # Name the posted moves whose own lines do not sum to zero: that is the cause in Odoo.
602
+ named = ", any_value(move_name)" if "move_name" in move_cols else ""
603
+ for item in balance_diffs:
604
+ moves = candidate.execute(
605
+ f"SELECT move_id, sum(CAST(balance AS DECIMAL(38,6))) AS total{named} FROM account_move_line "
606
+ f"WHERE {where} AND isfinite(balance) AND company_id=? AND move_id IS NOT NULL "
607
+ "GROUP BY move_id HAVING abs(sum(CAST(balance AS DECIMAL(38,6)))) > ? ORDER BY abs(total) DESC, move_id",
608
+ [item["company_id"], Decimal(str(policy["balance_tolerance"]))]).fetchall()
609
+ item["unbalanced_moves"] = len(moves)
610
+ item["moves"] = [{"move_id": row[0], **({"move_name": row[2]} if named else {}),
611
+ "balance": float(row[1])} for row in moves[:10]]
612
  if invalid:
613
  balance_diffs.append({"invalid_ledger_lines": invalid})
614
  record("ledger_balance", balance_diffs, exceptions=accepted)
platform/harness/mirror_store.py CHANGED
@@ -856,8 +856,6 @@ class MirrorStore:
856
  return # The enclosing source pass owns publication after every table completes.
857
  uploaded = 0
858
  with self.lock:
859
- if _held_manifest(self, tenant_key, rt):
860
- raise PublicationHeld("Release the held snapshot before syncing this source.")
861
  cache = self.restore_mirror(tenant_key, rt, log=log)
862
  cache["dirty"].update(changed_tables)
863
  try:
@@ -941,13 +939,22 @@ class MirrorStore:
941
  **(_publication or {}))
942
  if _publication is not None:
943
  manifest["completed_at"] = stamp
944
- published = _mirror_json(manifest)
945
  if _hold is not None:
946
  manifest["hold"] = _hold
947
  rt.upload_bytes(self.prefix + _HELD_KEY, _mirror_json(manifest))
948
  return manifest
 
 
 
 
949
  rt.upload_bytes(self.prefix + _MANIFEST_KEY, published)
950
  uploaded += len(published)
 
 
 
 
 
 
951
  if _publication is None:
952
  datastore._write_publication(con, self.connector, manifest)
953
  cache["manifest"] = manifest
@@ -1016,9 +1023,31 @@ def _held_manifest(store, tenant_key, rt):
1016
  if (published.get("tenant") == tenant_key and published.get("snapshot_id") == held["snapshot_id"]
1017
  and published.get("release")):
1018
  return None
 
 
 
 
1019
  return held
1020
 
1021
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  def _publication_summary(manifest):
1023
  return {**{key: manifest.get(key) or "unknown" for key in
1024
  ("snapshot_id", "started_at", "completed_at", "state")},
@@ -1194,8 +1223,6 @@ def sync_mirror(connector, tenant_key, rt, *, report=None, log=print, before_pub
1194
  with store.lock:
1195
  if getattr(datastore._SYNC_TLS, "candidate", None) is not None:
1196
  raise RuntimeError("A source publication is already active on this thread")
1197
- if _held_manifest(store, tenant_key, rt):
1198
- raise PublicationHeld("Release the held snapshot before syncing this source.")
1199
  restored = store.restore_mirror(tenant_key, rt, log=log)
1200
  if restored["state"] == "refused":
1201
  raise RuntimeError("The saved mirror could not be restored. Repair store access and restart.")
@@ -1273,8 +1300,9 @@ def sync_mirror(connector, tenant_key, rt, *, report=None, log=print, before_pub
1273
  validating = time.monotonic()
1274
  metadata["validation"] = datastore.check_odoo_snapshot(rt, candidate, published, metadata["rows"])
1275
  failed = [row["check"] for row in metadata["validation"]["checks"] if row["state"] == "failed"]
1276
- note("validation " + ("failed" if failed else "passed"), validating,
1277
- names=(lambda: failed) if failed else None)
 
1278
  if failed:
1279
  prior = _publication_summary(datastore._publication(published, store.connector))
1280
  hold = {"previous_snapshot_id": prior["snapshot_id"], "previous_publication": prior,
@@ -1286,7 +1314,8 @@ def sync_mirror(connector, tenant_key, rt, *, report=None, log=print, before_pub
1286
  if key != "rows"}, _hold=hold)
1287
  if not held:
1288
  raise RuntimeError("The failed candidate could not be saved. " + "; ".join(result["problems"]))
1289
- raise PublicationHeld("Snapshot held: " + ", ".join(failed) + ". Release held snapshot requires an Administrator.")
 
1290
  metadata.pop("rows")
1291
  metadata["completed_at"] = _iso(datetime.now(timezone.utc))
1292
  result = {"problems": []}
 
856
  return # The enclosing source pass owns publication after every table completes.
857
  uploaded = 0
858
  with self.lock:
 
 
859
  cache = self.restore_mirror(tenant_key, rt, log=log)
860
  cache["dirty"].update(changed_tables)
861
  try:
 
939
  **(_publication or {}))
940
  if _publication is not None:
941
  manifest["completed_at"] = stamp
 
942
  if _hold is not None:
943
  manifest["hold"] = _hold
944
  rt.upload_bytes(self.prefix + _HELD_KEY, _mirror_json(manifest))
945
  return manifest
946
+ superseded = _superseded_hold(self, tenant_key, rt)
947
+ if superseded:
948
+ manifest["superseded_hold"] = superseded
949
+ published = _mirror_json(manifest)
950
  rt.upload_bytes(self.prefix + _MANIFEST_KEY, published)
951
  uploaded += len(published)
952
+ if superseded is not None:
953
+ # A newer publication replaces a stored hold. Nobody has to release it.
954
+ try:
955
+ rt.delete_path(self.prefix + _HELD_KEY)
956
+ except Exception: # noqa: BLE001
957
+ log(f"{self.label} superseded hold pointer stays until the next publication")
958
  if _publication is None:
959
  datastore._write_publication(con, self.connector, manifest)
960
  cache["manifest"] = manifest
 
1023
  if (published.get("tenant") == tenant_key and published.get("snapshot_id") == held["snapshot_id"]
1024
  and published.get("release")):
1025
  return None
1026
+ # A publication that already superseded this hold leaves only a stale pointer.
1027
+ if (published.get("tenant") == _tenant_key(tenant_key) and isinstance(published.get("superseded_hold"), dict)
1028
+ and published["superseded_hold"].get("snapshot_id") == held["snapshot_id"]):
1029
+ return None
1030
  return held
1031
 
1032
 
1033
+ def _superseded_hold(store, tenant_key, rt):
1034
+ """Describe the stored hold a new publication replaces: None if there is none, {} for a stale pointer."""
1035
+ try:
1036
+ if rt.download_bytes(store.prefix + _HELD_KEY) is None:
1037
+ return None
1038
+ except Exception: # noqa: BLE001
1039
+ return None
1040
+ try:
1041
+ held = _held_manifest(store, tenant_key, rt)
1042
+ except Exception: # noqa: BLE001
1043
+ # An unreadable hold is deleted with the publication, never a crash.
1044
+ return {"snapshot_id": "unknown", "held_at": "unknown", "failed_checks": [], "unreadable": True}
1045
+ if held is None:
1046
+ return {}
1047
+ return {"snapshot_id": held["snapshot_id"], "held_at": held["hold"].get("held_at") or "unknown",
1048
+ "failed_checks": list(held["hold"].get("failed_checks") or [])}
1049
+
1050
+
1051
  def _publication_summary(manifest):
1052
  return {**{key: manifest.get(key) or "unknown" for key in
1053
  ("snapshot_id", "started_at", "completed_at", "state")},
 
1223
  with store.lock:
1224
  if getattr(datastore._SYNC_TLS, "candidate", None) is not None:
1225
  raise RuntimeError("A source publication is already active on this thread")
 
 
1226
  restored = store.restore_mirror(tenant_key, rt, log=log)
1227
  if restored["state"] == "refused":
1228
  raise RuntimeError("The saved mirror could not be restored. Repair store access and restart.")
 
1300
  validating = time.monotonic()
1301
  metadata["validation"] = datastore.check_odoo_snapshot(rt, candidate, published, metadata["rows"])
1302
  failed = [row["check"] for row in metadata["validation"]["checks"] if row["state"] == "failed"]
1303
+ warned = [row["check"] for row in metadata["validation"]["checks"] if row["state"] == "warning"]
1304
+ note("validation " + ("failed" if failed else "passed with warnings" if warned else "passed"),
1305
+ validating, names=(lambda: failed or warned) if failed or warned else None)
1306
  if failed:
1307
  prior = _publication_summary(datastore._publication(published, store.connector))
1308
  hold = {"previous_snapshot_id": prior["snapshot_id"], "previous_publication": prior,
 
1314
  if key != "rows"}, _hold=hold)
1315
  if not held:
1316
  raise RuntimeError("The failed candidate could not be saved. " + "; ".join(result["problems"]))
1317
+ raise PublicationHeld("Snapshot held: " + ", ".join(failed) + ". The previous snapshot is kept "
1318
+ "and the next pass checks again.")
1319
  metadata.pop("rows")
1320
  metadata["completed_at"] = _iso(datetime.now(timezone.utc))
1321
  result = {"problems": []}
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 26bc1979c690ddeed82695d659f7292f420157c5091a7a294e7aef35fdbf4901
 
1
+ d68e1f654f4af5fafc6220cea354bd6a23ba8130013285950b6d0044bc4a3257
web/src/connectors/ConnectorModal.tsx CHANGED
@@ -725,6 +725,8 @@ export function ConnectorOverviewPanel({
725
  const failed = state === "failed" || state === "partial";
726
  const status = failed ? "Sync failed" : state === "running" ? "Syncing"
727
  : state === "queued" ? "Queued" : accessSentence(keychain, overview.status, overview.key);
 
 
728
  return (
729
  <div className="conn-settings-overview">
730
  <header className="conn-settings-header" aria-label="Connection status">
@@ -735,9 +737,10 @@ export function ConnectorOverviewPanel({
735
  <span className="conn-settings-status" data-sync-state={state || overview.status}
736
  data-tone={failed ? "error" : state === "running" || state === "queued" ? "active" : "neutral"}
737
  role="status">{status}</span>
738
- <span className="conn-settings-last-success">Last good sync {health?.lastSuccess
739
- ? <time dateTime={health.lastSuccess}>{readableSyncStamp(health.lastSuccess)}</time>
740
  : "not recorded"}</span>
 
741
  </div>
742
  </div>
743
  {isAdmin && detail.syncNow && onSyncNow ? (
 
725
  const failed = state === "failed" || state === "partial";
726
  const status = failed ? "Sync failed" : state === "running" ? "Syncing"
727
  : state === "queued" ? "Queued" : accessSentence(keychain, overview.status, overview.key);
728
+ // Last good sync is the last published source pull. Only a source with no such stamp (Amazon) falls back.
729
+ const lastGood = health?.sourceTimestamp ?? health?.lastSuccess ?? null;
730
  return (
731
  <div className="conn-settings-overview">
732
  <header className="conn-settings-header" aria-label="Connection status">
 
737
  <span className="conn-settings-status" data-sync-state={state || overview.status}
738
  data-tone={failed ? "error" : state === "running" || state === "queued" ? "active" : "neutral"}
739
  role="status">{status}</span>
740
+ <span className="conn-settings-last-success">Last good sync {lastGood
741
+ ? <time dateTime={lastGood}>{readableSyncStamp(lastGood)}</time>
742
  : "not recorded"}</span>
743
+ {health?.warning ? <span className="conn-settings-warning" role="note">{health.warning}</span> : null}
744
  </div>
745
  </div>
746
  {isAdmin && detail.syncNow && onSyncNow ? (
web/src/connectors/DatabasesTab.tsx CHANGED
@@ -104,6 +104,7 @@ export interface DatabaseSyncHealth {
104
  rowCount: number | null;
105
  lagSeconds: number | null;
106
  error: { code: string; message: string } | null;
 
107
  }
108
 
109
  function syncObject(value: unknown): Record<string, unknown> {
@@ -257,6 +258,7 @@ export function parseDatabaseSyncHealth(value: unknown): DatabaseSyncHealth | nu
257
  rowCount: syncCount(raw.rowCount),
258
  lagSeconds,
259
  error: errorCode && errorMessage ? { code: errorCode, message: errorMessage } : null,
 
260
  };
261
  }
262
 
 
104
  rowCount: number | null;
105
  lagSeconds: number | null;
106
  error: { code: string; message: string } | null;
107
+ warning?: string | null;
108
  }
109
 
110
  function syncObject(value: unknown): Record<string, unknown> {
 
258
  rowCount: syncCount(raw.rowCount),
259
  lagSeconds,
260
  error: errorCode && errorMessage ? { code: errorCode, message: errorMessage } : null,
261
+ warning: syncText(raw.warning).trim() || null,
262
  };
263
  }
264
 
web/src/styles/sdlc74/connectors.css CHANGED
@@ -23,6 +23,12 @@
23
  font-size: var(--lp-fs-2xs);
24
  }
25
 
 
 
 
 
 
 
26
  .conn-settings-account-name {
27
  color: var(--lp-ink);
28
  font-size: var(--lp-fs-md);
 
23
  font-size: var(--lp-fs-2xs);
24
  }
25
 
26
+ .conn-settings-warning {
27
+ color: var(--lp-ink);
28
+ font-size: var(--lp-fs-2xs);
29
+ font-weight: var(--lp-fw-semibold);
30
+ }
31
+
32
  .conn-settings-account-name {
33
  color: var(--lp-ink);
34
  font-size: var(--lp-fs-md);