Repository navigation
Measure D1 usage again after Cloudflare made its binding fields private - #266
Merged
Merged
Conversation
Cloudflare moved the D1 binding's primary-only session into a private field. The runtime needed it to observe queries, so it fell back to the unobserved binding and measured no usage at all. Observe the fresh session of each query in place instead, and run exec as one batch on that session, as native exec treats each line as one statement. A query that completes without a measurement is reported.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 0f6783d | Nov 21 2026, 04:47 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The runtime measured D1 queries through the binding's primary-only session,
alwaysPrimarySession. On 2026-11-04 Cloudflare made that field private (workerd 7d790e45). Since then the setup check fails on every query. The runtime then falls back to the unobserved binding and only logsD1 observation unavailable: incompatible native binding. No D1 usage is measured at all.Fix
withSession(). It changes_sendon that session in place. A copy cannot reach the private transport fields.exec: nativeexecruns only on the private primary-only session. The runtime now runs the same statements as one batch on the query's session:exec, it treats each line as one statement.execfor multi-statement lines, blank lines,PRAGMAand failures. On a failure, both roll back every statement.D1_EXEC_ERROR: Error in line 1: …format._sendis reported with the same error. That would happen if D1 queries took another path, such as the experimentald1_binding_jsrpcbinding.Tests
tests/cloudflare/d1-observer.test.tscompares every scenario natively and through the runtime, includingexecandexec-error.pnpm check, the app runtime unit tests, and the Cloudflare and dynamic runtime suites.noindexcontrol-plane test, which also fails locally onmain.

Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Restores D1 usage measurement by observing each query’s fresh session instead of the binding’s now-private primary session.
execruns each SQL line together on the query session.Reviews (1) · Last reviewed commit: "Measure D1 usage again after Cloudflare ..." · Reviewed by Greptile