Skip to content

Cloudflare R2 sync memory bugfix#24

Merged
PCBZ merged 7 commits into
mainfrom
memory_fix
May 8, 2026
Merged

Cloudflare R2 sync memory bugfix#24
PCBZ merged 7 commits into
mainfrom
memory_fix

Conversation

@PCBZ
Copy link
Copy Markdown
Owner

@PCBZ PCBZ commented May 6, 2026

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.

  • Cloud Run: HOME=/tmp/openclaw-state, openclaw stores state at $HOME/.openclaw/
  • rclone sidecar syncs /data/ (same volume) → R2, so R2 contains .openclaw/workspace/...
  • GCP VM was restoring 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.sh to use r2:bucket/.openclaw/ as the R2 path:

  • Restore on boot: r2:bucket/.openclaw//root/.openclaw/
  • Periodic 60s sync: /root/.openclaw/r2:bucket/.openclaw/
  • Shutdown final sync: same

🤖 Generated with Claude Code

PCBZ and others added 6 commits May 6, 2026 13:48
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>
@PCBZ PCBZ self-assigned this May 7, 2026
@PCBZ PCBZ added the bug Something isn't working label May 7, 2026
@PCBZ PCBZ changed the title fix(gcp-vm): fix R2 rclone path to use .openclaw/ prefix Cloudflare R2 sync memory bugfix May 7, 2026
@PCBZ PCBZ requested a review from Copilot May 7, 2026 06:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json to 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"]
@PCBZ PCBZ merged commit 9077278 into main May 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants