Repository navigation
fix: binding leftovers match workerd (#239) - #249
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 14 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
ryuzdev
force-pushed
the
fix/binding-leftovers-2
branch
from
November 24, 2026 11:45
d02e53b to
e6f7da2
Compare
- storage.put(entries) takes a plain object, as workerd's one overload resolves it: own enumerable string keys, undefined values dropped, a Map or Set writing nothing, and an array read as the single-pair form with a coerced key. A primitive key coerces and a symbol key throws V8's conversion error; put() with no argument names the `string or object` parameter instead of a conversion error. - list() and the synchronous kv.list() convert ListOptions the way JSG does: string fields by ToString, reverse by ToBoolean, limit as an int32 with `List limit must be positive.`, start+startAfter refused, undefined fields absent. No serde text reaches a Worker. - exec() counts one per input line that carries a statement, refuses an input with no such line before running anything, and keeps the line-1 error shape. Cello still runs the input as one statement stream, so a statement may span lines where workerd's line split forbids it. - A D1 meta reports the application's own last_row_id (0 for a fresh DDL, and a read after a write keeps it) and a size_after that counts only the application's pages: dbstat subtracts the storage control tables and the replica's, so a fresh database is 4096 bytes as in workerd. - Binding methods report length 0 like the native functions they emulate; D1 keeps its TypeScript arities and query() takes one argument. - The differential gate gains five cases (223 total), each with a fail-before, plus unit tests for the line scan and the two meta values.
- storage.put(entries, options): any object is the options dictionary,
an array included. workerd's struct conversion reads an array
positionally into PutOptions, so every shape leaves the fields at
their defaults and put({a: 1}, []) writes `a`; the batch form no longer
refuses one.
- exec() trims its input the way String.prototype.trim does before it
splits, runs and names the failing line, so NBSP and the byte-order
mark reach neither SQLite nor the error text, and the line a failure
names is the trimmed one.
- Gate: five array-options sub-cases in do/storage-put-entries and a
d1-exec-unicode case (224 cases agree), both with a fail-before on
d02e53b.
ryuzdev
force-pushed
the
fix/binding-leftovers-2
branch
from
November 24, 2026 11:55
e6f7da2 to
cb48f2a
Compare
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.
Closes #239
The five binding leftovers from the #235 sweep, each measured against workerd
1.20261121.1 (its local D1 is
src/workerd/server/d1/d1.js; storage isapi/actor-state.c++; binding methods are JSG/native).storage.put(entries)takes a plain objectworkerd has one signature,
put(key: string or object, value, options), andits WebIDL union picks the form: a non-array object is the batch dictionary
(the second argument is then its options), everything else is the single-pair
form with a ToString key. The same rule now decides in Cello:
put(new Map([["a",1]]))aput(new Set/Date)put(new Entries())a,b(own enumerable keys)put({u: undefined, keep: 1})keeponlyundefinedkeeponlyput([["a",1]])TypeError: put() called with undefined value.0put([["r",1]], opts)"r,1"0"r,1"put(5, "five"),put(null, 1),put(7n, "seven")"5","null","7"put(Symbol())Cannot convert a Symbol value to a stringSymbol(...)storedput()parameter 1 is not of type 'string or object'Cannot convert undefined or null to objectlist()andkv.list()convertListOptionsEvery field now converts as JSG converts it, so no serde text reaches a
Worker: the string fields take any value (
start: 5reads"5",prefix: nullreads"null"),reverseis a boolean coercion ("0"istrue),
limitis anint("5"→ 5,1.9→ 1,2**31→ workerd's int32range message,
5n→Cannot convert a BigInt value to a number,null/{}/NaN→List limit must be positive.), anundefinedfield isabsent, and
startwithstartAfteris refused withlist() cannot be called with both start and startAfter values.The synchronouskv.list()sharesthe conversion and names
SyncKvStoragein its parameter refusal.exec()counts input linesworkerd trims the input, splits it on newlines and sends each line as one
query, so
countis one per line that carries a statement: one line holdingtwo statements counts once, and blank, whitespace-only,
;-only andcomment-only lines count not at all. An input with no counted line fails with
D1_EXEC_ERROR: Error in line 1: <line>: No SQL statements detected.beforeanything runs, and a failing input still reports line 1's text, as workerd's
wrapper does.
Deliberate deviation: Cello still runs the whole input as one statement
stream, so a statement may span lines (a multi-line
CREATE TABLEin a dumpworks); workerd's per-line split forbids that. Documented on the D1 service
page and in the compatibility reference.
Fresh-cell
last_row_idandsize_afterlast_row_idis the connection's last assignment in workerd, so a readafter a write still reports it. Cello's value was moved by its own writes:
opening a replicated cell upserts the alarm wake record, which is why a
first DDL reported 1. The cell now tracks the application's own assignment,
resetting the connection's value before each statement (SQLite never uses it
to assign rowids), so a fresh DDL reports 0, a first insert 1, a read after
a write the same value, and a DDL after Cello's own insert no longer
inherits it.
size_afteris workerd's(page_count - freelist_count) * page_sizeover adatabase with no control tables in it -- workerd creates
_cf_KVandfriends lazily and a D1 database never touches them. Cello creates them on
open and keeps the wake record and the replica's tables in the same file, so
a fresh database read 49152 bytes where workerd reads 4096.
dbstat(already compiled into Cello's SQLite) names the btree that owns each page,
so those objects are subtracted exactly with one
name = ?lookup perobject: fresh 4096, one table 8192, two tables 12288, and a 304-row bulk
insert 151552 -- the same numbers the gate compares against workerd.
Binding method arities
A binding's methods are native in workerd, so V8 publishes
length0 forevery JSG interface whatever its signature reads; the D1 interface is a
TypeScript class there and keeps its declared arities.
put.lengthwas 3 andis now 0, as are every method of
DurableObjectStorage,SqlStorage,DurableObjectState,DurableObjectNamespace,DurableObjectId,KvNamespace,R2Bucket,QueueandCache/CacheStorage.D1Databasekeeps
prepare/batch/exec/withSession/query/dump= 1/1/1/1/1/0 asworkerd does, and
query()now takes one declared argument.Not covered, each a different class of divergence:
DurableObjectStorage'sprototype also carries Cello's internal
_-prefixed members and lacksworkerd's
getCurrentBookmark/getBookmarkForTime/onNextSessionRestoreBookmark;SqlStorageexposesprepare/ingestand its test hooks; a DO stub is aProxy with no prototype (
stub.fetch.lengthis 2); the D1 session mirrorsworkerd's internal
_send-style members in neither direction; andsetHibernatableWebSocketEventTimeoutis missing. An array passed whereListOptionsis expected returns the reversed listing on workerd, whichreads as uninitialised state rather than a rule, so it is not reproduced.
Verification
do/storage-put-entries,do/storage-list-fields,do/method-lengths,d1-exec-lines,d1-meta-fresh(a second, pristine D1 database so thesize and row-id numbers are not disturbed by earlier cases).
storage.rsfor the line scan, the exec count, thetracked row id and the page subtraction.
cargo test --profile ci --locked -p cello --no-fail-fast, clippy with-D warnings,cargo fmt --checkandnode scripts/check-docs.mjsallclean.
page (put/list shapes), compatibility reference, changelog.