From 18802b101acb7493131edc430c5b00020fec5093 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Wed, 29 Jul 2026 22:24:05 -0400 Subject: [PATCH 1/2] Retry Azure container creation after a failed first attempt The lazy createIfNotExists memo cached rejections as well as successes, so one transient failure (network blip, emulator API-version rejection) latched the store into replaying the same error on every subsequent operation until the host process restarted. Clear the memo on rejection so the next operation retries; the happy path keeps its single-flight memoization. Observed during the Exsimplify migration's Phase 2 boot smoke against Azurite. The S3 and Cloudflare R2 adapters do not lazily create buckets, so only the Azure adapter carried this pattern. Bump all published packages to 0.1.2 (release tooling requires one shared version). Co-Authored-By: Claude Fable 5 --- package-lock.json | 14 +++--- packages/storage-azure-blob/package.json | 4 +- packages/storage-azure-blob/src/index.test.ts | 44 ++++++++++++++++++- packages/storage-azure-blob/src/index.ts | 10 ++++- packages/storage-blobs/package.json | 2 +- packages/storage-cloudflare-r2/package.json | 4 +- packages/storage-s3/package.json | 4 +- 7 files changed, 65 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index c78627c..bb239e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6249,11 +6249,11 @@ }, "packages/storage-azure-blob": { "name": "@pegma/storage-azure-blob", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "dependencies": { "@azure/storage-blob": "^12.29.1", - "@pegma/storage-blobs": "0.1.1" + "@pegma/storage-blobs": "0.1.2" }, "engines": { "node": ">=22" @@ -6261,7 +6261,7 @@ }, "packages/storage-blobs": { "name": "@pegma/storage-blobs", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "engines": { "node": ">=22" @@ -6269,11 +6269,11 @@ }, "packages/storage-cloudflare-r2": { "name": "@pegma/storage-cloudflare-r2", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.1" + "@pegma/storage-blobs": "0.1.2" }, "engines": { "node": ">=22" @@ -6281,11 +6281,11 @@ }, "packages/storage-s3": { "name": "@pegma/storage-s3", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.1" + "@pegma/storage-blobs": "0.1.2" }, "engines": { "node": ">=22" diff --git a/packages/storage-azure-blob/package.json b/packages/storage-azure-blob/package.json index 74e2843..1c88b9d 100644 --- a/packages/storage-azure-blob/package.json +++ b/packages/storage-azure-blob/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-azure-blob", - "version": "0.1.1", + "version": "0.1.2", "description": "Azure Blob Storage adapter for @pegma/storage-blobs.", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ }, "dependencies": { "@azure/storage-blob": "^12.29.1", - "@pegma/storage-blobs": "0.1.1" + "@pegma/storage-blobs": "0.1.2" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/storage-azure-blob/src/index.test.ts b/packages/storage-azure-blob/src/index.test.ts index edbcb4d..6a876dc 100644 --- a/packages/storage-azure-blob/src/index.test.ts +++ b/packages/storage-azure-blob/src/index.test.ts @@ -1,11 +1,11 @@ -import { BlobServiceClient } from "@azure/storage-blob"; +import { BlobServiceClient, type ContainerClient } from "@azure/storage-blob"; import { concurrentConformanceCases, conformanceCases, dualStoreConformanceCases, sizeLimitConformanceCases, } from "@pegma/storage-blobs/conformance"; -import { describe, it } from "vitest"; +import { describe, expect, it } from "vitest"; import { BLOB_PORT } from "../../../test/azurite.js"; import { createAzureBlobStore } from "./index.js"; @@ -91,4 +91,44 @@ describe("createAzureBlobStore", () => { ); }); } + + // Azurite cannot be made to fail createIfNotExists exactly once, so this + // fault-injection case uses a stub client instead of the emulator. + it("retries container creation after a failed first attempt", async () => { + let createAttempts = 0; + const notFound = () => + Object.assign(new Error("BlobNotFound"), { statusCode: 404 }); + const containerClient = { + containerName: "retry-container", + accountName: ACCOUNT, + url: `http://127.0.0.1:${BLOB_PORT}/${ACCOUNT}/retry-container`, + createIfNotExists: async () => { + createAttempts += 1; + if (createAttempts === 1) { + throw new Error("transient container create failure"); + } + return { succeeded: true }; + }, + getBlockBlobClient: () => ({ + getProperties: async () => { + throw notFound(); + }, + }), + } as unknown as ContainerClient; + + const store = createAzureBlobStore({ + containerClient, + createContainerIfMissing: true, + }); + + await expect(store.head("some-key")).rejects.toThrow( + "transient container create failure", + ); + await expect(store.head("some-key")).resolves.toBeNull(); + expect(createAttempts).toBe(2); + + // Success stays memoized: further operations do not re-create. + await expect(store.head("some-key")).resolves.toBeNull(); + expect(createAttempts).toBe(2); + }); }); diff --git a/packages/storage-azure-blob/src/index.ts b/packages/storage-azure-blob/src/index.ts index cb30323..0866f92 100644 --- a/packages/storage-azure-blob/src/index.ts +++ b/packages/storage-azure-blob/src/index.ts @@ -283,7 +283,15 @@ export function createAzureBlobStore( return; } if (ensureContainer === undefined) { - ensureContainer = container.createIfNotExists().then(() => undefined); + // Memoize only success: a cached rejection would replay the original + // failure on every operation for the lifetime of the store. + ensureContainer = container.createIfNotExists().then( + () => undefined, + (error: unknown) => { + ensureContainer = undefined; + throw error; + }, + ); } await ensureContainer; } diff --git a/packages/storage-blobs/package.json b/packages/storage-blobs/package.json index 682550c..39f8d20 100644 --- a/packages/storage-blobs/package.json +++ b/packages/storage-blobs/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-blobs", - "version": "0.1.1", + "version": "0.1.2", "description": "Provider-neutral object (blob) storage: opaque keys, streaming put/get, conditionals, and a conformance suite.", "license": "MIT", "type": "module", diff --git a/packages/storage-cloudflare-r2/package.json b/packages/storage-cloudflare-r2/package.json index bd9588b..f3b3739 100644 --- a/packages/storage-cloudflare-r2/package.json +++ b/packages/storage-cloudflare-r2/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-cloudflare-r2", - "version": "0.1.1", + "version": "0.1.2", "description": "Cloudflare R2 adapter for @pegma/storage-blobs (S3-compatible API).", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ }, "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.1" + "@pegma/storage-blobs": "0.1.2" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/storage-s3/package.json b/packages/storage-s3/package.json index 0d5415f..7bea126 100644 --- a/packages/storage-s3/package.json +++ b/packages/storage-s3/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-s3", - "version": "0.1.1", + "version": "0.1.2", "description": "AWS S3 / S3-compatible adapter for @pegma/storage-blobs.", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ }, "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.1" + "@pegma/storage-blobs": "0.1.2" }, "scripts": { "build": "tsc -p tsconfig.json", From 94901415fee2ceac132b8d15f9502a0374105e87 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Wed, 29 Jul 2026 22:29:59 -0400 Subject: [PATCH 2/2] Exercise the container-creation retry against Azurite Review feedback: the retry regression test stubbed the whole ContainerClient, which conflicts with the repository rule to verify adapters against a real backend. Use a real client against Azurite and inject the one-shot fault into createIfNotExists only, delegating to the real implementation on retry, so the second attempt actually creates the container and the subsequent head round-trips the emulator. Co-Authored-By: Claude Fable 5 --- packages/storage-azure-blob/src/index.test.ts | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/packages/storage-azure-blob/src/index.test.ts b/packages/storage-azure-blob/src/index.test.ts index 6a876dc..03262ff 100644 --- a/packages/storage-azure-blob/src/index.test.ts +++ b/packages/storage-azure-blob/src/index.test.ts @@ -1,4 +1,4 @@ -import { BlobServiceClient, type ContainerClient } from "@azure/storage-blob"; +import { BlobServiceClient } from "@azure/storage-blob"; import { concurrentConformanceCases, conformanceCases, @@ -92,32 +92,22 @@ describe("createAzureBlobStore", () => { }); } - // Azurite cannot be made to fail createIfNotExists exactly once, so this - // fault-injection case uses a stub client instead of the emulator. + // Real client against Azurite; only the first createIfNotExists call is + // forced to fail, since the emulator cannot inject a one-shot fault itself. it("retries container creation after a failed first attempt", async () => { + const container = serviceClient().getContainerClient(nextContainerName()); let createAttempts = 0; - const notFound = () => - Object.assign(new Error("BlobNotFound"), { statusCode: 404 }); - const containerClient = { - containerName: "retry-container", - accountName: ACCOUNT, - url: `http://127.0.0.1:${BLOB_PORT}/${ACCOUNT}/retry-container`, - createIfNotExists: async () => { - createAttempts += 1; - if (createAttempts === 1) { - throw new Error("transient container create failure"); - } - return { succeeded: true }; - }, - getBlockBlobClient: () => ({ - getProperties: async () => { - throw notFound(); - }, - }), - } as unknown as ContainerClient; + const realCreate = container.createIfNotExists.bind(container); + container.createIfNotExists = async (createOptions) => { + createAttempts += 1; + if (createAttempts === 1) { + throw new Error("transient container create failure"); + } + return realCreate(createOptions); + }; const store = createAzureBlobStore({ - containerClient, + containerClient: container, createContainerIfMissing: true, });