Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ The `v0.4.3` attempt failed its npm-version check before preparation.
The `v0.4.4` attempt completed preparation and smoke checks, then failed the
preflight CLI entry with a module cycle (exit 13), before publication.
Keep both signed tags immutable and retain their releases as failed attempts.
`@pegma/storage-dynamodb@0.4.5` is the unpublished first trusted
AWS runtime candidate (see `docs/AWS_ADAPTER.md` and `docs/RELEASING.md`).
The later D1 feature is planned as `0.4.6`. Do not claim runtime release before
its actual registry qualification. The port offers keyed access,
`@pegma/storage-dynamodb@0.4.5` is now a
[qualified trusted runtime](https://github.com/pegma-dev/storage-core/releases/tag/v0.4.5),
retaining exact Core `0.4.0`. D1 `0.4.6` is the unpublished candidate for optional
concurrent keyed-read batching; its default remains `readBatchSize: 1`.
Its own review, release qualification and host Free-plan acceptance remain
separate gates. See `docs/RELEASING.md` and the D1 package README.
The port offers keyed access,
optimistic concurrency through `update`, version-conditional
`putIfUnchanged` and `deleteIfUnchanged`, partition reads, bounded
authoritative cross-partition scans, and `transact`.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ and what you decode is what the last writer decided.
| `@pegma/storage-cloudflare-d1` | available; passes the same conformance run |
| `@pegma/storage-dynamodb` | available; passes the same conformance run |

Published versions are Core `0.4.0`, Azure Tables `0.4.0`, D1 `0.4.1` and the
[qualified DynamoDB `0.4.5` runtime](https://github.com/pegma-dev/storage-core/releases/tag/v0.4.5).
D1 `0.4.6` remains an unpublished candidate for optional concurrent keyed-read
batching, with direct reads still the default; see its
[package README](packages/storage-cloudflare-d1/README.md). This candidate does
not establish a released adapter or live Workers Free host acceptance.

The in-memory store is not only for tests. It enforces the same concurrency
rules as a real backend, so an assembled application runs correctly before
anyone has configured a database.
Expand Down
19 changes: 10 additions & 9 deletions docs/AWS_ADAPTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

The runtime adapter is implemented in this repository. It qualifies when every
conformance case passes against **Amazon DynamoDB Local** and the release gates
are satisfied. `@pegma/storage-dynamodb@0.4.5` is the unpublished first trusted
runtime candidate. Version `0.4.2` was published as a separately reviewed,
are satisfied. [`@pegma/storage-dynamodb@0.4.5`](https://github.com/pegma-dev/storage-core/releases/tag/v0.4.5)
is now the qualified first trusted runtime. Version `0.4.2` was published as a separately reviewed,
metadata-only registration archive: it contains no runtime, exports, scripts or
dependencies, is not an SDK, and must never be a host input. The `v0.4.3` release
attempt failed its npm-version check before preparation, producing no runtime
archive. The `v0.4.4` attempt completed preparation and smoke checks, then failed
the preflight CLI entry with a module cycle (exit 13). Neither published a
runtime. Keep both signed tags immutable and retain the failed releases.
Runtime qualification remains pending.
The later `0.4.5` runtime completed registry and public-consumer qualification;
actual host adoption remains a separate acceptance step.

Decided 2026-09-11. This is the assignment record for Storage Core's third
real adapter — read `AGENTS.md` first; its hard rules govern everything here.
Expand Down Expand Up @@ -81,20 +82,20 @@ Node 22 + 24.
## Versioning and publish

The port is unchanged, so `@pegma/storage-core` stays at `0.4.0` and the runtime
candidate pins it exactly. `0.4.2` is registration-only metadata under `bootstrap`,
not a usable adapter release. The first trusted runtime candidate is `0.4.5`;
its publication requires the reviewed signed-source and trusted-publisher flow.
runtime pins it exactly. `0.4.2` is registration-only metadata under `bootstrap`,
not a usable adapter release. The qualified `0.4.5` runtime completed the reviewed
signed-source and trusted-publisher flow.
Existing repository-wide tags `v0.4.0`, `v0.4.1`, failed `v0.4.3` and failed
`v0.4.4` must never be reused. The later D1 feature is planned as `0.4.6`, after
its own review.
`v0.4.4` must never be reused. The separate D1 `0.4.6` candidate remains
unpublished and requires its own review and release qualification.

Unprivileged validation runs the full gates on Node 22 and 24 before preparation.
Preparation depends on that validation and signed-release identity checks; it
packs only selected source packages and retains the independently pinned exact
original registry archives for unselected packages. Only the minimal publish job
receives OIDC authority. See [RELEASING.md](RELEASING.md) for the separate
registration exception and runtime release procedure. Published metadata
registration does not qualify a runtime, which remains unpublished.
registration alone does not qualify a runtime.

## What it unblocks

Expand Down
58 changes: 42 additions & 16 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,38 @@ below is an explicit first-package exception, not a runtime release path.

## Current versions and source ownership

Core and Azure are published at `0.4.0`; D1 at `0.4.1`. DynamoDB `0.4.2` is
published registration-only metadata, and `0.4.5` is the unpublished first trusted
runtime candidate. The `v0.4.3` release attempt failed its npm-version check
Core and Azure are published at `0.4.0`; D1 at `0.4.1`. DynamoDB `0.4.5` is the
qualified trusted runtime; `0.4.2` remains published registration-only metadata.
D1 `0.4.6` is the current unpublished candidate for optional concurrent keyed-read
batching. Its release and host request-budget acceptance remain separate gates.
The `v0.4.3` release attempt failed its npm-version check
before preparation: no runtime archive was produced or published. Its signed
tag remains immutable; preserve the release as a failed attempt. The `v0.4.4`
attempt completed preparation and smoke checks, then its direct preflight CLI
failed with a top-level-await module-entry cycle (exit 13), before publication.
Retain that signed tag, prepared artifacts and failed release as well.
Registration is not adapter code, conformance
evidence or a production dependency; runtime qualification remains pending.

Unversioned Core/Azure/D1 changes in current source are **not** the code published
at those versions. Schema 2 deliberately selects source artifacts by the new tag
version and reuses original registry archives for the others. It never rebuilds
those old versions or labels their old provenance as the new source. Hosts retain
Registration is not adapter code, conformance evidence or a production dependency.

The [qualified DynamoDB `0.4.5` release](https://github.com/pegma-dev/storage-core/releases/tag/v0.4.5)
binds signed source
[`a5a5d0bfe6355df89c049fcec3148845c5124735`](https://github.com/pegma-dev/storage-core/commit/a5a5d0bfe6355df89c049fcec3148845c5124735).
[Recovery attempt 2](https://github.com/pegma-dev/storage-core/actions/runs/42679292292/attempts/2)
reused the original prepared artifact and made no new npm uploads. The accepted write
belongs to attempt 1, whose visibility check failed; final registry cryptographic,
source and isolated public-consumer verification completed during recovery.

For D1 `0.4.6`, schema 2 selects only the new D1 source artifact and must reuse
the original qualified Core `0.4.0`, Azure `0.4.0` and DynamoDB `0.4.5` registry
archives. Unselected workspace builds are not substitutes for those bytes.
The reviewed reuse policy must bind their original source and writer identities.
Never label historical provenance as the new D1 source. Hosts retain
the genuine Core `0.4.0` runtime, including StorageError/ConcurrencyError identity;
no Core or host upgrade is implied.

Versions are independently assigned but release tags share a repository-wide
namespace. Never reuse or move a tag/version, including failed publication or
registration versions. First trusted DynamoDB is now planned as `v0.4.5`; the
separate later D1 feature is planned as `0.4.6`, after rebase and its own review.
registration versions. DynamoDB `v0.4.5` is qualified; the next D1 release is
planned as `v0.4.6` and requires its own current-head review and release gates.

A release run uses the workflow at its tagged commit, as documented in
[workflow triggers](https://docs.github.com/en/actions/concepts/workflows-and-actions/workflows#workflow-triggers)
Expand Down Expand Up @@ -65,12 +75,12 @@ record; never install it for a backend/host proof or describe it as the
latest runtime. Inspect actual registry bytes/dist-tags afterward. No GitHub
v0.4.2 release is needed.

Verify trusted publishing and package/account restrictions again for the fresh
runtime candidate. After the corrected source passes full gates and merges,
create and verify its signed annotated `v0.4.5` tag on `origin/main`; create its
For the D1 `0.4.6` candidate, verify trusted publishing and package/account
restrictions again. After its reviewed source passes full gates and merges,
create and verify its signed annotated `v0.4.6` tag on `origin/main`; create its
GitHub release only when this configuration is complete. Do not move or reuse
the signed `v0.4.3` or `v0.4.4` tags; retain their releases as failed attempts.
Never manually publish the real `0.4.5` artifact
Never manually publish the real `0.4.6` artifact
first: immutable bytes with missing trusted
provenance cannot later be repaired by a skip. Registration `0.4.2` remains immutable
and explicitly outside runtime qualification.
Expand Down Expand Up @@ -163,6 +173,22 @@ It imports public roots, executes published Core conformance against DynamoDB
Local, and proves real StorageError/ConcurrencyError identity with Core `0.4.0`.
The fixture is local synthetic backend evidence, not a deployed AWS claim.

For D1 `0.4.6`, that generic consumer proves only a D1 import; its DynamoDB
conformance run does not exercise the D1 adapter. Before merge or publication,
owner acceptance additionally requires an isolated selected D1 tarball plus
genuine canonical registry Core `0.4.0`, with no aliases, overrides or workspace
resolution. Copy the existing full D1 suite, changing only its adapter import to
the bare package. Run every conformance case exported by published Core `0.4.0`
in both default and `readBatchSize: 512` modes and all adapter-specific cases
against real Miniflare on Node 22 and 24, with no skips, using the
[D1 test configuration](../vitest.d1.config.ts). Typecheck the
[public type fixture](../test/d1-public-types.ts) on both lanes.
Record actual case counts, the lockfile, archive and complete suite/input hashes,
and constructor-resolution evidence. Published Core's case count can differ from
the workspace suite; require the full suite from pinned inputs, not a fixed
workspace count. Source-suite
passes do not satisfy this separate packed gate or establish live Free acceptance.

## Preflight and minimal publish

A separate unprivileged whole-set preflight verifies exact canonical registry
Expand Down
13 changes: 9 additions & 4 deletions docs/securityscan.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ the end. Severity scale: Critical / High / Medium / Low / Informational.
larger batch than the caller wrote. Corrected 2026-07-29: D1 publishes no
per-batch statement or SQL-size limit, as originally claimed here. The limit
that actually binds is per Worker invocation — 1000 queries on Workers Paid,
50 on Free — and every statement inside a batch counts against it.
50 on Free. **Accounting correction 2026-11-09:** the July note incorrectly
counted each statement inside a batch against that budget. The current
[Cloudflare D1 limits](https://developers.cloudflare.com/d1/platform/limits/)
count one `db.batch()` call as one query against the invocation limit.
Individual statements retain their own SQL limits. The adapter's 100-action
transaction cap is a parity/robustness bound, not a platform batch limit.
- **Exploitability:** Not attacker-reachable on its own; a host application
would have to pass an oversized action list. The outcome is a thrown D1
error, not corruption — D1 batches are atomic. It is a robustness/parity
Expand All @@ -103,9 +108,9 @@ the end. Severity scale: Critical / High / Medium / Low / Informational.
- ✅ Resolved 2026-07-29 — the D1 adapter refuses more than 100 actions with a
`StorageError` from the action count alone, before deriving keys, preparing
statements, or touching the database, matching the Azure adapter's limit so
one action list is accepted or refused by both. The query-budget correction
noted in the evidence is recorded in the adapter comment and the package
README.
one action list is accepted or refused by both. The current query-budget
accounting is documented in the November correction above, the adapter
comment and the package README.

### 4. D1 transaction rejection inferred by substring match on error text

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.18.8",
"@cloudflare/workers-types": "^5.20260727.1",
"@pegma/storage-cloudflare-d1": "workspace:0.4.1",
"@pegma/storage-cloudflare-d1": "workspace:0.4.6",
"@types/node": "^26.1.1",
"azurite": "^3.36.0",
"prettier": "^3.9.6",
Expand Down
59 changes: 57 additions & 2 deletions packages/storage-cloudflare-d1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Cloudflare D1 adapter for
[`@pegma/storage-core`](https://www.npmjs.com/package/@pegma/storage-core).

The published release remains `0.4.1`. This source is the unpublished `0.4.6`
candidate for optional concurrent keyed-read batching and retains exact Core
`0.4.0`. Its review, registry qualification and complete host request-budget
acceptance remain pending; source tests alone do not establish live Free usage.

It stores every collection in one D1 database and one `RECORDS` data table.
The physical partition key is `<collection>:<partition>` and the row key is
the record id. All values are passed through prepared statements.
Expand Down Expand Up @@ -78,6 +83,55 @@ Replicated or session-based reads are incompatible with this adapter. Even a
session that starts on the primary may use replicas for subsequent reads, so
the adapter deliberately does not use the Sessions API.

## Optional concurrent keyed-read batching

The default `readBatchSize: 1` retains direct keyed reads. To coalesce
concurrent public `get` and `getVersioned` calls, opt in when constructing a
Store inside the request:

```ts
const store = createCloudflareD1Store({
database: env.DB,
readBatchSize: 512,
});
```

`readBatchSize` must be a safe integer from 1 through 512. This is an adapter
tuning bound, not a Cloudflare batch-size limit. Calls queued together are
sent as at most that many prepared keyed statements in one real D1 batch.
There is at most one read batch in flight per Store, and a partial batch runs
without waiting for more calls. Collection handles on that Store share the
queue; separate Store instances do not. Use a request-scoped Store rather
than sharing the queue across Worker requests.

`readBatchSize` bounds each D1 batch, not the total pending read requests.
The adapter has no total pending-queue cap. Callers must bound their concurrent
read waves and the Store's lifetime within the request.

Only calls that actually reach storage concurrently can coalesce. Finish
asynchronous key preparation before starting a parallel read wave if the
caller needs predictable batching. Sequential awaited calls remain separate.
There is no caching or same-key deduplication, and each caller decodes its
own value. A batch failure rejects all reads in that batch; later calls can
recover without an automatic fallback to individual requests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 Reversed Cloudflare D1 quota-accounting claim (batch = one query) is now asserted as fact and underpins the feature's value proposition (risk)

If the linked Cloudflare limits page does not actually say that one db.batch() counts as a single query against the per-invocation limit, the new documentation actively misleads Free-plan users: a 512-statement read batch or a 100-action transaction would still consume 50/100+ queries per invocation, and a host that adopts readBatchSize: 512 to stay inside the 50-query Free budget would instead be throttled mid-request.

This is not a neutral restatement: the code comment being edited asserted the exact opposite before this PR ("every statement inside a batch counts against the Worker invocation's D1 query budget"), and the whole rationale for MAX_TRANSACTION_ACTIONS = 100 was premised on that older understanding. The PR flips the claim in three places at once:

  • packages/storage-cloudflare-d1/src/index.ts MAX_TRANSACTION_ACTIONS comment (~line 32): "D1 counts a batch as one query against the invocation budget"
  • packages/storage-cloudflare-d1/README.md (~line 113): "one db.batch() counts as one query against that limit, not one per statement" and "50 queries per Free Worker invocation"
  • packages/storage-cloudflare-d1/README.md transaction section (~line 168): "Cloudflare counts the batch as one query against the invocation query budget"

I could not verify the external claim: the review environment has no network access, and no repository file or test pins the Cloudflare-documented accounting. Given the repository's own discipline of not asserting unqualified external facts, the claim should be re-verified against the linked page (and ideally pinned with a quoted excerpt and observation date, as tests/fixtures/release-registry/README.md does) before this text is published in the 0.4.6 package README.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current Cloudflare limits page explicitly documents this accounting rule. Under “Batch limits” it says: “a db.batch() call counts as a single query against it”. The same page lists 50 queries per Worker invocation on Free and 1,000 on Paid. See Cloudflare D1 limits, updated October 30, 2026.

The per-statement SQL limits still apply to each individual statement. Our README separates those limits from the adapter's configurable 1–512 statement batching bound. This PR makes no claim that a local test proves live Free CPU or daily usage acceptance.

The finding's conditional premise is therefore contradicted by the current primary documentation. I am retaining the correct accounting statement and leaving this thread visible with the supporting evidence.

Writes, internal optimistic reads, partition lists, scans and transactions
keep their existing paths. Batching does not add snapshot or read/write
ordering guarantees: retain version checks and current-state fences. A new
read after an awaited write still reads the direct primary binding.

Cloudflare's [current D1 limits](https://developers.cloudflare.com/d1/platform/limits/)
allow 50 queries per Free Worker invocation; one `db.batch()` counts as one
query against that limit, not one per statement. The limit of 100 bound
parameters applies to each individual query, not the whole batch. The adapter's
512-statement tuning ceiling is not a Cloudflare batch-size limit.
Statement constraints and row-based usage still apply. A larger batch reduces
binding calls, not rows read or serialization work. Choose the
size for the application's bounded record sizes and concurrent callers;
512 arbitrary large records can exceed platform memory or result limits.
Measure complete request budgets, including authentication and final fences,
before relying on a Free-plan profile.

## Versions and deletes

Versions are opaque strings backed by monotonically increasing SQLite integer
Expand Down Expand Up @@ -115,8 +169,9 @@ required by `@pegma/storage-core`.
A transaction carries at most 100 actions, the same limit the Azure Tables
adapter enforces, so an action list either works on both adapters or is
refused by both with a `StorageError`. The limit is checked before any
statement is sent. Each action costs one to three statements in the batch, and
every statement counts against the Worker invocation's D1 query budget.
statement is sent. Each action costs one to three statements in the batch.
Cloudflare counts the batch as one query against the invocation query budget;
individual statement constraints and row-based usage still apply.

## License

Expand Down
2 changes: 1 addition & 1 deletion packages/storage-cloudflare-d1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/storage-cloudflare-d1",
"version": "0.4.1",
"version": "0.4.6",
"description": "Cloudflare D1 adapter for @pegma/storage-core.",
"license": "MIT",
"type": "module",
Expand Down
Loading
Loading