fsanyoto commited on
Commit
b8caa46
Β·
verified Β·
1 Parent(s): b51b46f

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
Files changed (3) hide show
  1. RELEASES.json +1 -1
  2. VERSION +1 -1
  3. api/automation_engine.py +35 -10
RELEASES.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "current": "7799d94",
3
  "releases": [
4
  {
5
  "version": "v12",
 
1
  {
2
+ "current": "2dcd7b3",
3
  "releases": [
4
  {
5
  "version": "v12",
VERSION CHANGED
@@ -1 +1 @@
1
- 7799d94
 
1
+ 2dcd7b3
api/automation_engine.py CHANGED
@@ -958,7 +958,12 @@ def clean_config(kind, raw, previous=None):
958
  "one shape the vendor refuses outright (NOT_ENOUGH_FUNDS)")
959
  if limit > BD_MAX_RECORDS:
960
  return None, f"a single discovery run may ask for at most {BD_MAX_RECORDS} profiles"
961
- preds, perr = clean_predicates(raw.get("predicates"))
 
 
 
 
 
962
  if perr:
963
  return None, perr
964
  if raw.get("lanes") if "lanes" in raw else prev.get("lanes"):
@@ -970,7 +975,7 @@ def clean_config(kind, raw, previous=None):
970
  if not target.startswith(UT_PREFIX):
971
  target = UT_PREFIX + target
972
  return {"recordsLimit": limit, "predicates": preds,
973
- "operator": "or" if str(raw.get("operator") or "").lower() == "or" else "and",
974
  "targetTable": target,
975
  "targetLabel": _s(raw.get("targetLabel"), 60).strip() or "IG candidates",
976
  "dryRun": flag("dryRun")}, None
@@ -2343,11 +2348,31 @@ def predicate_narrows(p):
2343
  and str((p or {}).get("operator") or "") in BD_NARROWING_OPS)
2344
 
2345
 
2346
- def narrowing_refusal(preds):
2347
- """C4's server law: the sentence when a predicate set has ZERO narrowing predicates, else
2348
- ''. One function so create/patch (via `clean_predicates`) and RUN (legacy stored configs
2349
- predate the law) refuse in the same words."""
2350
- if any(predicate_narrows(p) for p in preds or []):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2351
  return ""
2352
  return ("add at least one CONTENT condition (biography includes …, account =, a hashtag) β€” "
2353
  "number and yes/no filters alone make the vendor scan the whole 620-million-row "
@@ -2388,7 +2413,7 @@ CANDIDATE_FIELDS = [
2388
  ]
2389
 
2390
 
2391
- def clean_predicates(raw):
2392
  """Validate a discovery filter into the vendor's shape. Returns `(predicates, error)`.
2393
 
2394
  Refuses rather than coerces: a predicate naming a field the API rejects comes back as a
@@ -2430,7 +2455,7 @@ def clean_predicates(raw):
2430
  return [], None
2431
  # C4 (wave 22): breadth is refused at WRITE time too β€” see `narrowing_refusal` for the
2432
  # measured hang this guards against. Same sentence at create/patch and at run.
2433
- guard_err = narrowing_refusal(out)
2434
  if guard_err:
2435
  return None, guard_err
2436
  return out, None
@@ -3147,7 +3172,7 @@ def run_discover_instagram(rt, defn, username="automation", log=print, step=_no_
3147
  if not pending:
3148
  # C4 (wave 22): the guard holds at RUN too β€” a stored config can predate the law, and
3149
  # the vendor bills for breadth whether the filter was saved yesterday or last month.
3150
- guard_err = narrowing_refusal(preds)
3151
  if guard_err:
3152
  steps["find"] = "blocked"
3153
  return ("error", f"the search was not started β€” {guard_err}", counts, [], steps)
 
958
  "one shape the vendor refuses outright (NOT_ENOUGH_FUNDS)")
959
  if limit > BD_MAX_RECORDS:
960
  return None, f"a single discovery run may ask for at most {BD_MAX_RECORDS} profiles"
961
+ # ⚠ THE JOIN IS RESOLVED BEFORE THE PREDICATES ARE JUDGED, because it is part of what
962
+ # makes them broad or narrow (see `narrowing_refusal`). Validating them first and reading
963
+ # the operator afterwards is how the OR hole survived: the guard was handed the branches
964
+ # and never told they were a union.
965
+ join = "or" if str(raw.get("operator") or "").lower() == "or" else "and"
966
+ preds, perr = clean_predicates(raw.get("predicates"), join)
967
  if perr:
968
  return None, perr
969
  if raw.get("lanes") if "lanes" in raw else prev.get("lanes"):
 
975
  if not target.startswith(UT_PREFIX):
976
  target = UT_PREFIX + target
977
  return {"recordsLimit": limit, "predicates": preds,
978
+ "operator": join,
979
  "targetTable": target,
980
  "targetLabel": _s(raw.get("targetLabel"), 60).strip() or "IG candidates",
981
  "dryRun": flag("dryRun")}, None
 
2348
  and str((p or {}).get("operator") or "") in BD_NARROWING_OPS)
2349
 
2350
 
2351
+ def narrowing_refusal(preds, operator="and"):
2352
+ """C4's server law: the sentence when a predicate set does not narrow, else ''. One function
2353
+ so create/patch (via `clean_predicates`) and RUN (legacy stored configs predate the law)
2354
+ refuse in the same words.
2355
+
2356
+ ⭐ THE JOIN IS PART OF THE LAW, and it was missed for two waves. The guard asked "does ANY
2357
+ predicate narrow?" β€” a question that is only correct under AND. Under **OR** the result is a
2358
+ UNION, so the query is exactly as broad as its WIDEST branch: `biography includes "florist" OR
2359
+ followers >= 10000` saved clean and asked the vendor for every account over ten thousand
2360
+ followers, which is the measured 50-minute / NOT_ENOUGH_FUNDS shape the guard exists to stop.
2361
+ A money wall that a dropdown three rows above it can walk through is not a wall.
2362
+
2363
+ So: under OR every branch must narrow; under AND one is enough. An EMPTY set never narrows
2364
+ either way β€” `all([])` is True, which would have made "no conditions at all" the widest legal
2365
+ query of the lot.
2366
+ """
2367
+ preds = list(preds or [])
2368
+ if str(operator or "").lower() == "or":
2369
+ if preds and all(predicate_narrows(p) for p in preds):
2370
+ return ""
2371
+ return ("with Match set to ANY, EVERY condition has to be a content one (biography "
2372
+ "includes …, account =, a hashtag) β€” 'any of them' asks the vendor for the UNION, "
2373
+ "so one number or yes/no branch makes the whole search as broad as that branch. "
2374
+ "Either narrow every condition or set Match to ALL")
2375
+ if any(predicate_narrows(p) for p in preds):
2376
  return ""
2377
  return ("add at least one CONTENT condition (biography includes …, account =, a hashtag) β€” "
2378
  "number and yes/no filters alone make the vendor scan the whole 620-million-row "
 
2413
  ]
2414
 
2415
 
2416
+ def clean_predicates(raw, operator="and"):
2417
  """Validate a discovery filter into the vendor's shape. Returns `(predicates, error)`.
2418
 
2419
  Refuses rather than coerces: a predicate naming a field the API rejects comes back as a
 
2455
  return [], None
2456
  # C4 (wave 22): breadth is refused at WRITE time too β€” see `narrowing_refusal` for the
2457
  # measured hang this guards against. Same sentence at create/patch and at run.
2458
+ guard_err = narrowing_refusal(out, operator)
2459
  if guard_err:
2460
  return None, guard_err
2461
  return out, None
 
3172
  if not pending:
3173
  # C4 (wave 22): the guard holds at RUN too β€” a stored config can predate the law, and
3174
  # the vendor bills for breadth whether the filter was saved yesterday or last month.
3175
+ guard_err = narrowing_refusal(preds, cfg.get("operator"))
3176
  if guard_err:
3177
  steps["find"] = "blocked"
3178
  return ("error", f"the search was not started β€” {guard_err}", counts, [], steps)