fsanyoto commited on
Commit
e636b23
Β·
verified Β·
1 Parent(s): acf60ed

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "ab60955",
3
  "releases": [
4
  {
5
  "version": "v24",
 
1
  {
2
+ "current": "335e9cd",
3
  "releases": [
4
  {
5
  "version": "v24",
VERSION CHANGED
@@ -1 +1 @@
1
- ab60955
 
1
+ 335e9cd
api/automation_engine.py CHANGED
@@ -2149,6 +2149,10 @@ def create(rt, raw, username=""):
2149
  minted = minted if minted and minted not in before else ""
2150
  if patch_cfg:
2151
  raw["config"] = {**(raw.get("config") or {}), **patch_cfg}
 
 
 
 
2152
  defn, err = clean_definition(raw, None, username)
2153
  if err:
2154
  _unmint(rt, minted)
@@ -2194,6 +2198,11 @@ def patch(rt, auto_id, raw, username=""):
2194
  for k in ("name", "config", "schedule", "kind", "trigger", "flow"):
2195
  if k in (raw or {}):
2196
  merged[k] = raw[k]
 
 
 
 
 
2197
  defn, err = clean_definition(merged, prev, username)
2198
  if err:
2199
  return None, err
@@ -3599,6 +3608,71 @@ def _ig_profile_tables(rt):
3599
  return out
3600
 
3601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3602
  def _vestigial_name_field(fields, rows):
3603
  """⭐ 2026-08-07 β€” the born-blank `Name` column, or None. The owner's *"REPLACED"* half.
3604
 
 
2149
  minted = minted if minted and minted not in before else ""
2150
  if patch_cfg:
2151
  raw["config"] = {**(raw.get("config") or {}), **patch_cfg}
2152
+ # 2026-08-10 β€” point a targetless discovery flow at the profile database this tenant ALREADY
2153
+ # has, instead of letting the pure validator mint a second empty one. See
2154
+ # `discover_default_table`; a target the caller named is never rewritten.
2155
+ raw = _apply_discover_default(rt, raw)
2156
  defn, err = clean_definition(raw, None, username)
2157
  if err:
2158
  _unmint(rt, minted)
 
2198
  for k in ("name", "config", "schedule", "kind", "trigger", "flow"):
2199
  if k in (raw or {}):
2200
  merged[k] = raw[k]
2201
+ # 2026-08-10 β€” the PATCH door needs it too, and this is the one that actually bit: picking the
2202
+ # Instagram trigger on an existing automation flips the kind, and the very next Save runs a
2203
+ # config that has never carried a target through the pure validator, which mints the empty
2204
+ # `ut_ig_candidates`. `create` alone would have left the commonest path untouched.
2205
+ merged = _apply_discover_default(rt, merged)
2206
  defn, err = clean_definition(merged, prev, username)
2207
  if err:
2208
  return None, err
 
3608
  return out
3609
 
3610
 
3611
+ def discover_default_table(rt):
3612
+ """Which database should a discovery automation write to when nobody has said? (2026-08-10)
3613
+
3614
+ Owner: *"the damn database is supposed to be dynamic for whatever instagram profile is there.
3615
+ We only need ONE IG profile so it's not confusing."*
3616
+
3617
+ β›” THE COMPLAINT WAS ABOUT A SECOND EMPTY DATABASE, NOT A HARDCODED KEY. `ut_beauty_influencer_
3618
+ leads` appears NOWHERE in this product as a literal β€” it is a slug `ut_ensure` minted from the
3619
+ label the tenant typed, and `_ig_profile_tables` finds it structurally (that function's own
3620
+ note says so). What IS hardcoded is `DISCOVER_TABLE`, the FALLBACK target β€” and because it is
3621
+ a constant rather than a question, a tenant that already had an Instagram profile database got
3622
+ a SECOND, empty one the first time a discovery automation was saved without a target.
3623
+ MEASURED on nurilab: `ut_ig_candidates` (0 rows, 44 preset columns) sitting beside
3624
+ `ut_beauty_influencer_leads` (105 rows), both matching the profile predicate, one of them
3625
+ pure confusion.
3626
+
3627
+ So the default becomes a question asked of the tenant:
3628
+
3629
+ exactly one profile database (excluding the fallback) -> that one
3630
+ several, exactly one of which holds rows -> the one in use
3631
+ several in use, or none at all -> "" (the caller keeps DISCOVER_TABLE)
3632
+
3633
+ ⚠ RETURNS "" RATHER THAN GUESSING. Two populated profile databases is a real ambiguity and
3634
+ picking one silently would write a paid discovery run into a database the user did not name β€”
3635
+ worse than the empty table this exists to prevent. "" means "no opinion", and the caller's
3636
+ existing fallback stands, which is exactly today's behaviour for that case.
3637
+ ⚠ THE FALLBACK IS EXCLUDED FROM ITS OWN ELECTION. `ut_ig_candidates` carries the full preset
3638
+ schema, so it matches `_ig_profile_tables` β€” without this line a tenant that already has the
3639
+ empty table would keep re-electing it and nothing would ever change.
3640
+ """
3641
+ try:
3642
+ tables = ut_all(rt) or {}
3643
+ found = [k for k in _ig_profile_tables(rt) if k != DISCOVER_TABLE]
3644
+ except Exception: # noqa: BLE001
3645
+ return ""
3646
+ if len(found) == 1:
3647
+ return found[0]
3648
+ if len(found) > 1:
3649
+ used = [k for k in found if (tables.get(k) or {}).get("rows")]
3650
+ if len(used) == 1:
3651
+ return used[0]
3652
+ return ""
3653
+
3654
+
3655
+ def _apply_discover_default(rt, raw):
3656
+ """Fill in a discovery automation's target BEFORE the pure validator invents one.
3657
+
3658
+ β›” IT HAS TO HAPPEN HERE, AND THE REASON IS THE WHOLE DESIGN. `clean_config` is the thing that
3659
+ turns a missing target into `DISCOVER_TABLE` β€” and it takes no `rt`, by design (it is a pure
3660
+ validator with a two-argument contract every gate and route depends on). Resolving only at the
3661
+ RUN sites would be cosmetic: the literal is written into the STORED config at save time, so
3662
+ `cfg.get("targetTable")` is truthy forever after and no runtime resolver is ever consulted.
3663
+ `create`/`patch` are the one pair that both know the tenant and sit above that validator.
3664
+ ⚠ ONLY WHEN THE CALLER SAID NOTHING. An explicit target β€” including one a previous save
3665
+ stored β€” is the user's choice and is never rewritten.
3666
+ """
3667
+ cfg = raw.get("config")
3668
+ if not isinstance(cfg, dict) or str(cfg.get("targetTable") or "").strip():
3669
+ return raw
3670
+ default = discover_default_table(rt)
3671
+ if not default:
3672
+ return raw
3673
+ return {**raw, "config": {**cfg, "targetTable": default}}
3674
+
3675
+
3676
  def _vestigial_name_field(fields, rows):
3677
  """⭐ 2026-08-07 β€” the born-blank `Name` column, or None. The owner's *"REPLACED"* half.
3678
 
api/routes_automation.py CHANGED
@@ -272,7 +272,15 @@ def list_automations(session: Session = Depends(_GATE)):
272
  # validator refuses.
273
  "seedSources": list(engine.SEED_SOURCES),
274
  "seedMaxRows": engine.SEED_MAX_ROWS,
275
- "table": engine.DISCOVER_TABLE},
 
 
 
 
 
 
 
 
276
  "storeAvailable": bool(session.runtime.available()),
277
  # Wave 22 C3 β€” the trigger vocabulary, session-scoped because email readiness is a
278
  # per-USER fact (the poll runs through the creator's own Gmail connection).
 
272
  # validator refuses.
273
  "seedSources": list(engine.SEED_SOURCES),
274
  "seedMaxRows": engine.SEED_MAX_ROWS,
275
+ # 2026-08-10 β€” the OFFER must name the table the SAVE will actually use.
276
+ # This was the bare `DISCOVER_TABLE` constant while `create`/`patch` now
277
+ # resolve a targetless discovery flow to the profile database the tenant
278
+ # already has, so the picker would have shown `ut_ig_candidates` and the
279
+ # save would have written somewhere else β€” a default that disagrees with
280
+ # itself across two panels, which is the shape wave 25's R2 fixed for
281
+ # `targetTable` vs the action's `table`.
282
+ "table": (engine.discover_default_table(session.runtime)
283
+ or engine.DISCOVER_TABLE)},
284
  "storeAvailable": bool(session.runtime.available()),
285
  # Wave 22 C3 β€” the trigger vocabulary, session-scoped because email readiness is a
286
  # per-USER fact (the poll runs through the creator's own Gmail connection).