Skip to content

Commit 812bbd8

Browse files
authored
docs(deploy): add verification, cost, observability, and troubleshooting to the Cloudflare guide (#122932)
The template shipped without the operator-facing half: no way to prove the restore path works before depending on it, no cost signal for the always-on versus webhook-only choice, no log surfaces, and no failure-mode index. Adds an architecture diagram, a restore rehearsal, measured recovery numbers from the real-R2 proof, provisioned-resource cost guidance, wrangler tail observability, and a troubleshooting index covering image architecture, Litestream S3 credentials, the startupz/readyz split, and ephemeral-disk config loss.
1 parent c401f8a commit 812bbd8

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

‎docs/install/cloudflare.md‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,32 @@ The template lives in [`scripts/cloudflare`](https://github.com/openclaw/opencla
2727

2828
The Worker forwards every HTTP and WebSocket request to one stable Durable Object name. That Durable Object owns one Container instance and is the single-writer fence around the Litestream replica. The Container exposes OpenClaw on port `8080`; `/startupz` is its traffic-readiness check.
2929

30+
```mermaid
31+
flowchart TD
32+
client[Channels, browsers, API clients]
33+
worker[Cloudflare Worker]
34+
durable[Durable Object, one stable name]
35+
container[Container running the OpenClaw Gateway on 8080]
36+
litestream[Litestream sidecar process]
37+
r2[(R2 bucket of SQLite replicas)]
38+
39+
client --> worker
40+
worker --> durable
41+
durable --> container
42+
container --> litestream
43+
litestream -- continuous WAL streaming --> r2
44+
r2 -- restore on boot --> container
45+
```
46+
3047
Litestream watches both SQLite roots:
3148

3249
- `/home/node/.openclaw/state/*.sqlite`
3350
- `/home/node/.openclaw/agents/**/*.sqlite`
3451

3552
At boot, the entrypoint uses R2's S3 `ListObjectsV2` API as the restore manifest, rejects paths outside those roots, restores each discovered database, and only then starts the Gateway.
3653

54+
Measured on this template against a real R2 bucket: about 2.4 seconds from write to replica, and about 9 seconds to restore both databases into a fresh Container that reached a healthy Gateway roughly 13 seconds after start. Treat these as order-of-magnitude expectations, not guarantees.
55+
3756
## Deploy
3857

3958
<Steps>
@@ -156,6 +175,59 @@ At boot, the entrypoint uses R2's S3 `ListObjectsV2` API as the restore manifest
156175
</Step>
157176
</Steps>
158177

178+
## Verify the deployment
179+
180+
Run these checks after the first bootstrap, before you depend on this deployment.
181+
182+
Confirm the Gateway admits traffic. `/startupz` reports startup completion and ignores channel health, so it stays green when one channel account is broken:
183+
184+
```bash
185+
curl -sS https://<worker-subdomain>.workers.dev/startupz
186+
curl -sS -H "Authorization: Bearer $OPENCLAW_GATEWAY_TOKEN" \
187+
https://<worker-subdomain>.workers.dev/readyz
188+
```
189+
190+
Confirm replication is actually reaching R2. Objects should appear under `replicas/` within seconds of activity:
191+
192+
```bash
193+
npx wrangler r2 object get openclaw-backups/replicas --remote 2>/dev/null || true
194+
npx wrangler r2 bucket list
195+
```
196+
197+
Rehearse recovery before you need it. An untested restore path is not a backup:
198+
199+
1. Send one message so the Gateway writes a session row.
200+
2. Wait about ten seconds for replication.
201+
3. Delete the Container instance, or redeploy to force replacement.
202+
4. Reopen the Worker URL and confirm the conversation still exists.
203+
204+
If step 4 loses data, stop and fix replication before connecting production channels.
205+
206+
## Cost and sizing
207+
208+
Containers require the Workers Paid plan. Memory and disk bill on the resources **provisioned** for the instance type for as long as the Container is awake; CPU bills on active use only.
209+
210+
The default `standard-2` instance provisions 1 vCPU, 6 GiB memory, and 12 GB disk. Running it always-on for a full month is therefore dominated by provisioned memory rather than by how busy the agent is. At the published rates, that is roughly 40 to 50 US dollars per month including the plan fee, mostly memory, before egress.
211+
212+
This matters for the lifecycle decision below:
213+
214+
- **Socket channels keep the Container awake**, so they pay the always-on rate. A small always-on virtual machine is often cheaper. Choose Cloudflare here for its operational model, colocation with other Cloudflare services, or the R2 durability path, not to save money.
215+
- **Webhook-only installations sleep**, and a sleeping Container bills nothing. That is where this target is genuinely inexpensive.
216+
217+
Verify current rates on [Cloudflare's Containers pricing page](https://developers.cloudflare.com/containers/pricing/) before committing; these figures are estimates from the published rate card and change independently of OpenClaw.
218+
219+
## Observability
220+
221+
Stream Worker and Container logs while reproducing an issue:
222+
223+
```bash
224+
npx wrangler tail
225+
npx wrangler containers list
226+
npx wrangler containers instances <application-id> --json
227+
```
228+
229+
Gateway logs stay inside the Container. Reach them over the temporary SSH session described in the bootstrap step, or forward them to your own collector. The Container filesystem is ephemeral, so treat in-Container logs as debugging output rather than as a durable record.
230+
159231
## Choose the lifecycle mode
160232

161233
`OPENCLAW_WEBHOOK_ONLY` defaults to `false`, which keeps the Container running through idle periods. Keep this default for channels that maintain sockets or long-lived processes, including:
@@ -191,6 +263,26 @@ npm run deploy
191263

192264
Test updates and rollbacks against a separate R2 bucket first. Preserve current state before activating older bytes.
193265

266+
## Troubleshooting
267+
268+
**Worker returns 5xx and the Container never becomes ready** -- Cloudflare only runs `linux/amd64` images pulled from a public registry. Rebuild with `--platform linux/amd64`, confirm the derived Docker Hub repository is public, and confirm `containers[].image` uses the pushed digest rather than a moving tag.
269+
270+
**Deployment succeeds but every request times out** -- The Container helper waits for `GET /startupz`. Check that the Gateway inside the Container listens on port `8080` and that no bootstrap step changed the port.
271+
272+
**Litestream logs authentication or signature errors** -- Litestream needs R2 S3 API credentials, which are not the same as a Cloudflare API token. Create an R2 API token and use its access key ID and secret access key, and confirm `LITESTREAM_ENDPOINT` contains your account ID.
273+
274+
**First boot logs no databases to restore** -- Expected on an empty bucket. The entrypoint treats an empty replica listing as a fresh installation and starts the Gateway normally.
275+
276+
**`/readyz` returns 503 while `/startupz` returns 200** -- Working as designed. Startup finished, and a configured channel account is unhealthy. Inspect channel status rather than restarting the Container; see [Health checks](/gateway/health#http-probes).
277+
278+
**`wrangler containers ssh` is rejected** -- SSH ships disabled. Add `"ssh": { "enabled": true }` to the container entry, redeploy, then connect.
279+
280+
**Configuration disappeared after a sleep or a redeploy** -- Litestream restores SQLite databases only. `openclaw.json`, credential files, installed plugin files, and workspaces live on the ephemeral disk. Reapply your bootstrap runbook, or keep the installation always-on and take [full archives](/install/backups#full-archives).
281+
282+
**Channel sessions break after a restore** -- Restoring older bytes rolls back ratcheting credentials. Relink the affected channel and review pending approvals; see [Limits and recovery](#limits-and-recovery).
283+
284+
**WebSocket connections close on large payloads** -- Cloudflare closes received WebSocket messages larger than 32 MiB. Reduce attachment sizes or transfer them out of band.
285+
194286
## Related
195287

196288
- [Backups](/install/backups)

‎scripts/cloudflare/README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,23 @@ node openclaw.mjs doctor --json
125125

126126
Keep the exact bootstrap recipe in a private, reproducible runbook. Litestream does not replicate `openclaw.json`, credential files, installed plugin files, or workspaces.
127127

128+
## 5. Verify before relying on it
129+
130+
```bash
131+
curl -sS https://<worker-subdomain>.workers.dev/startupz
132+
npx wrangler tail
133+
```
134+
135+
Then rehearse recovery, because an untested restore path is not a backup: send one message, wait about ten seconds for replication, force a Container replacement, and confirm the conversation survives. Fix replication before connecting production channels if it does not.
136+
137+
Measured on this template against a real R2 bucket: about 2.4 s write-to-replica, about 9 s to restore both databases, and a healthy Gateway about 13 s after a fresh start.
138+
128139
## Scale-to-zero policy
129140

130141
The template defaults `OPENCLAW_WEBHOOK_ONLY` to `false`. This keeps the Container alive across idle periods for Discord, Slack Socket Mode, WhatsApp, and every other channel that maintains a socket or polling process.
131142

143+
Cost follows directly from that choice. Memory and disk bill on provisioned instance resources for as long as the Container is awake, so an always-on `standard-2` is dominated by its 6 GiB of provisioned memory rather than by agent activity -- roughly 40 to 50 US dollars per month at published rates, where a small always-on VM is often cheaper. A sleeping webhook-only Container bills nothing. Check [current rates](https://developers.cloudflare.com/containers/pricing/) before committing.
144+
132145
Set `OPENCLAW_WEBHOOK_ONLY` to `true` only when every enabled channel receives traffic through HTTP webhooks. The Container then stops after ten idle minutes and cold-starts on the next request. Because its disk is fresh after sleep, enable this only when an external process can reapply the declarative bootstrap above; Litestream alone restores SQLite, not the config files needed to activate channels.
133146

134147
## Operational constraints
@@ -154,6 +167,18 @@ npm run deploy
154167

155168
Treat rollbacks like restores: stop traffic where possible, preserve the current state first, and review credentials, approvals, and delivery state before activating older database bytes.
156169

170+
## Troubleshooting
171+
172+
- **Container never becomes ready:** the image must be `linux/amd64` and pulled from a public registry, referenced by digest rather than a moving tag.
173+
- **Requests time out after a successful deploy:** the Container helper waits for `GET /startupz` on port `8080`; confirm the Gateway still binds that port.
174+
- **Litestream authentication or signature errors:** Litestream needs R2 _S3 API_ credentials, not a Cloudflare API token, and `LITESTREAM_ENDPOINT` must contain the account ID.
175+
- **First boot reports no databases to restore:** expected on an empty bucket; the entrypoint treats that as a fresh installation.
176+
- **`/readyz` is 503 while `/startupz` is 200:** by design. Startup finished and a channel account is unhealthy; inspect channel status instead of restarting.
177+
- **`wrangler containers ssh` rejected:** SSH ships disabled; add `"ssh": { "enabled": true }`, redeploy, then connect.
178+
- **Config missing after sleep or redeploy:** Litestream restores SQLite only. Reapply the bootstrap runbook or stay always-on and take full archives.
179+
180+
Full operator guide: <https://docs.openclaw.ai/install/cloudflare>.
181+
157182
## Files
158183

159184
- `wrangler.jsonc`: Worker, Durable Object, Container application, and R2 binding

0 commit comments

Comments
 (0)