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

Claude Code: **CRITICAL: Fix Data Persistence - Add HF_TOKEN and AUTO_CREATE_DATASET*

Browse files
Files changed (1) hide show
  1. SETUP.md +168 -0
SETUP.md ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cain Data Persistence Setup
2
+
3
+ **CRITICAL:** Without completing this setup, all conversations, settings, and credentials will be **LOST** when the HuggingFace Space restarts.
4
+
5
+ ---
6
+
7
+ ## The Problem
8
+
9
+ Cain's data persistence is currently **DISABLED**. The `sync_hf.py` script requires:
10
+
11
+ 1. **HF_TOKEN** environment variable (Repository Secret) - Missing
12
+ 2. **AUTO_CREATE_DATASET=true** environment variable - Missing
13
+
14
+ Without these, Cain cannot persist data to the HuggingFace Dataset.
15
+
16
+ ---
17
+
18
+ ## Quick Setup (5 minutes)
19
+
20
+ ### Step 1: Create an HF Token with Write Access
21
+
22
+ 1. Go to: https://huggingface.co/settings/tokens
23
+ 2. Click **"New token"**
24
+ 3. Set **Type** to: **Write** (NOT "Read" - this is critical!)
25
+ 4. Name it something like: `Cain-Data-Persistence`
26
+ 5. Click **"Generate token"**
27
+ 6. **Copy the token immediately** - you won't see it again!
28
+
29
+ ### Step 2: Add Environment Variables in Space Settings
30
+
31
+ 1. Go to your Space settings: https://huggingface.co/spaces/tao-shen/HuggingClaw-Cain/settings
32
+ 2. Scroll to **"Repository Secrets"** section
33
+ 3. Click **"New Secret"**
34
+
35
+ Add these two secrets:
36
+
37
+ | Name | Value | Type |
38
+ |------|-------|------|
39
+ | `HF_TOKEN` | *[Paste your token from Step 1]* | Repository Secret |
40
+ | `AUTO_CREATE_DATASET` | `true` | Repository Secret |
41
+
42
+ 4. Click **"Save"** for each secret
43
+
44
+ ### Step 3: Restart the Space
45
+
46
+ 1. Go to: https://huggingface.co/spaces/tao-shen/HuggingClaw-Cain
47
+ 2. Click the **"Settings"** tab (top right gear icon)
48
+ 3. Scroll down and click **"Factory reset"** or **"Restart"**
49
+ 4. Wait 2-3 minutes for the Space to restart
50
+
51
+ ---
52
+
53
+ ## What Happens After Setup
54
+
55
+ ### Automatic Dataset Creation
56
+
57
+ When the Space restarts with `HF_TOKEN` and `AUTO_CREATE_DATASET=true`:
58
+
59
+ 1. The script auto-creates the dataset: `tao-shen/HuggingClaw-Cain-data`
60
+ 2. The dataset will be **private** (only you can access it)
61
+ 3. You can verify it at: https://huggingface.co/datasets/tao-shen/HuggingClaw-Cain-data
62
+
63
+ ### What Data Gets Synced
64
+
65
+ The `sync_hf.py` script syncs the entire `~/.openclaw` directory, including:
66
+
67
+ - **Conversations** - All chat history
68
+ - **Settings** - `openclaw.json` configuration
69
+ - **Credentials** - API keys (stored in config)
70
+ - **Workspace files** - All user-created files
71
+ - **Agent memory** - Persistent agent state
72
+ - **Devices** - Paired Telegram/WhatsApp connections
73
+
74
+ ### Sync Schedule
75
+
76
+ - **On startup:** Downloads latest data from dataset
77
+ - **Every 60 seconds:** Uploads changes (only if files changed)
78
+ - **On shutdown:** Final upload before Space stops
79
+
80
+ ### Logs to Monitor
81
+
82
+ After restart, check these logs for confirmation:
83
+
84
+ ```
85
+ [SYNC] Dataset repo found: tao-shen/HuggingClaw-Cain-data
86
+ [SYNC] ✓ Dataset repo created: tao-shen/HuggingClaw-Cain-data
87
+ [SYNC] ✓ Restore completed.
88
+ [SYNC] ✓ Upload completed at 2026-03-14T...
89
+ ```
90
+
91
+ Look for the sync log in the Space's "Logs" tab or in the running Space output.
92
+
93
+ ---
94
+
95
+ ## Troubleshooting
96
+
97
+ ### "Persistence disabled" message
98
+
99
+ **Cause:** `HF_TOKEN` is not set or invalid
100
+
101
+ **Solution:**
102
+ 1. Verify the token exists in Repository Secrets
103
+ 2. Ensure token type is "Write" (not "Read")
104
+ 3. Restart the Space after adding the token
105
+
106
+ ### "Dataset repo NOT found" (dataset not created)
107
+
108
+ **Cause:** `AUTO_CREATE_DATASET` is not set to `true`
109
+
110
+ **Solution:**
111
+ 1. Add `AUTO_CREATE_DATASET=true` as a Repository Secret
112
+ 2. Restart the Space
113
+
114
+ ### Data still not persisting after restart
115
+
116
+ **Check the Space logs for:**
117
+ ```
118
+ [SYNC] WARNING: HF_TOKEN not set. Persistence disabled.
119
+ ```
120
+
121
+ **Solution:** Re-add the HF_TOKEN secret (it may not have saved properly)
122
+
123
+ ---
124
+
125
+ ## Advanced Configuration
126
+
127
+ ### Change Sync Interval
128
+
129
+ Default sync interval is 60 seconds. To change it:
130
+
131
+ | Name | Value | Type |
132
+ |------|-------|------|
133
+ | `SYNC_INTERVAL` | `120` (for 2 minutes) | Repository Secret |
134
+
135
+ ### Custom Dataset Name
136
+
137
+ To use a different dataset (not auto-derived):
138
+
139
+ | Name | Value | Type |
140
+ |------|-------|------|
141
+ | `OPENCLAW_DATASET_REPO` | `your-name/custom-dataset-name` | Repository Secret |
142
+
143
+ ---
144
+
145
+ ## Summary
146
+
147
+ | Setting | Value Required | Default if Missing |
148
+ |---------|----------------|-------------------|
149
+ | `HF_TOKEN` | Write token from HF settings | **Persistence DISABLED** |
150
+ | `AUTO_CREATE_DATASET` | `true` | Dataset NOT auto-created |
151
+ | Dataset ID | Auto: `tao-shen/HuggingClaw-Cain-data` | N/A |
152
+ | Sync Interval | 60 seconds | N/A |
153
+
154
+ ---
155
+
156
+ ## Verification Checklist
157
+
158
+ After completing setup:
159
+
160
+ - [ ] HF Token created with "Write" type
161
+ - [ ] `HF_TOKEN` secret added to Space settings
162
+ - [ ] `AUTO_CREATE_DATASET=true` secret added
163
+ - [ ] Space restarted
164
+ - [ ] Dataset created at `tao-shen/HuggingClaw-Cain-data`
165
+ - [ ] Logs show "Dataset repo found" or "Dataset repo created"
166
+ - [ ] Logs show "Restore completed" or "Upload completed"
167
+
168
+ **Once all items are checked, data persistence is enabled!**