Handle 'already in use' error when R2 bucket is already mounted #209
+43
−1
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.
Summary
Two bugs in R2 mount/sync handling that cause errors on fresh deployments and subsequent requests:
1. Handle "already in use" error when R2 bucket is already mounted
isR2Mounted()runsmount | grep "s3fs on /data/moltbot"inside the sandbox to detect existing mounts, but this check is unreliable — it can returnfalseeven when the bucket is already mounted (due to process polling timing, the grep not matching, etc.)isR2Mounted()incorrectly returnsfalse,mountBucket()is called again, which throwsInvalidMountConfigError: Mount path "/data/moltbot" is already in use by bucket "moltbot-data"mount | grepcheck2. Ensure gateway is running before syncing to R2
syncToR2only mounted R2 but never started the gatewayopenclaw onboard(which createsopenclaw.json) only runs during gateway startup viastart-openclaw.shensureMoltbotGateway()call before syncingChanges
src/gateway/r2.ts: Added early return in catch block when error contains "already in use"src/gateway/r2.test.ts: Added test case for theInvalidMountConfigErrorscenariosrc/gateway/sync.ts: AddedensureMoltbotGateway()call before sync, import from./processsrc/gateway/sync.test.ts: Added mock forensureMoltbotGatewayTest plan
mountR2StoragereturnstruewhenmountBucketthrows "already in use"syncToR2tests pass with mockedensureMoltbotGateway🤖 Generated with Claude Code