Spaces:
Sleeping
Sleeping
fix: always derive dataset from SPACE_ID, ignore OPENCLAW_DATASET_REPO on HF
Browse filesWhen running on HF Spaces (SPACE_ID is set), always use
{SPACE_ID}-data as the dataset name. This prevents duplicated
Spaces from inheriting the original's dataset via copied secrets.
OPENCLAW_DATASET_REPO is only used for local Docker without SPACE_ID.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
79 unmodified lines808182838485868788899091929394959697989910010110210310479 unmodified linesSYNC_INTERVAL = int(os.environ.get("SYNC_INTERVAL", "60"))AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")# Dataset repo: always auto-derive from SPACE_ID when not explicitly set.# Format: {username}/{SpaceName}-data (e.g. "tao-shen/HuggingClaw-data")# This ensures each duplicated Space gets its own dataset automatically.HF_REPO_ID = os.environ.get("OPENCLAW_DATASET_REPO", "")if not HF_REPO_ID and SPACE_ID:# SPACE_ID = "username/SpaceName" → derive "username/SpaceName-data"HF_REPO_ID = f"{SPACE_ID}-data"print(f"[SYNC] OPENCLAW_DATASET_REPO not set — auto-derived from SPACE_ID: {HF_REPO_ID}")elif not HF_REPO_ID and HF_TOKEN:# Fallback: no SPACE_ID (local Docker), derive from HF_TOKEN usernametry:_api = HfApi(token=HF_TOKEN)_username = _api.whoami()["name"]HF_REPO_ID = f"{_username}/HuggingClaw-data"print(f"[SYNC] OPENCLAW_DATASET_REPO not set — auto-derived from HF_TOKEN: {HF_REPO_ID}")del _api, _usernameexcept Exception as e:print(f"[SYNC] WARNING: Could not derive username from HF_TOKEN: {e}")HF_REPO_ID = ""# Setup logginglog_dir = OPENCLAW_HOME / "workspace"79 unmodified lines808182838485868788899091929394959697989910010110210310410510610710810911011111279 unmodified linesSYNC_INTERVAL = int(os.environ.get("SYNC_INTERVAL", "60"))AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")# Dataset repo: always derive from SPACE_ID to ensure each Space uses its own dataset.# OPENCLAW_DATASET_REPO is only used as fallback when SPACE_ID is not available (local Docker)._user_repo = os.environ.get("OPENCLAW_DATASET_REPO", "")if SPACE_ID:# Always use SPACE_ID — prevents duplicated Spaces from sharing the original's datasetHF_REPO_ID = f"{SPACE_ID}-data"if _user_repo and _user_repo != HF_REPO_ID:print(f"[SYNC] NOTE: Ignoring OPENCLAW_DATASET_REPO={_user_repo} — using SPACE_ID-derived: {HF_REPO_ID}")else:print(f"[SYNC] Dataset repo auto-derived from SPACE_ID: {HF_REPO_ID}")elif _user_repo:HF_REPO_ID = _user_repoprint(f"[SYNC] Using OPENCLAW_DATASET_REPO: {HF_REPO_ID}")elif HF_TOKEN:# Fallback: no SPACE_ID (local Docker), derive from HF_TOKEN usernametry:_api = HfApi(token=HF_TOKEN)_username = _api.whoami()["name"]HF_REPO_ID = f"{_username}/HuggingClaw-data"print(f"[SYNC] Dataset repo auto-derived from HF_TOKEN: {HF_REPO_ID}")del _api, _usernameexcept Exception as e:print(f"[SYNC] WARNING: Could not derive username from HF_TOKEN: {e}")HF_REPO_ID = ""else:HF_REPO_ID = ""del _user_repo# Setup logginglog_dir = OPENCLAW_HOME / "workspace"
scripts/sync_hf.py+17-9