fsanyoto commited on
Commit
4082b56
·
verified ·
1 Parent(s): db44b32

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "50fe127fc",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "9da9a5ca9",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- 50fe127fc
 
1
+ 9da9a5ca9
api/routes_sheet.py CHANGED
@@ -1900,6 +1900,45 @@ def _snapshot_cell(cell, snapshot):
1900
  cell.update(deepcopy(snapshot))
1901
 
1902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1903
  def _source_snapshot_stale(session, hit):
1904
  """Compare source tokens once per request without resolving any bindings."""
1905
  from core import sheet_binding
@@ -1915,7 +1954,8 @@ def _source_snapshot_stale(session, hit):
1915
  try:
1916
  import harness.mirror_tokens # noqa: F401
1917
  memo[key] = sheet_binding.database_change_token(_store(session), database)
1918
- except Exception:
 
1919
  memo[key] = None
1920
  # Missing or unreadable tokens cannot prove that a stored answer changed.
1921
  if previous and memo[key] and memo[key] != previous:
@@ -3795,9 +3835,9 @@ def _resolve_refresh_sheet(workbook_id: str, session: Session, *, only=None, for
3795
  shared["bound_values"][fr.a1_key(addr, scope_names.get(id(tab), ""))] = out
3796
  limits = list(out.get("limits") or [])
3797
  if not all(source_tokens.values()):
3798
- limits.append({"code": "change_token_unavailable",
3799
- "cause": "The database change token could not be read. This Refresh resolved the cell.",
3800
- "recommendation": "Restore the database store and connector sync receipts to enable skipping."})
3801
  snapshot = {"state": "fresh", "value": out["value"],
3802
  "display": "" if out["value"] is None else str(out["value"]),
3803
  "refreshed_at": stamp}
@@ -4840,7 +4880,8 @@ class _BindingSourceCapture:
4840
  try:
4841
  import harness.mirror_tokens # noqa: F401
4842
  self.tokens[database] = sheet_binding.database_change_token(_store(self.session), database)
4843
- except Exception:
 
4844
  self.tokens[database] = None
4845
  return self.tokens[database]
4846
 
@@ -5727,12 +5768,15 @@ _DRILL_MIRROR_MAX = 6
5727
  def _drill_tokens(session, databases):
5728
  """Unknown freshness disables reuse. No workspace documents are retained here."""
5729
  from core import sheet_binding
5730
- try:
5731
- import harness.mirror_tokens # noqa: F401
5732
- return {db: sheet_binding.database_change_token(_store(session), db)
5733
- for db in sorted(databases)}
5734
- except Exception:
5735
- return {db: None for db in sorted(databases)}
 
 
 
5736
 
5737
 
5738
  @contextlib.contextmanager
 
1900
  cell.update(deepcopy(snapshot))
1901
 
1902
 
1903
+ def _token_unread(session, database, exc):
1904
+ """Log why a database change token could not be read, once per database per request."""
1905
+ line = (str(exc).splitlines() or [""])[0][:300]
1906
+ cause = f"{type(exc).__name__}: {line}"
1907
+ memo = getattr(session, "_sheet_read_memo", None)
1908
+ causes = memo.setdefault("token_causes", {}) if isinstance(memo, dict) else None
1909
+ if causes is not None and database in causes:
1910
+ return
1911
+ print(f"[sheet-token] db={database} {cause}", flush=True)
1912
+ if causes is not None:
1913
+ causes[database] = cause
1914
+
1915
+
1916
+ def _token_unread_limit(session, unread):
1917
+ """The change_token_unavailable limit, naming the unread databases and the logged cause."""
1918
+ memo = getattr(session, "_sheet_read_memo", None)
1919
+ causes = memo.get("token_causes", {}) if isinstance(memo, dict) else {}
1920
+ labels = []
1921
+ for db in unread:
1922
+ try:
1923
+ labels.append(str(_related_filter_database_label(session, {}, db)))
1924
+ except Exception: # noqa: BLE001
1925
+ labels.append(str(db))
1926
+ cause = next((causes[db] for db in unread if causes.get(db)), "")
1927
+ because, recommendation = "", "The value is current. Refresh again to retry the check."
1928
+ if "CatalogException" in cause or "does not exist" in cause:
1929
+ because = " because a source table is missing"
1930
+ recommendation = "Sync the connector to restore the table. The value is current."
1931
+ elif "no sync receipt" in cause:
1932
+ because = " because it has no finished sync"
1933
+ recommendation = "Sync the connector once. The value is current."
1934
+ elif cause:
1935
+ because = f" because the check failed ({cause.split(':', 1)[0]})"
1936
+ names = labels[0] if len(labels) == 1 else ", ".join(labels[:-1]) + " and " + labels[-1]
1937
+ return {"code": "change_token_unavailable",
1938
+ "cause": f"Refresh could not check {names} for changes{because}, so it recomputed this cell.",
1939
+ "recommendation": recommendation}
1940
+
1941
+
1942
  def _source_snapshot_stale(session, hit):
1943
  """Compare source tokens once per request without resolving any bindings."""
1944
  from core import sheet_binding
 
1954
  try:
1955
  import harness.mirror_tokens # noqa: F401
1956
  memo[key] = sheet_binding.database_change_token(_store(session), database)
1957
+ except Exception as exc:
1958
+ _token_unread(session, database, exc)
1959
  memo[key] = None
1960
  # Missing or unreadable tokens cannot prove that a stored answer changed.
1961
  if previous and memo[key] and memo[key] != previous:
 
3835
  shared["bound_values"][fr.a1_key(addr, scope_names.get(id(tab), ""))] = out
3836
  limits = list(out.get("limits") or [])
3837
  if not all(source_tokens.values()):
3838
+ # A None token never lets a cell skip.
3839
+ limits.append(_token_unread_limit(session,
3840
+ [name for name, value in source_tokens.items() if not value]))
3841
  snapshot = {"state": "fresh", "value": out["value"],
3842
  "display": "" if out["value"] is None else str(out["value"]),
3843
  "refreshed_at": stamp}
 
4880
  try:
4881
  import harness.mirror_tokens # noqa: F401
4882
  self.tokens[database] = sheet_binding.database_change_token(_store(self.session), database)
4883
+ except Exception as exc:
4884
+ _token_unread(self.session, database, exc)
4885
  self.tokens[database] = None
4886
  return self.tokens[database]
4887
 
 
5768
  def _drill_tokens(session, databases):
5769
  """Unknown freshness disables reuse. No workspace documents are retained here."""
5770
  from core import sheet_binding
5771
+ tokens = {}
5772
+ for db in sorted(databases):
5773
+ try:
5774
+ import harness.mirror_tokens # noqa: F401
5775
+ tokens[db] = sheet_binding.database_change_token(_store(session), db)
5776
+ except Exception as exc:
5777
+ _token_unread(session, db, exc)
5778
+ tokens[db] = None
5779
+ return tokens
5780
 
5781
 
5782
  @contextlib.contextmanager
platform/harness/mirror_tokens.py CHANGED
@@ -33,32 +33,45 @@ def mirror_change_token(st, database):
33
  spec = connector_spec.spec_for(database)
34
  if database in ("customer_data", "product_data"):
35
  sources = set(datastore.ENTITIES)
 
36
  elif spec:
37
- sources = {spec.source}
38
  # A connector grid also reads joined label/identity columns declared by its spec.
39
- sources.update(target.source for _, key, _, _ in spec.links
40
- if (target := connector_spec.spec_for(key)) is not None)
 
41
  else:
42
  raise RuntimeError("The connector has no declared source for its change token.")
43
  if not sources or any(not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", s) for s in sources):
44
  raise RuntimeError("The connector source identity is invalid.")
45
  sources = sorted(sources)
 
 
 
 
 
 
 
 
 
 
 
46
  receipt_sources = sorted(set(sources) | ({"meta"} if any(s.startswith("meta_") for s in sources) else set()))
47
  clauses = [f"SELECT '{source}' AS source, CAST(count(*) AS VARCHAR) AS n, "
48
  f"CAST(bit_xor(hash(t)) AS VARCHAR) AS x, "
49
  f"CAST(sum(CAST(hash(t) AS HUGEINT)) AS VARCHAR) AS s FROM \"{source}\" t"
50
- for source in sources]
51
- placeholders = ",".join("?" for _ in sources)
52
  clauses.append("SELECT 'schema', table_name, column_name, data_type FROM duckdb_columns() "
53
  f"WHERE table_name IN ({placeholders})")
54
  # _sync_state is the resident mirror writer's receipt, not the app's status cache.
55
  clauses.append("SELECT 'sync', entity, phase, concat_ws('|', last_id, cursor_wd, rows, updated_at) "
56
  "FROM _sync_state WHERE split_part(entity, '.', 1) IN ("
57
  + ",".join("?" for _ in receipt_sources) + ")")
58
- rows = mirror_cursor(st).execute(" UNION ALL ".join(clauses) + " ORDER BY 1,2,3,4",
59
- [*sources, *receipt_sources]).fetchall()
60
  if not any(row[0] == "sync" for row in rows):
61
  raise RuntimeError("The connector has no sync receipt.")
62
- return fingerprint(rows)
 
 
63
 
64
  sheet_binding.set_mirror_token_provider(mirror_change_token)
 
33
  spec = connector_spec.spec_for(database)
34
  if database in ("customer_data", "product_data"):
35
  sources = set(datastore.ENTITIES)
36
+ optional = set(sources)
37
  elif spec:
 
38
  # A connector grid also reads joined label/identity columns declared by its spec.
39
+ optional = {target.source for _, key, _, _ in spec.links
40
+ if (target := connector_spec.spec_for(key)) is not None} - {spec.source}
41
+ sources = {spec.source} | optional
42
  else:
43
  raise RuntimeError("The connector has no declared source for its change token.")
44
  if not sources or any(not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", s) for s in sources):
45
  raise RuntimeError("The connector source identity is invalid.")
46
  sources = sorted(sources)
47
+ cur = mirror_cursor(st)
48
+ placeholders = ",".join("?" for _ in sources)
49
+ # An ENTITIES table or a link target may be absent from a seed. A connector's own source may not.
50
+ present = set()
51
+ if optional:
52
+ present = {row[0] for row in cur.execute(
53
+ "SELECT table_name FROM information_schema.tables WHERE table_schema = 'main' "
54
+ f"AND table_name IN ({','.join('?' for _ in optional)})", sorted(optional)).fetchall()}
55
+ hashed = [source for source in sources if source not in optional or source in present]
56
+ if not hashed:
57
+ raise RuntimeError("The mirror holds none of the tables this database reads.")
58
  receipt_sources = sorted(set(sources) | ({"meta"} if any(s.startswith("meta_") for s in sources) else set()))
59
  clauses = [f"SELECT '{source}' AS source, CAST(count(*) AS VARCHAR) AS n, "
60
  f"CAST(bit_xor(hash(t)) AS VARCHAR) AS x, "
61
  f"CAST(sum(CAST(hash(t) AS HUGEINT)) AS VARCHAR) AS s FROM \"{source}\" t"
62
+ for source in hashed]
 
63
  clauses.append("SELECT 'schema', table_name, column_name, data_type FROM duckdb_columns() "
64
  f"WHERE table_name IN ({placeholders})")
65
  # _sync_state is the resident mirror writer's receipt, not the app's status cache.
66
  clauses.append("SELECT 'sync', entity, phase, concat_ws('|', last_id, cursor_wd, rows, updated_at) "
67
  "FROM _sync_state WHERE split_part(entity, '.', 1) IN ("
68
  + ",".join("?" for _ in receipt_sources) + ")")
69
+ rows = cur.execute(" UNION ALL ".join(clauses) + " ORDER BY 1,2,3,4",
70
+ [*sources, *receipt_sources]).fetchall()
71
  if not any(row[0] == "sync" for row in rows):
72
  raise RuntimeError("The connector has no sync receipt.")
73
+ absent = sorted(optional - present)
74
+ # Absent names stay in the token, so a table that appears later changes it.
75
+ return fingerprint([rows, {"absent": absent}]) if absent else fingerprint(rows)
76
 
77
  sheet_binding.set_mirror_token_provider(mirror_change_token)
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 308e5ad77ac727f420f8d81956e33107c259017a5c7e69793258d9631f376a5d
 
1
+ e982321b324b788e038956341793b7deb6440facbca6e40a7d476029c7154403