Cloudflare R2 sync memory bugfix#24
Merged
Merged
Conversation
Cloud Run stores openclaw state at HOME/.openclaw/ (HOME=/tmp/openclaw-state), so rclone syncs /data/ → R2 with .openclaw/ as subdir prefix in R2. GCP VM must therefore use r2:bucket/.openclaw/ ↔ /root/.openclaw/ to match. Fixes BOOTSTRAP.md re-init and soul/user template regression after Cloud Run → Compute Engine failover. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t for improved state handling
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes Cloudflare R2 state synchronization across Cloud Run and GCE VM deployments by tightening what gets synced and moving platform-specific config out of R2 into Secret Manager.
Changes:
- Introduce rclone allowlist filter files to sync only shared workspace/session state (not config files).
- Move
openclaw.json(and Telegram allowlist JSON) to Google Secret Manager for Cloud Run. - Adjust Cloud Run runtime mount/state paths and remove the Terraform-based upload of
openclaw.jsonto R2.
Reviewed changes
Copilot reviewed 5 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| terraform/gcp_vm/bootstrap.sh | Replaces --exclude flags with an allowlist filter file for VM restore/sync. |
| terraform/gcp_cloudrun/secrets.tf | Adds Secret Manager secrets/versions for openclaw.json and Telegram allowlist. |
| terraform/gcp_cloudrun/rclone-sync.sh | Replaces excludes with an allowlist filter file for Cloud Run sidecar sync. |
| terraform/gcp_cloudrun/r2.tf | Removes Terraform logic that uploaded openclaw.json to R2. |
| terraform/gcp_cloudrun/main.tf | Writes config/auth files from secrets/env on startup; changes mount/state paths; wires new Secret Manager env vars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+18
| cat > "$FILTER_FILE" << 'EOF' | ||
| + workspace/MEMORY.md | ||
| + workspace/SOUL.md | ||
| + workspace/USER.md | ||
| + workspace/AGENTS.md | ||
| + agents/main/sessions/** | ||
| - * | ||
| EOF | ||
|
|
||
| # ── Restore from R2 on startup ──────────────────────────────── | ||
| rclone sync r2:$R2_BUCKET/ /data/ --create-empty-src-dirs $RCLONE_EXCLUDE 2>/dev/null || true | ||
| rclone sync r2:$R2_BUCKET/ /data/ --create-empty-src-dirs --filter-from "$FILTER_FILE" 2>/dev/null || true |
| image = local.effective_container_image | ||
| command = ["/bin/sh"] | ||
| args = ["-lc", "openclaw gateway run --bind lan --port \"$${PORT:-8080}\" --allow-unconfigured"] | ||
| args = ["-lc", "mkdir -p /home/node/.openclaw/agents/main/agent /home/node/.openclaw/credentials; [ -n \"$OPENCLAW_JSON\" ] && echo \"$OPENCLAW_JSON\" > /home/node/.openclaw/openclaw.json; [ -n \"$TELEGRAM_ALLOW_FROM\" ] && echo \"$TELEGRAM_ALLOW_FROM\" > /home/node/.openclaw/credentials/telegram-allowFrom.json; printf '{\"openrouter\":{\"apiKey\":\"%s\"}}' \"$OPENROUTER_API_KEY\" > /home/node/.openclaw/agents/main/agent/auth-profiles.json; printf '{\"providers\":{\"openrouter\":{\"baseUrl\":\"https://openrouter.ai/api/v1\",\"api\":\"openai-completions\",\"apiKey\":\"OPENROUTER_API_KEY\"}}}' > /home/node/.openclaw/agents/main/agent/models.json; exec openclaw gateway run --bind lan --port \"$${PORT:-8080}\" --allow-unconfigured"] |
| image = local.effective_container_image | ||
| command = ["/bin/sh"] | ||
| args = ["-lc", "openclaw gateway run --bind lan --port \"$${PORT:-8080}\" --allow-unconfigured"] | ||
| args = ["-lc", "mkdir -p /home/node/.openclaw/agents/main/agent /home/node/.openclaw/credentials; [ -n \"$OPENCLAW_JSON\" ] && echo \"$OPENCLAW_JSON\" > /home/node/.openclaw/openclaw.json; [ -n \"$TELEGRAM_ALLOW_FROM\" ] && echo \"$TELEGRAM_ALLOW_FROM\" > /home/node/.openclaw/credentials/telegram-allowFrom.json; printf '{\"openrouter\":{\"apiKey\":\"%s\"}}' \"$OPENROUTER_API_KEY\" > /home/node/.openclaw/agents/main/agent/auth-profiles.json; printf '{\"providers\":{\"openrouter\":{\"baseUrl\":\"https://openrouter.ai/api/v1\",\"api\":\"openai-completions\",\"apiKey\":\"OPENROUTER_API_KEY\"}}}' > /home/node/.openclaw/agents/main/agent/models.json; exec openclaw gateway run --bind lan --port \"$${PORT:-8080}\" --allow-unconfigured"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After switching from Cloud Run to Compute Engine, BOOTSTRAP.md re-appeared and SOUL.md/USER.md reset to templates.
Root cause: Path mismatch between Cloud Run and GCP VM rclone sync paths.
HOME=/tmp/openclaw-state, openclaw stores state at$HOME/.openclaw//data/(same volume) → R2, so R2 contains.openclaw/workspace/...r2:bucket/→/root/.openclaw/, placing files at/root/.openclaw/.openclaw/workspace/...(one level too deep)Fix
Change all three rclone commands in
gcp_vm/bootstrap.shto user2:bucket/.openclaw/as the R2 path:r2:bucket/.openclaw/→/root/.openclaw//root/.openclaw/→r2:bucket/.openclaw/🤖 Generated with Claude Code