Powerman9x commited on
Commit
3ee8a74
Β·
verified Β·
1 Parent(s): b6a037a

Upload sync_hf.py

Browse files
Files changed (1) hide show
  1. scripts/sync_hf.py +50 -14
scripts/sync_hf.py CHANGED
@@ -621,24 +621,60 @@ class OpenClawFullSync:
621
  # ── Application runner ─────────────────────────────────────────────
622
 
623
  def run_doctor_fix(self):
624
- """Run `openclaw doctor --fix` so pending state-DB schema migrations
625
- (e.g. audit-events-v2) are applied BEFORE the gateway starts.
626
- Exit code 78 = gateway.maintenance_required."""
 
 
 
 
627
  if not (APP_DIR / "dist" / "entry.js").exists():
628
- return
629
- print("[SYNC] Running `openclaw doctor --fix` (schema migrations)...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
630
  try:
631
- r = subprocess.run(
632
- ["node", "dist/entry.js", "doctor", "--fix"],
633
- cwd=str(APP_DIR), env=os.environ.copy(),
634
- capture_output=True, text=True, timeout=300,
 
635
  )
636
- tail = (r.stdout + r.stderr).strip().splitlines()[-15:]
637
- for line in tail:
638
- print(f"[DOCTOR] {line}")
639
- print(f"[SYNC] doctor --fix exit code: {r.returncode}")
640
  except Exception as e:
641
- print(f"[SYNC] doctor --fix failed: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
 
643
  def run_openclaw(self):
644
  log_file = OPENCLAW_HOME / "workspace" / "startup.log"
 
621
  # ── Application runner ─────────────────────────────────────────────
622
 
623
  def run_doctor_fix(self):
624
+ """Apply pending OpenClaw state-DB migrations (e.g. audit-events-v2)
625
+ BEFORE the gateway starts. Output is streamed live so a hang is visible.
626
+
627
+ Env knobs: DOCTOR_TIMEOUT (seconds, default 900), SKIP_DOCTOR=1."""
628
+ if os.environ.get("SKIP_DOCTOR") == "1":
629
+ print("[SYNC] SKIP_DOCTOR=1 β€” skipping doctor")
630
+ return True
631
  if not (APP_DIR / "dist" / "entry.js").exists():
632
+ return True
633
+ timeout = int(os.environ.get("DOCTOR_TIMEOUT", "900"))
634
+
635
+ env = os.environ.copy()
636
+ env["CI"] = "1"
637
+ env["NO_COLOR"] = "1"
638
+ # Drop --require/-r preloads (telegram-proxy, token-redirect, ...): they
639
+ # keep timers/sockets open and can stop a short-lived CLI from exiting.
640
+ no = env.get("NODE_OPTIONS", "")
641
+ no = re.sub(r"(--require[= ]\S+|-r \S+)", "", no).strip()
642
+ if no:
643
+ env["NODE_OPTIONS"] = no
644
+ else:
645
+ env.pop("NODE_OPTIONS", None)
646
+
647
+ cmd = ["node", "dist/entry.js", "doctor", "--fix", "--non-interactive"]
648
+ print(f"[SYNC] Running: {' '.join(cmd)} (timeout={timeout}s)")
649
+ t0 = time.time()
650
  try:
651
+ proc = subprocess.Popen(
652
+ cmd, cwd=str(APP_DIR), env=env,
653
+ stdin=subprocess.DEVNULL,
654
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
655
+ text=True, bufsize=1, start_new_session=True,
656
  )
 
 
 
 
657
  except Exception as e:
658
+ print(f"[SYNC] could not start doctor: {e}")
659
+ return False
660
+
661
+ def pump():
662
+ for line in proc.stdout:
663
+ print(f"[DOCTOR +{time.time() - t0:.0f}s] {line.rstrip()}", flush=True)
664
+ th = threading.Thread(target=pump, daemon=True)
665
+ th.start()
666
+ try:
667
+ rc = proc.wait(timeout=timeout)
668
+ except subprocess.TimeoutExpired:
669
+ print(f"[SYNC] doctor exceeded {timeout}s β€” killing it")
670
+ try:
671
+ os.killpg(proc.pid, signal.SIGKILL)
672
+ except Exception:
673
+ proc.kill()
674
+ return False
675
+ th.join(timeout=5)
676
+ print(f"[SYNC] doctor --fix exit code: {rc} ({time.time() - t0:.0f}s)")
677
+ return rc == 0
678
 
679
  def run_openclaw(self):
680
  log_file = OPENCLAW_HOME / "workspace" / "startup.log"