fsanyoto commited on
Commit
4eb21a6
Β·
verified Β·
1 Parent(s): 443b62f

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "4f19ed4",
3
  "releases": [
4
  {
5
  "version": "v74",
 
1
  {
2
+ "current": "06c1b08",
3
  "releases": [
4
  {
5
  "version": "v74",
VERSION CHANGED
@@ -1 +1 @@
1
- 4f19ed4
 
1
+ 06c1b08
api/routes_nav.py CHANGED
@@ -455,6 +455,28 @@ def _visible_database_keys(session):
455
  return keys, enumerated
456
 
457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
  def _granted_view_ids(session):
459
  """Every view id a wave-21 NAMED-USER GRANT lets this caller see. Fail-closed to `set()`.
460
 
@@ -464,21 +486,13 @@ def _granted_view_ids(session):
464
  answer "which views has this person starred", so the derivation moves here beside the reader
465
  it feeds rather than being copied into a second file ([[one-evaluator-per-question]]).
466
 
467
- ⚠ THE READ-PREDICATE FILTER IS NOT BELT-AND-BRACES. `shared_with` answers "is there an entry
468
- naming me"; `may_see` answers whether that entry currently grants this caller visibility.
469
- Keeping those questions separate preserves dynamic all-eligible-user grants and fails closed
470
- for a stale or malformed grant. One tenant-wide bucket is read once per call.
471
  ⚠ Fail-closed: no grants is a NARROWER answer, never a wider one.
472
  """
473
- import core.shares as shares
474
- try:
475
- return {str(v) for v in
476
- ((shares.shared_with(session.uname, kind="view", st=session.runtime) or {})
477
- .get("view") or [])
478
- if shares.may_see("view", str(v), session.uname,
479
- st=session.runtime)}
480
- except Exception:
481
- return set()
482
 
483
 
484
  #: ⭐⭐ W54-T48 / OWNER RULING R4 / CONTRACT C4 β€” ONE CONNECTION, ONE FOLDER IN THE RAIL.
 
455
  return keys, enumerated
456
 
457
 
458
+ def _granted_view_sources(session):
459
+ """`{view_id: owner}` for grants this caller may read, from one registry read.
460
+
461
+ `owner` may be ``None`` for a legacy ownerless grant. Callers preserve the old fail-closed
462
+ source lookup for that case; modern grants point directly at the canonical personal stratum.
463
+ """
464
+ import core.shares as shares
465
+ try:
466
+ out = {}
467
+ for raw_id, record in shares.grants_bulk("view", st=session.runtime).items():
468
+ owner = str(record.get("owner") or "").strip().lower() or None
469
+ if owner == session.uname:
470
+ continue
471
+ # Match the historical `shared_with` + `may_see` path: being an admin alone did not
472
+ # add a View to "shared with me"; a valid named or everyone grant did.
473
+ if shares.role_from(record, session.uname) is not None:
474
+ out[str(raw_id)] = owner
475
+ return out
476
+ except Exception:
477
+ return {}
478
+
479
+
480
  def _granted_view_ids(session):
481
  """Every view id a wave-21 NAMED-USER GRANT lets this caller see. Fail-closed to `set()`.
482
 
 
486
  answer "which views has this person starred", so the derivation moves here beside the reader
487
  it feeds rather than being copied into a second file ([[one-evaluator-per-question]]).
488
 
489
+ ⚠ THE READ PREDICATE STILL HAS ONE OWNER. `_granted_view_sources` obtains the registry once
490
+ through `grants_bulk` and delegates each held record to `shares.role_from`, the same pure
491
+ evaluator `may_see` uses. Named and dynamic-everyone grants therefore keep identical semantics
492
+ without one registry round trip per id.
493
  ⚠ Fail-closed: no grants is a NARROWER answer, never a wider one.
494
  """
495
+ return set(_granted_view_sources(session))
 
 
 
 
 
 
 
 
496
 
497
 
498
  #: ⭐⭐ W54-T48 / OWNER RULING R4 / CONTRACT C4 β€” ONE CONNECTION, ONE FOLDER IN THE RAIL.
api/routes_starred.py CHANGED
@@ -207,7 +207,7 @@ def _scan_starred_views(session, keys=None, cache=None):
207
  import core.table_store as table_store
208
  import core.view_templates as view_templates
209
 
210
- granted = routes_nav._granted_view_ids(session)
211
  # ⭐⭐ W62-T17 (D-756) β€” EVERY GRANTED VIEW ID WAS RESOLVED ONCE PER DATABASE, and that loop is
212
  # where `/starred`'s budget went. MEASURED on staging's Royal Imports, 26 databases
213
  # (`AutoWiki/waves/wave62/proto/T17-profile.md`): 4,844 ms total, of which `_visible_views` was
@@ -216,20 +216,15 @@ def _scan_starred_views(session, keys=None, cache=None):
216
  # 8 KB and each read is a single ~40 ms round trip. They are about the same question being
217
  # asked once per database.
218
  #
219
- # ⭐ A VIEW LIVES IN EXACTLY ONE DATABASE. Once a database has resolved a granted id, every
220
- # LATER database in the scan is being asked a question whose answer cannot be yes β€” and each
221
- # of those "no"s costs a `shares.may_see` read plus a full workspace-document read through
222
- # `find_view`. Dropping resolved ids from the set handed on narrows only the LOOKUPS, never
223
- # the answer: `_visible_views` still returns this caller's own views for every database, and a
224
- # granted view is still admitted by `shares.may_see` before it is looked up at all.
225
  #
226
- # β›” AND THE OBVIOUS SECOND SAVING IS NOT AVAILABLE: lending `object_shares` for the pass
227
- # (`user_tables.lend`) would collapse those 28 reads to one, but `TableStore.find_view` reaches
228
- # `migrate_legacy_shared_views`, which WRITES grants and then READS THEM BACK to verify them. A
229
- # lent snapshot would serve the pre-write value to that readback and the migration would raise
230
- # `LegacySharedViewMigrationError` on any tenant that still has legacy shared views β€” a 500 on
231
- # `/starred` in exchange for a few hundred milliseconds. `_Lent`'s own contract says it may
232
- # only serve code "proven not to mutate" the lent key; this path is not that code.
233
  resolved, out = set(), []
234
  for key in order:
235
  doc = docs.get(key)
@@ -239,9 +234,42 @@ def _scan_starred_views(session, keys=None, cache=None):
239
  if not ws_key:
240
  continue
241
  views = table_store.make(ws_key, st=session.runtime)
242
- pending = granted - resolved
243
- found = routes_nav._visible_views(doc, session.uname, session.admin, pending, views)
244
- resolved |= pending & set(found)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  for vid, view in found.items():
246
  cfg = view.get("config") or {}
247
  if cfg.get("important") is True:
 
207
  import core.table_store as table_store
208
  import core.view_templates as view_templates
209
 
210
+ granted = routes_nav._granted_view_sources(session)
211
  # ⭐⭐ W62-T17 (D-756) β€” EVERY GRANTED VIEW ID WAS RESOLVED ONCE PER DATABASE, and that loop is
212
  # where `/starred`'s budget went. MEASURED on staging's Royal Imports, 26 databases
213
  # (`AutoWiki/waves/wave62/proto/T17-profile.md`): 4,844 ms total, of which `_visible_views` was
 
216
  # 8 KB and each read is a single ~40 ms round trip. They are about the same question being
217
  # asked once per database.
218
  #
219
+ # ⭐ A VIEW LIVES IN EXACTLY ONE DATABASE AND ITS GRANT NAMES ITS OWNER. The modern fast path
220
+ # resolves that owner directly in the projected document this scan already paid for; it never
221
+ # re-reads the grant registry or calls `find_view` for every database. `resolved` still removes
222
+ # a found id from every later database's lookup work.
 
 
223
  #
224
+ # β›” THIS IS NOT A LENT `object_shares` SNAPSHOT. `TableStore.find_view` reaches the legacy
225
+ # migration, which WRITES grants and reads them back; lending that key across the migration
226
+ # would serve a pre-write value and raise. The branch below detects retired shapes in the
227
+ # document already held, runs the unchanged strict migration, and refreshes that one document.
 
 
 
228
  resolved, out = set(), []
229
  for key in order:
230
  doc = docs.get(key)
 
234
  if not ws_key:
235
  continue
236
  views = table_store.make(ws_key, st=session.runtime)
237
+ pending = set(granted) - resolved
238
+
239
+ # The old path called `find_view` once for every pending grant in every database. Each
240
+ # call strictly re-read this same workspace document and the whole share registry. The
241
+ # projected document above already contains every personal View, so modern grants can
242
+ # resolve directly through their canonical owner. A legacy document still takes the old
243
+ # strict migration door and is re-read afterwards; the optimization never skips a write.
244
+ if pending and views.prepare_view_projection(doc):
245
+ doc = session.runtime.get_projection(ws_key, drop=("overlays", "fields")) or {}
246
+ docs[key] = doc
247
+
248
+ found = {}
249
+ own = doc.get(session.uname)
250
+ for vid, view in ((own.get("views") or {}) if isinstance(own, dict) else {}).items():
251
+ if isinstance(view, dict):
252
+ found[str(vid)] = view
253
+
254
+ for vid in pending:
255
+ owner = granted.get(vid)
256
+ view = None
257
+ if owner:
258
+ owner_ws = doc.get(owner)
259
+ view = ((owner_ws.get("views") or {}).get(vid)
260
+ if isinstance(owner_ws, dict) else None)
261
+ else:
262
+ # Preserve the historical first-source lookup for a legacy ownerless grant.
263
+ for candidate_owner, workspace in doc.items():
264
+ if candidate_owner in table_store.RESERVED_MEMBERS or not isinstance(workspace, dict):
265
+ continue
266
+ candidate = (workspace.get("views") or {}).get(vid)
267
+ if isinstance(candidate, dict):
268
+ view = candidate
269
+ break
270
+ if isinstance(view, dict):
271
+ found.setdefault(vid, view)
272
+ resolved.add(vid)
273
  for vid, view in found.items():
274
  cfg = view.get("config") or {}
275
  if cfg.get("important") is True:
platform/core/table_store.py CHANGED
@@ -1331,6 +1331,34 @@ class TableStore:
1331
  })
1332
  return plans
1333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1334
  def migrate_legacy_shared_views(self):
1335
  """Convert ``__shared__.views`` to personal source records plus explicit grants.
1336
 
 
1331
  })
1332
  return plans
1333
 
1334
+ def legacy_view_migration_needed(self, source=None):
1335
+ """Whether a preloaded workspace document still carries either retired View shape.
1336
+
1337
+ This is the read-only half of :meth:`migrate_legacy_shared_views`. A caller that already
1338
+ paid for a rows-free workspace projection can avoid a second store read for the common
1339
+ clean document while still routing every legacy document through the full strict,
1340
+ write-and-read-back migration below. Malformed legacy data raises here exactly as it does
1341
+ there; it is never interpreted as clean.
1342
+ """
1343
+ data = self._strict_document() if source is None else source
1344
+ if not isinstance(data, dict):
1345
+ raise LegacySharedViewMigrationError(
1346
+ 'legacy shared-view migration found a non-object workspace document')
1347
+ has_blank_legacy, _blank = self._blank_legacy_view_bucket(data)
1348
+ return bool(has_blank_legacy or self._legacy_shared_plans(data)
1349
+ or self._personal_permission_plans(data))
1350
+
1351
+ def prepare_view_projection(self, source):
1352
+ """Migrate a preloaded projection when needed; return whether its caller must refresh.
1353
+
1354
+ Keeping this decision beside the migration prevents read routes from acquiring a second,
1355
+ partial definition of which retired shapes are write-bearing.
1356
+ """
1357
+ if not self.legacy_view_migration_needed(source):
1358
+ return False
1359
+ self.migrate_legacy_shared_views()
1360
+ return True
1361
+
1362
  def migrate_legacy_shared_views(self):
1363
  """Convert ``__shared__.views`` to personal source records plus explicit grants.
1364
 
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 422efafe67e36a0b9ed33e80ef44bf47f1433402854ab0715382a95e83a7bf96
 
1
+ 6cb32ea63263b21f7458a0a1bf7a4ef3505c8667be5a4758d767339264e5c174
web/src/home/HomePage.tsx CHANGED
@@ -50,7 +50,7 @@ import { QueryIcon, StarButton, Tile } from "../starred/StarredPage";
50
  import { ITEM_DELETED_EVENT, isMissingItem, itemDeleted, openExistingItem, sameDeletedItem, shapeStarred, useStarred, viewCount, viewCountKey } from "../starred/starredApi";
51
  import type { DeletedItem, StarKind, Starred, StarredCounts, StarredLoad } from "../starred/starredApi";
52
  import { StarIcon } from "../ui/icons";
53
- import { createWorkbook, readIndex, writeIndex } from "../sheet/sheetApi";
54
  import type { SheetIndex } from "../sheet/sheetApi";
55
  import { AutomationError, createAutomation, nextAutomationName } from "../automation/automationApi";
56
  import {
@@ -1371,9 +1371,13 @@ export default function HomePage(props: HomeProps) {
1371
  let timeout: ReturnType<typeof setTimeout> | undefined;
1372
  const timeoutError = new Error("The folder move timed out. Reload folders to retry.");
1373
  try {
 
 
 
1374
  const result = await Promise.race([
1375
- writeIndex({ ...sheetIndex, folders: next.folders,
1376
- itemFolders: next.itemFolders, starred: sheetIndex.starred, rev: sheetIndex.rev }),
 
1377
  new Promise<never>((_, reject) => {
1378
  timeout = setTimeout(() => reject(timeoutError), FOLDER_WRITE_TIMEOUT_MS);
1379
  }),
 
50
  import { ITEM_DELETED_EVENT, isMissingItem, itemDeleted, openExistingItem, sameDeletedItem, shapeStarred, useStarred, viewCount, viewCountKey } from "../starred/starredApi";
51
  import type { DeletedItem, StarKind, Starred, StarredCounts, StarredLoad } from "../starred/starredApi";
52
  import { StarIcon } from "../ui/icons";
53
+ import { createWorkbook, placementOnlyDelta, readIndex, writeIndex, writePlacements } from "../sheet/sheetApi";
54
  import type { SheetIndex } from "../sheet/sheetApi";
55
  import { AutomationError, createAutomation, nextAutomationName } from "../automation/automationApi";
56
  import {
 
1371
  let timeout: ReturnType<typeof setTimeout> | undefined;
1372
  const timeoutError = new Error("The folder move timed out. Reload folders to retry.");
1373
  try {
1374
+ const nextIndex = { ...sheetIndex, folders: next.folders,
1375
+ itemFolders: next.itemFolders, starred: sheetIndex.starred };
1376
+ const placements = placementOnlyDelta(sheetIndex, nextIndex);
1377
  const result = await Promise.race([
1378
+ placements
1379
+ ? writePlacements(placements)
1380
+ : writeIndex({ ...nextIndex, rev: sheetIndex.rev }),
1381
  new Promise<never>((_, reject) => {
1382
  timeout = setTimeout(() => reject(timeoutError), FOLDER_WRITE_TIMEOUT_MS);
1383
  }),
web/src/sheet/SheetPage.tsx CHANGED
@@ -65,7 +65,7 @@ import SheetRail from "./SheetRail";
65
  import type { RailStrata } from "./SheetRail";
66
  import {
67
  computeCell, createWorkbook, deleteWorkbook, patchTabCells, readIndex, readTab, readTabMeta,
68
- readWorkbook, refreshWorkbook, writeIndex, writeWorkbook,
69
  } from "./sheetApi";
70
  import type { SheetIndex } from "./sheetApi";
71
  // β›”β›” W51-T10 / R6 β€” THE ONE CONFIRM DIALOG (contract C8). The sheet-delete prompt below used to
@@ -2488,6 +2488,7 @@ export default function SheetPage() {
2488
  */
2489
  const saveStrata = useCallback(async (next: RailStrata) => {
2490
  const previousIndex = index;
 
2491
  setNotice("");
2492
  setIndex((prev) => ({
2493
  ...prev,
@@ -2509,7 +2510,9 @@ export default function SheetPage() {
2509
  const timeoutError = new Error("The folder move timed out. Your items were put back.");
2510
  try {
2511
  const saved = await Promise.race([
2512
- writeIndex(indexRev === undefined ? next : { ...next, rev: indexRev }),
 
 
2513
  new Promise<never>((_, reject) => {
2514
  timeout = setTimeout(() => reject(timeoutError), FOLDER_WRITE_TIMEOUT_MS);
2515
  }),
 
65
  import type { RailStrata } from "./SheetRail";
66
  import {
67
  computeCell, createWorkbook, deleteWorkbook, patchTabCells, readIndex, readTab, readTabMeta,
68
+ placementOnlyDelta, readWorkbook, refreshWorkbook, writeIndex, writePlacements, writeWorkbook,
69
  } from "./sheetApi";
70
  import type { SheetIndex } from "./sheetApi";
71
  // β›”β›” W51-T10 / R6 β€” THE ONE CONFIRM DIALOG (contract C8). The sheet-delete prompt below used to
 
2488
  */
2489
  const saveStrata = useCallback(async (next: RailStrata) => {
2490
  const previousIndex = index;
2491
+ const placements = placementOnlyDelta(index, next);
2492
  setNotice("");
2493
  setIndex((prev) => ({
2494
  ...prev,
 
2510
  const timeoutError = new Error("The folder move timed out. Your items were put back.");
2511
  try {
2512
  const saved = await Promise.race([
2513
+ placements
2514
+ ? writePlacements(placements)
2515
+ : writeIndex(indexRev === undefined ? next : { ...next, rev: indexRev }),
2516
  new Promise<never>((_, reject) => {
2517
  timeout = setTimeout(() => reject(timeoutError), FOLDER_WRITE_TIMEOUT_MS);
2518
  }),
web/src/sheet/sheetApi.ts CHANGED
@@ -6,7 +6,7 @@
6
  // ⚠ Three doors below refuse with `sheet_resolution_not_built` until W49-T04 lands. They are
7
  // declared now so the later ticket changes the SERVER and not this file's shape.
8
  import { API_V1, CREDENTIALS } from "../apiContract";
9
- import { emptyIndex, normalizeCellBinding } from "./types";
10
  import type { Cell, CellRefusal, SheetTab, Workbook, WorkbookIndex, WorkbookRow } from "./types";
11
 
12
  export type Result<T> =
@@ -143,6 +143,45 @@ export const writeIndex = (
143
  ): Promise<Result<SheetIndex>> =>
144
  call("/sheets/index", sends("PUT", next), asIndex);
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  export const createWorkbook = (name = ""): Promise<Result<Workbook>> =>
147
  call("/sheets", sends("POST", { name }), asWorkbook);
148
 
 
6
  // ⚠ Three doors below refuse with `sheet_resolution_not_built` until W49-T04 lands. They are
7
  // declared now so the later ticket changes the SERVER and not this file's shape.
8
  import { API_V1, CREDENTIALS } from "../apiContract";
9
+ import { emptyIndex, normalizeCellBinding, ROOT_FOLDER_ID } from "./types";
10
  import type { Cell, CellRefusal, SheetTab, Workbook, WorkbookIndex, WorkbookRow } from "./types";
11
 
12
  export type Result<T> =
 
143
  ): Promise<Result<SheetIndex>> =>
144
  call("/sheets/index", sends("PUT", next), asIndex);
145
 
146
+ /** One placement-only merge. `null` is the server's spelling for the Sheet root. */
147
+ export type PlacementDelta = Record<string, string | null>;
148
+
149
+ const sameFolders = (left: WorkbookIndex["folders"], right: WorkbookIndex["folders"]): boolean =>
150
+ left.length === right.length && left.every((folder, index) => {
151
+ const other = right[index];
152
+ return !!other && folder.id === other.id && folder.name === other.name
153
+ && (folder.parent ?? null) === (other.parent ?? null);
154
+ });
155
+
156
+ const sameStrings = (left: string[], right: string[]): boolean =>
157
+ left.length === right.length && left.every((value, index) => value === right[index]);
158
+
159
+ /**
160
+ * Return the changed workbook placements only when folders and stars are unchanged.
161
+ *
162
+ * A missing placement and the explicit root marker mean the same thing to the merge door. The
163
+ * server accepts `null` to remove the stored placement; forwarding `__root__` would turn a root
164
+ * move into a folder-id validation failure.
165
+ */
166
+ export const placementOnlyDelta = (
167
+ previous: Pick<WorkbookIndex, "folders" | "itemFolders" | "starred">,
168
+ next: Pick<WorkbookIndex, "folders" | "itemFolders" | "starred">,
169
+ ): PlacementDelta | null => {
170
+ if (!sameFolders(previous.folders, next.folders) || !sameStrings(previous.starred, next.starred)) return null;
171
+ const delta: PlacementDelta = {};
172
+ const ids = new Set([...Object.keys(previous.itemFolders), ...Object.keys(next.itemFolders)]);
173
+ for (const id of ids) {
174
+ const before = previous.itemFolders[id] ?? ROOT_FOLDER_ID;
175
+ const after = next.itemFolders[id] ?? ROOT_FOLDER_ID;
176
+ if (before !== after) delta[id] = after === ROOT_FOLDER_ID ? null : after;
177
+ }
178
+ return Object.keys(delta).length ? delta : null;
179
+ };
180
+
181
+ /** Merge disjoint moves without a stale whole-index revision overwriting somebody else's move. */
182
+ export const writePlacements = (placements: PlacementDelta): Promise<Result<SheetIndex>> =>
183
+ call("/sheets/index", sends("PUT", { placements }), asIndex);
184
+
185
  export const createWorkbook = (name = ""): Promise<Result<Workbook>> =>
186
  call("/sheets", sends("POST", { name }), asWorkbook);
187