fsanyoto commited on
Commit
0bd5b3e
Β·
verified Β·
1 Parent(s): e1b3e71

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
Files changed (4) hide show
  1. RELEASES.json +1 -1
  2. VERSION +1 -1
  3. api/automation_engine.py +166 -25
  4. api/connectors_tt.py +52 -9
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "4258a93",
3
  "releases": [
4
  {
5
  "version": "v24",
 
1
  {
2
+ "current": "d84a1fa",
3
  "releases": [
4
  {
5
  "version": "v24",
VERSION CHANGED
@@ -1 +1 @@
1
- 4258a93
 
1
+ d84a1fa
api/automation_engine.py CHANGED
@@ -1697,8 +1697,37 @@ def clean_flow(raw, previous=None):
1697
  DISCOVER_SEED_RECORDS = 25
1698
 
1699
 
1700
- def _ensure_ig_action(flow_raw, table):
1701
- """Create record is PERMANENT step 1 on `ig_profile_match` β€” it cannot be deleted or moved.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1702
 
1703
  ⭐ OWNER RULING 2026-08-06, AND IT REVERSES WAVE 24's LAW 3. That law seeded this action once,
1704
  on the edge into the trigger, and ended "deleting it is their call, not a refusal" β€” with a
@@ -1720,7 +1749,7 @@ def _ensure_ig_action(flow_raw, table):
1720
  actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
1721
  if actions and actions[0].get("kind") == "create_record":
1722
  return _pin_unique(_ensure_enrich_step(
1723
- flow_raw if isinstance(flow_raw, dict) else flow))
1724
  at = next((i for i, a in enumerate(actions) if a.get("kind") == "create_record"), -1)
1725
  if at > 0:
1726
  actions.insert(0, actions.pop(at))
@@ -1739,11 +1768,15 @@ def _ensure_ig_action(flow_raw, table):
1739
  "values": {"handle": "{{handle}}"}},
1740
  })
1741
  flow["actions"] = actions
1742
- return _pin_unique(_ensure_enrich_step(flow))
 
1743
 
 
 
1744
 
1745
- def _ensure_enrich_step(flow_raw):
1746
- """⭐ 2026-08-07 (owner ruling) β€” ENRICH IS STEP 2 ON AN INSTAGRAM SEARCH.
 
1747
 
1748
  Owner: *"make it default that this enrichment action is Step 2 always, and under Config of
1749
  Step 2 … we can have a toggle on or off."* Which is the same shape as step 1's ruling and for
@@ -1766,14 +1799,14 @@ def _ensure_enrich_step(flow_raw):
1766
  """
1767
  flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
1768
  actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
1769
- if any(a.get("kind") == "enrich_instagram" for a in walk_actions(actions)):
1770
  return flow_raw if isinstance(flow_raw, dict) else flow
1771
  seeded = list(actions)
1772
  # Index 1 β€” after the pinned Create record, because there is nothing to enrich until the
1773
  # profiles have been written as records. `insert` past the end is a plain append, so a flow
1774
  # with only step 1 lands this at the end, which IS step 2.
1775
  seeded.insert(1, {
1776
- "id": "act_enrich", "kind": "enrich_instagram", "enabled": True, "when": None,
1777
  "config": {"postMetrics": False, "commentMetrics": False,
1778
  "dryRun": False, "maxPosts": DEFAULT_POSTS_PER_PULL,
1779
  "fromView": "", "sortField": DEFAULT_ENRICH_SORT, "sortDir": "desc",
@@ -1839,10 +1872,13 @@ def _pin_unique(flow):
1839
 
1840
  #: The two steps `_ensure_ig_action` / `_ensure_enrich_step` plant, as `(kind, id)`. Named here so
1841
  #: the seeder and the un-seeder cannot disagree about what "seeded" means.
1842
- _IG_SEED_IDS = {"create_record": "act_1", "enrich_instagram": "act_enrich"}
 
 
 
1843
 
1844
 
1845
- def _is_untouched_ig_seed(action, table):
1846
  """Is this action still EXACTLY what the Instagram trigger planted? (wave 27 item 15)
1847
 
1848
  β›” THE COMPARISON IS AGAINST A FRESHLY BUILT SEED, not against a list of remembered keys, and
@@ -1867,19 +1903,19 @@ def _is_untouched_ig_seed(action, table):
1867
  if _IG_SEED_IDS.get(kind) != str(action.get("id") or ""):
1868
  return False
1869
  seeded, _seed_err = clean_actions(
1870
- (_ensure_ig_action({"actions": []}, table).get("actions") or []))
1871
  fresh = {a.get("kind"): a for a in (seeded or [])}
1872
  seed = fresh.get(kind)
1873
  if not seed:
1874
  return False
1875
  cfg, seed_cfg = dict(action.get("config") or {}), dict(seed.get("config") or {})
1876
- if kind == "enrich_instagram":
1877
  cfg.pop("enabled", None)
1878
  seed_cfg.pop("enabled", None)
1879
  return cfg == seed_cfg and (action.get("when") or None) is None
1880
 
1881
 
1882
- def _drop_ig_seeds(flow_raw, table):
1883
  """Strip the trigger's own seeded steps, keeping any the person has since made theirs.
1884
 
1885
  ⭐⭐ WAVE 27 ITEM 15 (owner) β€” *"stale pinned create_record on trigger change"*. THE COMMENT
@@ -1899,7 +1935,7 @@ def _drop_ig_seeds(flow_raw, table):
1899
  """
1900
  flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
1901
  actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
1902
- kept = [a for a in actions if not _is_untouched_ig_seed(a, table)]
1903
  if len(kept) == len(actions):
1904
  return flow_raw
1905
  return {**flow, "actions": kept}
@@ -1908,7 +1944,10 @@ def _drop_ig_seeds(flow_raw, table):
1908
  def ig_action_pinned(defn, index):
1909
  """Is this action the one that cannot be removed? Derived, never stored β€” a stored `pinned`
1910
  flag is a second copy of the rule, and the copy is what a hand-written PATCH omits."""
1911
- return (defn or {}).get("kind") == "discover_instagram" and index == 0
 
 
 
1912
 
1913
 
1914
  def clean_definition(raw, previous=None, username=""):
@@ -1953,6 +1992,13 @@ def clean_definition(raw, previous=None, username=""):
1953
  # PREVIOUS one. Asking `"trigger" in raw` would fire on every empty patch, because
1954
  # `patch()` builds its raw as `dict(prev)` plus the caller's keys.
1955
  kind = DEFAULT_KIND
 
 
 
 
 
 
 
1956
  elif (kind == "discover_instagram"
1957
  and ((prev.get("trigger") or {}) or {}).get("key") == "ig_profile_match"
1958
  and (trigger or {}).get("key") != "ig_profile_match"):
@@ -2063,18 +2109,31 @@ def clean_definition(raw, previous=None, username=""):
2063
  # ⭐ EVERY CLEAN, NOT ONLY THE EDGE (owner ruling 6 β€” see `_ensure_ig_action`). The edge-only
2064
  # call was what made the action deletable; running it on every save is what makes step 1
2065
  # permanent, and it is deliberate rather than a widened condition nobody noticed.
2066
- if (trigger or {}).get("key") == "ig_profile_match":
2067
- flow_raw = _ensure_ig_action(flow_raw, config.get("targetTable") or DISCOVER_TABLE)
 
 
 
 
 
 
2068
  elif drop_ig_seeds:
2069
- # ITEM 15: the trigger just STOPPED being the Instagram one. Un-seed what the trigger
2070
  # planted and nobody has since made theirs β€” measured against the table the seeds were
2071
  # planted for, which is the PREVIOUS config's, not the one being saved.
 
 
 
 
2072
  flow_raw = _drop_ig_seeds(
2073
- flow_raw, (prev.get("config") or {}).get("targetTable") or DISCOVER_TABLE)
2074
  flow, ferr = clean_flow(flow_raw, prev.get("flow"))
2075
  if ferr:
2076
  return None, ferr
2077
- if (trigger or {}).get("key") == "ig_profile_match":
 
 
 
2078
  # ⭐ WAVE 25 Β· R2 β€” THE CREATE RECORD ACTION'S `config.table` IS AUTHORITATIVE, and
2079
  # `config.targetTable` FOLLOWS IT. Two fields have been naming the same database since
2080
  # wave 24: the pinned step 1 says where profiles are written, and the config says where
@@ -2399,7 +2458,12 @@ def create(rt, raw, username=""):
2399
  cur[defn["id"]] = defn
2400
  return cur
2401
 
2402
- rt.update(STORE_KEY, _up, flush="sync")
 
 
 
 
 
2403
  _presets_after_write(rt, defn, username) # R10: the columns exist before a run
2404
  if defn.get("trigger"):
2405
  _seed_event_state(rt, defn)
@@ -2435,8 +2499,36 @@ def patch(rt, auto_id, raw, username=""):
2435
  cur[defn["id"]] = defn
2436
  return cur
2437
 
2438
- rt.update(STORE_KEY, _up, flush="sync")
2439
- _presets_after_write(rt, defn, username) # R10: also on the save that RE-TARGETS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2440
  # A2(1): a NEW or CHANGED condition trigger starts with everything currently matching
2441
  # DISARMED β€” enabling never fires for records already in the state.
2442
  if (defn.get("trigger") or {}) != ((prev.get("trigger")) or {}):
@@ -2553,10 +2645,32 @@ def remove(rt, auto_id):
2553
  cur = cur if isinstance(cur, dict) else {}
2554
  cur.pop(aid, None)
2555
  return cur
2556
- rt.update(STORE_KEY, _up, flush="sync")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2557
  # C8 β€” the fields this flow tagged are DISABLED with the reason on them, never orphaned
2558
  # silently: the column keeps its values and its config, and says why it stopped. Scanned
2559
  # first so a delete with no tagged fields costs no store commit.
 
 
 
 
 
2560
  hit = any(str((f.get("automation") or {}).get("flowId") or "") == aid
2561
  for t in ut_all(rt).values() for f in (t.get("fields") or []))
2562
  if not hit:
@@ -2571,7 +2685,11 @@ def remove(rt, auto_id):
2571
  a["disabled"] = True
2572
  a["statusNote"] = f"its automation was deleted {_stamp()}"
2573
  return cur
2574
- rt.update(UT_STORE_KEY, _disable, flush="sync")
 
 
 
 
2575
 
2576
 
2577
  # ---------------------------------------------------------------------------------------------
@@ -8762,6 +8880,29 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
8762
  tt["posts"].extend(tt_idents)
8763
  tt["psnaps"].extend(tt_metrics)
8764
  tt["comments"].extend(tt_comments)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8765
  cells = tt_preset_cells(res, pulled)
8766
  if cfg.get("dryRun"):
8767
  tt["dry"] = True
 
1697
  DISCOVER_SEED_RECORDS = 25
1698
 
1699
 
1700
+ def discovery_seed_spec(kind):
1701
+ """-> (default table, enrich action kind) for a discovery KIND.
1702
+
1703
+ ⭐⭐ WAVE 30, OWNER REPORT 2026-08-12, verbatim: *"'When a Tiktok profile fits a criteria'
1704
+ should ALWAYS have a 'Create record' EXACTLY like the Instagram one … THE ONLY DIFFERENCE IS
1705
+ THE COLUMNS AND DATA SCHEMA"*. They were right, and the seeding path was the one family of
1706
+ sites this wave widened everywhere ELSE: `clean_definition` planted step 1 and step 2 only when
1707
+ the trigger was `ig_profile_match`, so a TikTok search stored `flow.actions = []` and had
1708
+ nowhere to put what it found β€” MEASURED live against `auto_1` (Instagram: create_record +
1709
+ enrich) versus a fresh TikTok discovery (empty).
1710
+
1711
+ ⭐ THIS IS A LOOKUP, NOT A SECOND SEEDER, and that is the whole point of the ruling. One
1712
+ builder plants both platforms' steps; the only things that vary are the table the record lands
1713
+ in and which enrich action reads it β€” literally "the columns and data schema". A forked
1714
+ `_ensure_tt_action` would start identical and drift, which is the failure `ENRICH_KINDS` and
1715
+ `DISCOVERY_KINDS` were introduced to prevent one screen up.
1716
+
1717
+ ⚠ Resolved in a FUNCTION rather than a module-level dict because `DISCOVER_TABLE` is defined
1718
+ far below this line; a dict here would raise at import.
1719
+ """
1720
+ if kind == "discover_tiktok":
1721
+ return TT_PROFILE_TABLE, "enrich_tiktok"
1722
+ return DISCOVER_TABLE, "enrich_instagram"
1723
+
1724
+
1725
+ def _ensure_ig_action(flow_raw, table, enrich_kind="enrich_instagram"):
1726
+ """Create record is PERMANENT step 1 on a DISCOVERY trigger β€” it cannot be deleted or moved.
1727
+
1728
+ ⚠ THE NAME IS INSTAGRAM'S AND THE BEHAVIOUR IS BOTH PLATFORMS' (wave 30). Renaming it would
1729
+ churn six gate references for no behaviour change; `enrich_kind` is what makes it general, and
1730
+ it defaults to Instagram's so every pre-existing caller keeps its exact meaning.
1731
 
1732
  ⭐ OWNER RULING 2026-08-06, AND IT REVERSES WAVE 24's LAW 3. That law seeded this action once,
1733
  on the edge into the trigger, and ended "deleting it is their call, not a refusal" β€” with a
 
1749
  actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
1750
  if actions and actions[0].get("kind") == "create_record":
1751
  return _pin_unique(_ensure_enrich_step(
1752
+ flow_raw if isinstance(flow_raw, dict) else flow, enrich_kind))
1753
  at = next((i for i, a in enumerate(actions) if a.get("kind") == "create_record"), -1)
1754
  if at > 0:
1755
  actions.insert(0, actions.pop(at))
 
1768
  "values": {"handle": "{{handle}}"}},
1769
  })
1770
  flow["actions"] = actions
1771
+ return _pin_unique(_ensure_enrich_step(flow, enrich_kind))
1772
+
1773
 
1774
+ def _ensure_enrich_step(flow_raw, enrich_kind="enrich_instagram"):
1775
+ """⭐ 2026-08-07 (owner ruling) β€” ENRICH IS STEP 2 ON A DISCOVERY SEARCH.
1776
 
1777
+ ⚠ WAVE 30: `enrich_kind` selects the network. Instagram's is the default so every pre-existing
1778
+ caller means exactly what it meant before; TikTok passes `enrich_tiktok` and gets the identical
1779
+ step shape, which is the owner's *"only the columns and data schema differ"*.
1780
 
1781
  Owner: *"make it default that this enrichment action is Step 2 always, and under Config of
1782
  Step 2 … we can have a toggle on or off."* Which is the same shape as step 1's ruling and for
 
1799
  """
1800
  flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
1801
  actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
1802
+ if any(a.get("kind") == enrich_kind for a in walk_actions(actions)):
1803
  return flow_raw if isinstance(flow_raw, dict) else flow
1804
  seeded = list(actions)
1805
  # Index 1 β€” after the pinned Create record, because there is nothing to enrich until the
1806
  # profiles have been written as records. `insert` past the end is a plain append, so a flow
1807
  # with only step 1 lands this at the end, which IS step 2.
1808
  seeded.insert(1, {
1809
+ "id": "act_enrich", "kind": enrich_kind, "enabled": True, "when": None,
1810
  "config": {"postMetrics": False, "commentMetrics": False,
1811
  "dryRun": False, "maxPosts": DEFAULT_POSTS_PER_PULL,
1812
  "fromView": "", "sortField": DEFAULT_ENRICH_SORT, "sortDir": "desc",
 
1872
 
1873
  #: The two steps `_ensure_ig_action` / `_ensure_enrich_step` plant, as `(kind, id)`. Named here so
1874
  #: the seeder and the un-seeder cannot disagree about what "seeded" means.
1875
+ #: ⚠ WAVE 30 β€” `enrich_tiktok` shares `act_enrich`. The map is keyed by KIND, and only one enrich
1876
+ #: step is ever seeded per flow (the network follows the trigger), so the id cannot collide.
1877
+ _IG_SEED_IDS = {"create_record": "act_1", "enrich_instagram": "act_enrich",
1878
+ "enrich_tiktok": "act_enrich"}
1879
 
1880
 
1881
+ def _is_untouched_ig_seed(action, table, enrich_kind="enrich_instagram"):
1882
  """Is this action still EXACTLY what the Instagram trigger planted? (wave 27 item 15)
1883
 
1884
  β›” THE COMPARISON IS AGAINST A FRESHLY BUILT SEED, not against a list of remembered keys, and
 
1903
  if _IG_SEED_IDS.get(kind) != str(action.get("id") or ""):
1904
  return False
1905
  seeded, _seed_err = clean_actions(
1906
+ (_ensure_ig_action({"actions": []}, table, enrich_kind).get("actions") or []))
1907
  fresh = {a.get("kind"): a for a in (seeded or [])}
1908
  seed = fresh.get(kind)
1909
  if not seed:
1910
  return False
1911
  cfg, seed_cfg = dict(action.get("config") or {}), dict(seed.get("config") or {})
1912
+ if kind in ENRICH_KINDS:
1913
  cfg.pop("enabled", None)
1914
  seed_cfg.pop("enabled", None)
1915
  return cfg == seed_cfg and (action.get("when") or None) is None
1916
 
1917
 
1918
+ def _drop_ig_seeds(flow_raw, table, enrich_kind="enrich_instagram"):
1919
  """Strip the trigger's own seeded steps, keeping any the person has since made theirs.
1920
 
1921
  ⭐⭐ WAVE 27 ITEM 15 (owner) β€” *"stale pinned create_record on trigger change"*. THE COMMENT
 
1935
  """
1936
  flow = dict(flow_raw or {}) if isinstance(flow_raw, dict) else {}
1937
  actions = [a for a in (flow.get("actions") or []) if isinstance(a, dict)]
1938
+ kept = [a for a in actions if not _is_untouched_ig_seed(a, table, enrich_kind)]
1939
  if len(kept) == len(actions):
1940
  return flow_raw
1941
  return {**flow, "actions": kept}
 
1944
  def ig_action_pinned(defn, index):
1945
  """Is this action the one that cannot be removed? Derived, never stored β€” a stored `pinned`
1946
  flag is a second copy of the rule, and the copy is what a hand-written PATCH omits."""
1947
+ # ⭐ WAVE 30 β€” BOTH discovery kinds. It read `== "discover_instagram"`, so TikTok's step 1 (once
1948
+ # seeded) would have rendered as an ordinary draggable, deletable card: the same rule the owner
1949
+ # asked for "EXACTLY", applied to only one network.
1950
+ return (defn or {}).get("kind") in DISCOVERY_KINDS and index == 0
1951
 
1952
 
1953
  def clean_definition(raw, previous=None, username=""):
 
1992
  # PREVIOUS one. Asking `"trigger" in raw` would fire on every empty patch, because
1993
  # `patch()` builds its raw as `dict(prev)` plus the caller's keys.
1994
  kind = DEFAULT_KIND
1995
+ # ⭐ WAVE 30 β€” un-seed on the way out, exactly as the Instagram arm below does. This line
1996
+ # was ABSENT and harmless for as long as TikTok had no seeds to leave behind; the moment
1997
+ # the seeder above learned TikTok, its absence became wave-27 item 15's defect on the other
1998
+ # network β€” a flow switched to Manual still carrying a "Save the profile" step nobody
1999
+ # planted deliberately. Found by widening the seeder and asking what else assumed only
2000
+ # Instagram could have seeds.
2001
+ drop_ig_seeds = True
2002
  elif (kind == "discover_instagram"
2003
  and ((prev.get("trigger") or {}) or {}).get("key") == "ig_profile_match"
2004
  and (trigger or {}).get("key") != "ig_profile_match"):
 
2109
  # ⭐ EVERY CLEAN, NOT ONLY THE EDGE (owner ruling 6 β€” see `_ensure_ig_action`). The edge-only
2110
  # call was what made the action deletable; running it on every save is what makes step 1
2111
  # permanent, and it is deliberate rather than a widened condition nobody noticed.
2112
+ # ⭐⭐ WAVE 30 (owner, 2026-08-12) β€” BOTH DISCOVERY TRIGGERS SEED, not just Instagram's. This
2113
+ # single `==` was the whole of *"why is it not copied EXACTLY"*: a TikTok search stored an
2114
+ # EMPTY flow, so the product's own rule β€” a search that finds profiles must have somewhere to
2115
+ # put them β€” held for one network and not the other.
2116
+ if (trigger or {}).get("key") in DISCOVERY_TRIGGER_KIND:
2117
+ _seed_table, _seed_enrich = discovery_seed_spec(kind)
2118
+ flow_raw = _ensure_ig_action(
2119
+ flow_raw, config.get("targetTable") or _seed_table, _seed_enrich)
2120
  elif drop_ig_seeds:
2121
+ # ITEM 15: the trigger just STOPPED being a discovery one. Un-seed what the trigger
2122
  # planted and nobody has since made theirs β€” measured against the table the seeds were
2123
  # planted for, which is the PREVIOUS config's, not the one being saved.
2124
+ # ⚠ And against the PREVIOUS kind's enrich action, for the same reason: the seeds to strip
2125
+ # are TikTok's if that is what was planted, and asking "is this Instagram's seed?" of a
2126
+ # TikTok flow answers no and silently leaves the leftover behind.
2127
+ _prev_table, _prev_enrich = discovery_seed_spec(prev.get("kind"))
2128
  flow_raw = _drop_ig_seeds(
2129
+ flow_raw, (prev.get("config") or {}).get("targetTable") or _prev_table, _prev_enrich)
2130
  flow, ferr = clean_flow(flow_raw, prev.get("flow"))
2131
  if ferr:
2132
  return None, ferr
2133
+ # ⭐ WAVE 30 β€” widened with the seeder above: TikTok now HAS a pinned step 1, so the rule that
2134
+ # its `config.table` is authoritative has to reach it, or the two fields that name one database
2135
+ # would disagree on exactly the network that just gained the card.
2136
+ if (trigger or {}).get("key") in DISCOVERY_TRIGGER_KIND:
2137
  # ⭐ WAVE 25 Β· R2 β€” THE CREATE RECORD ACTION'S `config.table` IS AUTHORITATIVE, and
2138
  # `config.targetTable` FOLLOWS IT. Two fields have been naming the same database since
2139
  # wave 24: the pinned step 1 says where profiles are written, and the config says where
 
2458
  cur[defn["id"]] = defn
2459
  return cur
2460
 
2461
+ # `async` for the reason spelled out at `remove` and applied at `patch` β€” a create is the same
2462
+ # blocking commit inside the same request, and the person is waiting on it in the same way.
2463
+ # ⚠ NO PRESET GUARD HERE, deliberately: `patch` may skip the spawn because it can compare
2464
+ # against a PREVIOUS definition, and a create has none β€” R10's columns must exist before a run,
2465
+ # so this call stays unconditional.
2466
+ rt.update(STORE_KEY, _up, flush="async")
2467
  _presets_after_write(rt, defn, username) # R10: the columns exist before a run
2468
  if defn.get("trigger"):
2469
  _seed_event_state(rt, defn)
 
2499
  cur[defn["id"]] = defn
2500
  return cur
2501
 
2502
+ # β›” WHY THIS IS `async` β€” owner report 2026-08-12 (wave 30), MEASURED on the deployed build.
2503
+ # Owner, verbatim: *"debug Automation module, its extremely slow, even renaming an Automation
2504
+ # takes forever"*. A rename paid a BLOCKING HF commit inside the request, and `Store.update`'s
2505
+ # sync branch holds `self._lock` across a strict DOWNLOAD **and** the upload β€” the same lock
2506
+ # `Store.get` takes β€” so one rename stalls every OTHER reader of that tenant's store for its
2507
+ # whole duration. That is the "module is slow" half a per-route fix never reaches.
2508
+ # The reasoning, the read-your-writes contract and the `user_tables.add_row` precedent are
2509
+ # written out in full at `remove` above (same wave, same owner report); this is that ruling
2510
+ # applied to the save path rather than a second argument for it.
2511
+ rt.update(STORE_KEY, _up, flush="async")
2512
+ # β›” THE PRESET SPAWN RUNS ONLY WHEN ITS OWN INPUTS MOVED β€” the other half of the same report.
2513
+ # MEASURED as `nurilab-admin` on `4258a93`: **7,912 ms** for one rename against a **288 ms**
2514
+ # warm `GET /automations` on the same connection, i.e. 27x the read this wave just made fast
2515
+ # (T12/T13). A rename changes `name`; `_presets_after_write` reads `config`, `flow` and
2516
+ # `trigger` and NOTHING else, then pays a full `user_tables` read (`ut_get`/`ut_ensure`;
2517
+ # `rt.get` deep-copies by design, documented ceiling 35.8 MB / ~1.4 s) to re-derive columns
2518
+ # that cannot have changed. ⭐ The generalisable half: T12/T13 took `ut_all` off the automation
2519
+ # READ path this wave and every sibling WRITE path still carried it β€” a performance fix scoped
2520
+ # to "the slow page" leaves the same call in every route beside it
2521
+ # [[read-a-gates-predicate-for-what-it-excludes]].
2522
+ # β›” THE DANGEROUS DIRECTION IS SKIPPING, NEVER RUNNING, so the predicate is the INPUT SET of
2523
+ # the function being skipped β€” not a hand-listed set of "cheap" edits, which is how a guard
2524
+ # silently un-ships W25/R10 the next time the spawn learns to read a fourth key. When none of
2525
+ # them moved the call is a no-op by construction (it re-derives from those same keys), and the
2526
+ # run-time `ut_ensure` R10 deliberately kept is still the backstop if the TABLE drifted
2527
+ # underneath β€” which is not a thing a rename should be repairing. Shaped after the trigger
2528
+ # comparison directly below, which already compares `prev` against the cleaned definition.
2529
+ if any((prev.get(k) or None) != (defn.get(k) or None)
2530
+ for k in ("config", "flow", "trigger", "kind")):
2531
+ _presets_after_write(rt, defn, username) # R10: also on the save that RE-TARGETS
2532
  # A2(1): a NEW or CHANGED condition trigger starts with everything currently matching
2533
  # DISARMED β€” enabling never fires for records already in the state.
2534
  if (defn.get("trigger") or {}) != ((prev.get("trigger")) or {}):
 
2645
  cur = cur if isinstance(cur, dict) else {}
2646
  cur.pop(aid, None)
2647
  return cur
2648
+ # β›” WHY THIS IS `async` AND NOT `sync` (owner report 2026-08-12, wave 30, MEASURED).
2649
+ # Owner, verbatim: *"it takes forever to delete an automation"*. A delete was paying up to
2650
+ # TWO BLOCKING UPLOADS inside the request β€” this one, plus the whole-document rewrite below,
2651
+ # which fires for every DISCOVERY automation because those always tag the columns they
2652
+ # spawned (deleting one marked all 30 columns of `ut_tt_profile` disabled). Measured 977 ms
2653
+ # for the CHEAPEST case (a `plain` flow, no tagged columns) against a 757 ms `GET /automations`
2654
+ # baseline on the same connection; the discovery case is strictly worse by a full-document
2655
+ # read plus a full-document commit.
2656
+ #
2657
+ # `flush="async"` is not a weakening: `Store.update`'s async branch applies the mutation to
2658
+ # the in-process cache, marks it owned+dirty and schedules a COALESCING worker, and the
2659
+ # class's read-your-writes contract means the very next `GET /automations` already sees the
2660
+ # deletion. This is the same trade `user_tables.add_row` makes for ROW creation β€” strictly
2661
+ # more valuable data than an automation definition β€” so a delete is not the place to be
2662
+ # stricter than a row insert. [[sync-write-eats-pending-async-write]] is the hazard in the
2663
+ # OTHER direction (a sync writer discarding a pending async write) and `Store.update`'s dirty
2664
+ # branch already handles it.
2665
+ rt.update(STORE_KEY, _up, flush="async")
2666
  # C8 β€” the fields this flow tagged are DISABLED with the reason on them, never orphaned
2667
  # silently: the column keeps its values and its config, and says why it stopped. Scanned
2668
  # first so a delete with no tagged fields costs no store commit.
2669
+ # ⚠ HONEST RESIDUAL, stated rather than smoothed: this scan still costs ONE full read of the
2670
+ # tenant's `user_tables` document on EVERY delete (`rt.get` deep-copies by design), and the
2671
+ # update below reads it a second time. Removing that needs a tagged-field index, which is a
2672
+ # feature and not a wave-tail edit β€” booked rather than improvised. What it no longer costs
2673
+ # is the part the owner could feel: the blocking network commits.
2674
  hit = any(str((f.get("automation") or {}).get("flowId") or "") == aid
2675
  for t in ut_all(rt).values() for f in (t.get("fields") or []))
2676
  if not hit:
 
2685
  a["disabled"] = True
2686
  a["statusNote"] = f"its automation was deleted {_stamp()}"
2687
  return cur
2688
+ # The expensive half of the owner's complaint: a whole-document rewrite, committed while the
2689
+ # person waits. Async for the reason given above β€” the disable is visible to the next read
2690
+ # immediately; only the upload is deferred, and it coalesces with any other pending write to
2691
+ # the same key instead of racing it.
2692
+ rt.update(UT_STORE_KEY, _disable, flush="async")
2693
 
2694
 
2695
  # ---------------------------------------------------------------------------------------------
 
8880
  tt["posts"].extend(tt_idents)
8881
  tt["psnaps"].extend(tt_metrics)
8882
  tt["comments"].extend(tt_comments)
8883
+ # ⭐⭐ WAVE 30 Β· T11 β€” A CAPABILITY THAT WAS ASKED FOR AND DID NOT ARRIVE IS
8884
+ # REPORTED. This is R6's second sentence applied to a capability rather than to
8885
+ # a row cap, and it was found the expensive way: the 09:14 UTC paid run on
8886
+ # nurilab enriched two profiles with `postMetrics` ON, wrote no posts, and said
8887
+ # NOTHING β€” `ok: true`, no note, no count β€” because `partial` takes the branch
8888
+ # ABOVE and only the `else` ever appended a note. Every `partial` return in
8889
+ # `pull_profile_tt` carries the reason in `note` (*"this account's row carried
8890
+ # no post links"*, *"the post source returned nothing"*, or the vendor's own
8891
+ # words), and all of them were being discarded. A person then sees two enriched
8892
+ # rows, an empty posts database and no explanation anywhere.
8893
+ # β›” ONLY WHEN IT WAS ASKED FOR, which is the difference between a report and
8894
+ # noise: with `postMetrics` off, `pull_profile_tt` returns `partial` + *"post
8895
+ # capture is off for this step"* for EVERY profile, and appending that would put
8896
+ # one useless line per record into the run entry and let the summary quote it.
8897
+ # β›” AND NOT WHEN THE BATCH DEFERRED β€” a deferral is not a failure to deliver,
8898
+ # it is a paid snapshot already filed for collection
8899
+ # (`ttEnrichMetricBatchesPending`, D-156), and reporting it as a miss would
8900
+ # teach a person to re-run and buy it twice.
8901
+ if (cfg.get("postMetrics") and not (res.get("posts") or [])
8902
+ and not (res.get("deferredMedia") or [])):
8903
+ _why = _s(res.get("note"), 300)
8904
+ if _why:
8905
+ tt["notes"].append(f"@{handle_raw} (TikTok): {_why}")
8906
  cells = tt_preset_cells(res, pulled)
8907
  if cfg.get("dryRun"):
8908
  tt["dry"] = True
api/connectors_tt.py CHANGED
@@ -240,7 +240,18 @@ def normalize_post(node):
240
  return _drop_blanks({
241
  "platform": engine.PLATFORM_TIKTOK,
242
  "shortcode": shortcode,
243
- "influencer_key": _tt_str(node, "profile_username"),
 
 
 
 
 
 
 
 
 
 
 
244
  "posted_at": _tt_day(node, "create_time"),
245
  "type": tt_post_type(node),
246
  "caption": _tt_str(node, "description"),
@@ -324,11 +335,19 @@ def tt_handle(url):
324
  def tt_post_urls(node, limit=0):
325
  """⭐ WAVE 30 Β· T10 β€” the profile row's own post permalinks, newest-first as the vendor sends.
326
 
327
- β›” THIS IS WHY TIKTOK POST CAPTURE COSTS NO EXTRA DISCOVERY. The probe measured `top_videos` as
328
- *"an array of video permalinks, NO empties"* on the PROFILE row we have already bought β€” so the
329
- posts read is a scrape of URLs we hold, never a search for them. The two TikTok DISCOVERY
330
- datasets (posts-by-profile, posts-by-keyword) are **404 for our key**, so a design that reached
331
- for either would not merely be dearer, it would not work.
 
 
 
 
 
 
 
 
332
 
333
  ⚠ `top_posts_data` is deliberately NOT read: the probe calls it *"a thin dup of `top_videos`"*,
334
  and preferring whichever happened to be longer is how one creator's window silently differs
@@ -341,9 +360,33 @@ def tt_post_urls(node, limit=0):
341
  raw = (node or {}).get("top_videos")
342
  out = []
343
  for item in raw if isinstance(raw, list) else []:
344
- # The array is documented as permalinks; a vendor that starts sending objects instead must
345
- # degrade to "no posts", never to a URL built out of a guess.
346
- u = str(item.get("url") or "").strip() if isinstance(item, dict) else str(item or "").strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  if u.lower().startswith("http") and u not in out:
348
  out.append(u)
349
  return out[:limit] if limit and limit > 0 else out
 
240
  return _drop_blanks({
241
  "platform": engine.PLATFORM_TIKTOK,
242
  "shortcode": shortcode,
243
+ # β›”β›” `account_id`, NOT `profile_username` β€” MEASURED on a real Posts row 2026-08-12.
244
+ # The vendor's `profile_username` is the DISPLAY NAME (`"Dina"`), while `account_id` is the
245
+ # @handle (`"d1na_th"`) β€” the same field `normalize_profile` already reads for `handle`, so
246
+ # one name means one thing across both corpora. Reading the display name silently broke the
247
+ # only join this table has: `ut_tt_posts.influencer_key` -> `ut_tt_profile.handle` matched
248
+ # NOTHING, so a person could not filter posts by creator and a rollup would count zero.
249
+ # ⚠ NO FALLBACK TO `profile_username`, deliberately. It is not a degraded handle, it is a
250
+ # different fact, and filling a join key with it is worse than leaving it blank β€” a blank
251
+ # is visibly missing, a display name looks like an answer [[one-question-two-normalizers]].
252
+ # The URL is the honest second source: it carries the handle by construction.
253
+ "influencer_key": (_tt_str(node, "account_id")
254
+ or tt_handle(_tt_str(node, "profile_url", "url") or "") or None),
255
  "posted_at": _tt_day(node, "create_time"),
256
  "type": tt_post_type(node),
257
  "caption": _tt_str(node, "description"),
 
335
  def tt_post_urls(node, limit=0):
336
  """⭐ WAVE 30 Β· T10 β€” the profile row's own post permalinks, newest-first as the vendor sends.
337
 
338
+ β›” THIS IS WHY TIKTOK POST CAPTURE COSTS NO EXTRA DISCOVERY. `top_videos` rides the PROFILE row
339
+ we have already bought, so the posts read is a scrape of links we hold, never a search for them.
340
+ The two TikTok DISCOVERY datasets (posts-by-profile, posts-by-keyword) are **404 for our key**,
341
+ so a design that reached for either would not merely be dearer, it would not work.
342
+
343
+ β›”β›” CORRECTED 2026-08-12 β€” THIS DOCSTRING USED TO SAY *"the probe MEASURED `top_videos` as an
344
+ array of video permalinks, NO empties"*, AND THAT SENTENCE IS WHAT SHIPPED THE BUG. The probe
345
+ read `/datasets/{id}/metadata` β€” a DATASET description β€” and the phrase quoted was the field's
346
+ `ai_description`, not an observation of a row. The real row sends **dicts keyed `video_url`**
347
+ (measured below), so the reader built against the quoted sentence found nothing, forever, in
348
+ silence. ⭐ The transferable half: *"the probe measured X"* and *"the probe read a declaration
349
+ of X"* are different claims, and prose cannot be told apart by a reader downstream β€” which is
350
+ why the correction names the method, not just the value.
351
 
352
  ⚠ `top_posts_data` is deliberately NOT read: the probe calls it *"a thin dup of `top_videos`"*,
353
  and preferring whichever happened to be longer is how one creator's window silently differs
 
360
  raw = (node or {}).get("top_videos")
361
  out = []
362
  for item in raw if isinstance(raw, list) else []:
363
+ # β›”β›” MEASURED ON A REAL ROW 2026-08-12, AND IT IS NOT WHAT THE SCHEMA SAID.
364
+ # `top_videos` is NOT an array of permalink strings. One paid TikTok Profiles scrape of a
365
+ # live handle returns **19 DICTS**, keyed
366
+ # `video_url Β· video_id Β· playcount Β· diggcount Β· commentcount Β· share_count Β·
367
+ # favorites_count Β· create_date Β· cover_image`.
368
+ # The docstring above cites the $0 probe as having "measured" permalinks β€” it had not, and
369
+ # could not: `/datasets/{id}/metadata` describes a DATASET, and the probe's own verdict says
370
+ # so in terms (*"what $0 cannot buy … the real ROW shape … that a declared field
371
+ # POPULATES"*, `wave29/proto/tiktok-schema.md`). This is the SECOND time this vendor's
372
+ # declaration has diverged from its delivery on this exact axis; BD's IG Reels `views` was
373
+ # the first. [[reachable-is-not-the-same-as-built]]
374
+ # β‡’ The consequence, live: `TT_DS_POSTS` was never reached, because this returned an EMPTY
375
+ # list on every real profile β€” post capture could not have worked for anybody, and the
376
+ # T10 gate stayed green because its canned fixture encoded the DECLARED shape. A fixture
377
+ # written from a schema tests the schema.
378
+ # ⚠ `video_url` is FIRST because it is the key the vendor actually sends; `url` is kept
379
+ # because it costs nothing and is what a future corpus revision would most likely use. The
380
+ # bare-string branch stays for the same reason β€” this widens what is ACCEPTED and invents
381
+ # nothing: a shape that yields no `http…` value still degrades to "no posts", exactly as
382
+ # before, rather than to a URL built out of a guess.
383
+ # ⚠ `top_posts_data` is STILL not read (it carries `post_url` and would work): preferring
384
+ # whichever array happened to be longer is how one creator's window silently differs from
385
+ # another's, and that reasoning is unchanged by this correction.
386
+ if isinstance(item, dict):
387
+ u = str(item.get("video_url") or item.get("url") or "").strip()
388
+ else:
389
+ u = str(item or "").strip()
390
  if u.lower().startswith("http") and u not in out:
391
  out.append(u)
392
  return out[:limit] if limit and limit > 0 else out