From cc1a155d653b77d7caa7792eff0190ac6b799aca Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Mon, 29 Dec 2025 22:49:22 +0900 Subject: [PATCH] fix(cliproxyapi): sync recovered auth files to R2 on startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, auth files recovered from dotfiles were merged to local storage but never uploaded to R2. This caused "key does not exist" errors when cliproxyapi tried to read auth files directly from object storage. Now start.sh always syncs local auth files to R2 after the recovery step, ensuring all auth files (recovered or created locally) are available in both the primary auths/ and backup locations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../services/cliproxyapi/scripts/start.sh | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/home-manager/services/cliproxyapi/scripts/start.sh b/home-manager/services/cliproxyapi/scripts/start.sh index 2c39c70cc..f3e7ef67f 100755 --- a/home-manager/services/cliproxyapi/scripts/start.sh +++ b/home-manager/services/cliproxyapi/scripts/start.sh @@ -70,6 +70,29 @@ if [ -n "${OBJECTSTORE_ENDPOINT:-}" ] && [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ]; t fi fi fi + + # CRITICAL: Always sync local auth files to R2 after merge + # This ensures any files that exist locally but not in R2 get uploaded, + # preventing "key does not exist" errors when cliproxyapi reads from object storage + if [ -d "$AUTH_DIR" ] && [ -n "$(ls -A "$AUTH_DIR" 2>/dev/null)" ]; then + echo "Syncing local auth files to R2..." >&2 + AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \ + AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY}" \ + @aws@ s3 sync \ + --endpoint-url="${OBJECTSTORE_ENDPOINT}" \ + --no-progress \ + "$AUTH_DIR/" \ + "s3://cliproxyapi/auths/" 2>&1 && echo "✅ Auth files synced to R2 auths/" >&2 || echo "⚠️ Failed to sync auth files to R2" >&2 + + # Also sync to backup location for redundancy + AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY}" \ + AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY}" \ + @aws@ s3 sync \ + --endpoint-url="${OBJECTSTORE_ENDPOINT}" \ + --no-progress \ + "$AUTH_DIR/" \ + "s3://cliproxyapi/backup/auths/" 2>&1 && echo "✅ Auth files synced to R2 backup/" >&2 || true + fi else echo "⚠️ Skipping auth sync: OBJECTSTORE credentials not set" >&2 fi