Skip to content

fix: cleanup R2 object if DB insert fails during artifact upload#307

Open
jasoncobra3 wants to merge 1 commit into
alookai:mainfrom
jasoncobra3:fix/atomic-artifact-upload-r2-cleanup
Open

fix: cleanup R2 object if DB insert fails during artifact upload#307
jasoncobra3 wants to merge 1 commit into
alookai:mainfrom
jasoncobra3:fix/atomic-artifact-upload-r2-cleanup

Conversation

@jasoncobra3

@jasoncobra3 jasoncobra3 commented Jun 7, 2026

Copy link
Copy Markdown

Closes #158

Orphaned R2 objects were created when bucket.put() succeeded but createArtifact() threw. Added try/catch to delete the R2 key on DB failure, preventing storage leaks.

What changed

Problem

When bucket.put() succeeded but createArtifact() threw, the R2
object was left orphaned in storage with no corresponding DB record.

Fix

Wrapped the DB insert and surrounding logic in a try/catch. On failure,
bucket.delete(r2Key) is called to clean up the orphaned R2 object
before re-throwing the original error.

Testing

  • pnpm typecheck ✅
  • @alook/app and @alook/web tests pass ✅

Closes alookai#158

Orphaned R2 objects were created when bucket.put() succeeded but
createArtifact() threw. Added try/catch to delete the R2 key on
DB failure, preventing storage leaks.
@jasoncobra3 jasoncobra3 requested a review from a team as a code owner June 7, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Artifact upload: DB record created even if R2 upload fails

1 participant