Claude Code commited on
Commit
a8ac8cc
·
1 Parent(s): fbf13b2

Claude Code: Review Cain's current environment configuration and prepare a detailed c

Browse files
Files changed (1) hide show
  1. HF_DATASET_CONFIGURATION_REPORT.md +275 -0
HF_DATASET_CONFIGURATION_REPORT.md ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # HuggingFace Dataset Persistence Configuration Report
2
+ **For Cain (tao-shen/HuggingClaw-Cain)**
3
+ **Generated:** 2026-03-14
4
+
5
+ ---
6
+
7
+ ## Executive Summary
8
+
9
+ Cain is currently **MISSING CRITICAL ENVIRONMENT VARIABLES** for data persistence. Without these, all conversations, settings, and credentials will be **LOST** when the Space restarts.
10
+
11
+ **Current Status:** ⚠️ **NOT CONFIGURED** - Data persistence is DISABLED
12
+
13
+ ---
14
+
15
+ ## Required Environment Variables
16
+
17
+ | Variable | Purpose | Required | Current Value | Expected Value |
18
+ |----------|---------|----------|---------------|----------------|
19
+ | `HF_TOKEN` | HuggingFace access token with WRITE permission | **YES** | ❌ NOT SET | `hf_***` (your token) |
20
+ | `OPENCLAW_DATASET_REPO` | Target Dataset repository ID | AUTO* | ❌ NOT SET | `tao-shen/HuggingClaw-Cain-data` |
21
+ | `AUTO_CREATE_DATASET` | Auto-create Dataset repo if missing | NO | ❌ NOT SET | `true` (recommended) |
22
+
23
+ \* **Note:** `OPENCLAW_DATASET_REPO` is automatically derived from `SPACE_ID` if not set:
24
+ - Space ID: `tao-shen/HuggingClaw-Cain`
25
+ - Auto-derived Dataset: `tao-shen/HuggingClaw-Cain-data`
26
+
27
+ ---
28
+
29
+ ## Detailed Variable Descriptions
30
+
31
+ ### 1. `HF_TOKEN` (REQUIRED)
32
+
33
+ **Purpose:** Authentication token for HuggingFace API with write permissions to create/access datasets.
34
+
35
+ **How to Generate:**
36
+ 1. Visit: https://huggingface.co/settings/tokens
37
+ 2. Click "Create new token"
38
+ 3. Select type: **Write** (must have write permissions for dataset operations)
39
+ 4. Copy the generated token (starts with `hf_`)
40
+
41
+ **Format:** `hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
42
+
43
+ ---
44
+
45
+ ### 2. `OPENCLAW_DATASET_REPO` (OPTIONAL - Auto-derived)
46
+
47
+ **Purpose:** Specifies which Dataset repository to use for backing up `~/.openclaw` data.
48
+
49
+ **Behavior:**
50
+ - **If NOT set:** Automatically derived from `SPACE_ID` as `{SPACE_ID}-data`
51
+ - Current SPACE_ID: `tao-shen/HuggingClaw-Cain`
52
+ - Auto-derived: `tao-shen/HuggingClaw-Cain-data`
53
+ - **If set manually:** Uses the specified repository ID
54
+
55
+ **Format:** `username/dataset-name`
56
+
57
+ **Example:** `tao-shen/HuggingClaw-Cain-data`
58
+
59
+ ---
60
+
61
+ ### 3. `AUTO_CREATE_DATASET` (OPTIONAL - Recommended)
62
+
63
+ **Purpose:** Controls whether HuggingClaw automatically creates the Dataset repository on first startup.
64
+
65
+ **Values:**
66
+ - `true` - Auto-create private Dataset repo if it doesn't exist
67
+ - `false` (default) - Require manual Dataset creation
68
+
69
+ **Recommendation:** Set to `true` for automatic setup
70
+
71
+ ---
72
+
73
+ ## Step-by-Step Configuration Instructions
74
+
75
+ ### Step 1: Generate HF_TOKEN
76
+
77
+ 1. Go to https://huggingface.co/settings/tokens
78
+ 2. Click **"New token"**
79
+ 3. **Token type:** Select **"Write"** (required for dataset operations)
80
+ 4. **Token name:** Enter `HuggingClaw-Cain` (or any descriptive name)
81
+ 5. Click **"Generate token"**
82
+ 6. **Copy the token** - it will look like `hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
83
+
84
+ ⚠️ **IMPORTANT:** The token is only shown once. Save it securely.
85
+
86
+ ---
87
+
88
+ ### Step 2: Configure Space Settings
89
+
90
+ 1. Go to your Space: https://huggingface.co/spaces/tao-shen/HuggingClaw-Cain/settings
91
+ 2. Scroll to **"Repository Secrets"** section
92
+ 3. Add the following secrets:
93
+
94
+ | Name | Value | Secret |
95
+ |------|-------|--------|
96
+ | `HF_TOKEN` | `hf_***` (your token from Step 1) | ✅ Yes |
97
+ | `AUTO_CREATE_DATASET` | `true` | ❌ No |
98
+
99
+ 4. Click **"Save"** for each secret added
100
+
101
+ **Optional Variable (if you want custom Dataset name):**
102
+ | Name | Value | Secret |
103
+ |------|-------|--------|
104
+ | `OPENCLAW_DATASET_REPO` | `tao-shen/HuggingClaw-Cain-data` | ❌ No |
105
+
106
+ **Note:** If you don't set `OPENCLAW_DATASET_REPO`, it will be auto-derived from SPACE_ID.
107
+
108
+ ---
109
+
110
+ ### Step 3: Restart the Space
111
+
112
+ After adding environment variables:
113
+
114
+ 1. Go to **Settings** tab
115
+ 2. Scroll to **"Factory reset"** section
116
+ 3. Click **"Factory reset and reboot"** (this ensures clean restart with new env vars)
117
+ 4. Wait ~2-3 minutes for the Space to restart
118
+ 5. Monitor logs to verify Dataset setup
119
+
120
+ ---
121
+
122
+ ### Step 4: Verify Configuration
123
+
124
+ After restart, check the logs for:
125
+
126
+ ```
127
+ [SYNC] OPENCLAW_DATASET_REPO not set — auto-derived from SPACE_ID: tao-shen/HuggingClaw-Cain-data
128
+ [SYNC] Dataset repo NOT found: tao-shen/HuggingClaw-Cain-data — creating...
129
+ [SYNC] ✓ Dataset repo created: tao-shen/HuggingClaw-Cain-data
130
+ [SYNC] ▶ Restoring ~/.openclaw from dataset tao-shen/HuggingClaw-Cain-data ...
131
+ ```
132
+
133
+ Or check the Dataset exists at:
134
+ https://huggingface.co/datasets/tao-shen/HuggingClaw-Cain-data
135
+
136
+ ---
137
+
138
+ ## Optional Environment Variables
139
+
140
+ ### `SYNC_INTERVAL`
141
+
142
+ **Purpose:** Controls how often (in seconds) data is synced to the Dataset.
143
+
144
+ **Default:** `60` (60 seconds)
145
+
146
+ **Format:** Integer (seconds)
147
+
148
+ **Example:** `SYNC_INTERVAL=120` (sync every 2 minutes)
149
+
150
+ **Usage:** Only adjust if you need less frequent API calls. Lower values = safer but more API usage.
151
+
152
+ ---
153
+
154
+ ## Data Persistence Behavior
155
+
156
+ ### What Gets Backed Up
157
+
158
+ The entire `~/.openclaw` directory is synced to the Dataset:
159
+
160
+ - ✅ Conversations and chat history
161
+ - ✅ Settings and configuration
162
+ - ��� API credentials and keys
163
+ - ✅ Agent plugins and configurations
164
+ - ✅ Workspace files and memories
165
+
166
+ ### What Gets Excluded
167
+
168
+ - ❌ `*.log` files (regenerated on startup)
169
+ - ❌ `*.lock` files (stale after restart)
170
+ - ❌ `*.tmp` and `*.pid` files
171
+ - ❌ `__pycache__` directories
172
+
173
+ ### Sync Schedule
174
+
175
+ 1. **Startup:** Download latest data from Dataset
176
+ 2. **Periodic:** Upload changes every `SYNC_INTERVAL` seconds (default: 60s)
177
+ 3. **Shutdown:** Final upload before Space stops
178
+
179
+ ---
180
+
181
+ ## Troubleshooting
182
+
183
+ ### Error: "HF_TOKEN not set"
184
+
185
+ **Solution:** Add `HF_TOKEN` as a Repository Secret in Space settings.
186
+
187
+ ### Error: "Dataset repo NOT found: xxx"
188
+
189
+ **Solution:** Either:
190
+ 1. Set `AUTO_CREATE_DATASET=true` to auto-create
191
+ 2. Create the Dataset manually at https://huggingface.co/new-dataset
192
+
193
+ ### Error: "Could not derive username from HF_TOKEN"
194
+
195
+ **Solution:** Verify your `HF_TOKEN` has read permissions. Check the token type is "Write".
196
+
197
+ ### Data not persisting after restart
198
+
199
+ **Solution:** Check logs for sync errors:
200
+ ```
201
+ [SYNC] ▶ Uploading ~/.openclaw → dataset ...
202
+ [SYNC] ✓ Upload completed
203
+ ```
204
+
205
+ If you see errors, verify:
206
+ 1. `HF_TOKEN` has Write permissions
207
+ 2. Dataset repository exists and is accessible
208
+ 3. No API quota issues
209
+
210
+ ---
211
+
212
+ ## Quick Reference: Minimal Working Configuration
213
+
214
+ For automatic setup (recommended), add these as Repository Secrets:
215
+
216
+ ```bash
217
+ HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # (Secret)
218
+ AUTO_CREATE_DATASET=true
219
+ ```
220
+
221
+ The Dataset ID will be automatically set to: `tao-shen/HuggingClaw-Cain-data`
222
+
223
+ ---
224
+
225
+ ## Current Cain Status
226
+
227
+ | Component | Status |
228
+ |-----------|--------|
229
+ | Space Status | ✅ RUNNING |
230
+ | Health | ✅ ALIVE (idle) |
231
+ | HF_TOKEN | ❌ NOT SET |
232
+ | OPENCLAW_DATASET_REPO | ❌ NOT SET (will auto-derive) |
233
+ | AUTO_CREATE_DATASET | ❌ NOT SET (defaults to false) |
234
+ | Data Persistence | ⚠️ DISABLED |
235
+
236
+ ---
237
+
238
+ ## Files Reference
239
+
240
+ | File | Purpose |
241
+ |------|---------|
242
+ | `scripts/sync_hf.py` | Main persistence script |
243
+ | `.env.example` | Environment variable reference |
244
+ | `README.md` | Space documentation |
245
+
246
+ ---
247
+
248
+ ## Code References
249
+
250
+ **sync_hf.py key lines:**
251
+
252
+ ```python
253
+ # Line 61 - HF_TOKEN retrieval
254
+ HF_TOKEN = os.environ.get("HF_TOKEN")
255
+
256
+ # Line 100 - AUTO_CREATE_DATASET
257
+ AUTO_CREATE_DATASET = os.environ.get("AUTO_CREATE_DATASET", "false").lower() in ("true", "1", "yes")
258
+
259
+ # Lines 105-109 - Auto-derive Dataset from SPACE_ID
260
+ HF_REPO_ID = os.environ.get("OPENCLAW_DATASET_REPO", "")
261
+ if not HF_REPO_ID and SPACE_ID:
262
+ HF_REPO_ID = f"{SPACE_ID}-data"
263
+ ```
264
+
265
+ ---
266
+
267
+ ## Contact & Support
268
+
269
+ For issues or questions:
270
+ 1. Check the main HuggingClaw repository
271
+ 2. Review sync logs in Cain's workspace: `~/.openclaw/workspace/sync.log`
272
+
273
+ ---
274
+
275
+ **Report End**