Spaces:
Sleeping
Sleeping
Claude Code commited on
Commit Β·
fd0440c
1
Parent(s): f80944f
Claude Code: Cain is showing RUNTIME_ERROR status. I need you to:
Browse files
scripts/__pycache__/sync_hf.cpython-311.pyc
ADDED
|
Binary file (50.9 kB). View file
|
|
|
scripts/sync_hf.py
CHANGED
|
@@ -186,6 +186,7 @@ class OpenClawFullSync:
|
|
| 186 |
self.enabled = False
|
| 187 |
self.dataset_exists = False
|
| 188 |
self.api = None
|
|
|
|
| 189 |
|
| 190 |
if not HF_TOKEN:
|
| 191 |
print("[SYNC] WARNING: HF_TOKEN not set. Persistence disabled.")
|
|
@@ -199,6 +200,44 @@ class OpenClawFullSync:
|
|
| 199 |
self.api = HfApi(token=HF_TOKEN)
|
| 200 |
self.dataset_exists = self._ensure_repo_exists()
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
# ββ Repo management ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 203 |
|
| 204 |
def _ensure_repo_exists(self):
|
|
@@ -284,6 +323,11 @@ class OpenClawFullSync:
|
|
| 284 |
self._patch_config()
|
| 285 |
self._debug_list_files()
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
# ββ Save (periodic + shutdown) βββββββββββββββββββββββββββββββββββββ
|
| 288 |
|
| 289 |
def save_to_repo(self):
|
|
@@ -299,6 +343,11 @@ class OpenClawFullSync:
|
|
| 299 |
print(f"[SYNC] Dataset {HF_REPO_ID} unavailable - skipping save")
|
| 300 |
return
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
print(f"[SYNC] βΆ Uploading ~/.openclaw β dataset {HF_REPO_ID}/{DATASET_PATH}/ ...")
|
| 303 |
|
| 304 |
try:
|
|
@@ -334,6 +383,9 @@ class OpenClawFullSync:
|
|
| 334 |
)
|
| 335 |
print(f"[SYNC] β Upload completed at {datetime.now().isoformat()}")
|
| 336 |
|
|
|
|
|
|
|
|
|
|
| 337 |
# Verify (summary only)
|
| 338 |
try:
|
| 339 |
files = self.api.list_repo_files(repo_id=HF_REPO_ID, repo_type="dataset")
|
|
@@ -343,6 +395,12 @@ class OpenClawFullSync:
|
|
| 343 |
pass
|
| 344 |
|
| 345 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
print(f"[SYNC] β Upload failed: {e}")
|
| 347 |
traceback.print_exc()
|
| 348 |
|
|
|
|
| 186 |
self.enabled = False
|
| 187 |
self.dataset_exists = False
|
| 188 |
self.api = None
|
| 189 |
+
self._last_upload_hash = None # Track last uploaded state
|
| 190 |
|
| 191 |
if not HF_TOKEN:
|
| 192 |
print("[SYNC] WARNING: HF_TOKEN not set. Persistence disabled.")
|
|
|
|
| 200 |
self.api = HfApi(token=HF_TOKEN)
|
| 201 |
self.dataset_exists = self._ensure_repo_exists()
|
| 202 |
|
| 203 |
+
def _compute_files_hash(self):
|
| 204 |
+
"""Compute a hash of file paths and mtimes to detect changes efficiently."""
|
| 205 |
+
import hashlib
|
| 206 |
+
file_hash = hashlib.sha256()
|
| 207 |
+
|
| 208 |
+
# Get all files, sorted for consistent hashing
|
| 209 |
+
files_list = []
|
| 210 |
+
for root, dirs, files in os.walk(OPENCLAW_HOME):
|
| 211 |
+
for fn in files:
|
| 212 |
+
# Skip ignored patterns
|
| 213 |
+
if any(fn.endswith(p.strip('*')) for p in ['*.log', '*.lock', '*.tmp', '*.pid']):
|
| 214 |
+
continue
|
| 215 |
+
if '__pycache__' in root:
|
| 216 |
+
continue
|
| 217 |
+
fp = os.path.join(root, fn)
|
| 218 |
+
files_list.append(fp)
|
| 219 |
+
|
| 220 |
+
# Hash based on file paths and modification times (much faster than reading content)
|
| 221 |
+
for fp in sorted(files_list):
|
| 222 |
+
try:
|
| 223 |
+
stat = os.stat(fp)
|
| 224 |
+
# Include path, size, and mtime in hash
|
| 225 |
+
file_hash.update(fp.encode())
|
| 226 |
+
file_hash.update(str(stat.st_size).encode())
|
| 227 |
+
file_hash.update(str(stat.st_mtime).encode())
|
| 228 |
+
except Exception:
|
| 229 |
+
# File might be locked or inaccessible - skip it
|
| 230 |
+
pass
|
| 231 |
+
|
| 232 |
+
return file_hash.hexdigest()
|
| 233 |
+
|
| 234 |
+
def _has_changes(self):
|
| 235 |
+
"""Check if any files have changed since last upload."""
|
| 236 |
+
current_hash = self._compute_files_hash()
|
| 237 |
+
if self._last_upload_hash is None:
|
| 238 |
+
return True
|
| 239 |
+
return current_hash != self._last_upload_hash
|
| 240 |
+
|
| 241 |
# ββ Repo management ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 242 |
|
| 243 |
def _ensure_repo_exists(self):
|
|
|
|
| 323 |
self._patch_config()
|
| 324 |
self._debug_list_files()
|
| 325 |
|
| 326 |
+
# Initialize hash after restore to avoid unnecessary first upload
|
| 327 |
+
if self.enabled and OPENCLAW_HOME.exists():
|
| 328 |
+
self._last_upload_hash = self._compute_files_hash()
|
| 329 |
+
print(f"[SYNC] Initialized change detection hash")
|
| 330 |
+
|
| 331 |
# ββ Save (periodic + shutdown) βββββββββββββββββββββββββββββββββββββ
|
| 332 |
|
| 333 |
def save_to_repo(self):
|
|
|
|
| 343 |
print(f"[SYNC] Dataset {HF_REPO_ID} unavailable - skipping save")
|
| 344 |
return
|
| 345 |
|
| 346 |
+
# Check for changes before attempting upload
|
| 347 |
+
if not self._has_changes():
|
| 348 |
+
print(f"[SYNC] No changes detected since last sync. Skipping upload.")
|
| 349 |
+
return
|
| 350 |
+
|
| 351 |
print(f"[SYNC] βΆ Uploading ~/.openclaw β dataset {HF_REPO_ID}/{DATASET_PATH}/ ...")
|
| 352 |
|
| 353 |
try:
|
|
|
|
| 383 |
)
|
| 384 |
print(f"[SYNC] β Upload completed at {datetime.now().isoformat()}")
|
| 385 |
|
| 386 |
+
# Update hash after successful upload
|
| 387 |
+
self._last_upload_hash = self._compute_files_hash()
|
| 388 |
+
|
| 389 |
# Verify (summary only)
|
| 390 |
try:
|
| 391 |
files = self.api.list_repo_files(repo_id=HF_REPO_ID, repo_type="dataset")
|
|
|
|
| 395 |
pass
|
| 396 |
|
| 397 |
except Exception as e:
|
| 398 |
+
error_msg = str(e)
|
| 399 |
+
# Handle empty commit gracefully - this is not an error
|
| 400 |
+
if "No files have been modified" in error_msg or "empty commit" in error_msg.lower():
|
| 401 |
+
print(f"[SYNC] No changes to commit (already in sync)")
|
| 402 |
+
self._last_upload_hash = self._compute_files_hash()
|
| 403 |
+
return
|
| 404 |
print(f"[SYNC] β Upload failed: {e}")
|
| 405 |
traceback.print_exc()
|
| 406 |
|