Skip to content

fix: binding leftovers match workerd (#239) - #249

Merged
ryuzdev merged 2 commits into
mainfrom
fix/binding-leftovers-2
Nov 24, 2026
Merged

ryuzdev merged 2 commits into
mainfrom
fix/binding-leftovers-2

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 24, 2026

Copy link
Copy Markdown
Member

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 is
api/actor-state.c++; binding methods are JSG/native).

storage.put(entries) takes a plain object

workerd has one signature, put(key: string or object, value, options), and
its 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:

call workerd before now
put(new Map([["a",1]])) writes nothing writes a writes nothing
put(new Set/Date) nothing nothing nothing
put(new Entries()) a, b (own enumerable keys) same same
put({u: undefined, keep: 1}) keep only stored undefined keep only
put([["a",1]]) TypeError: put() called with undefined value. stored key 0 same TypeError
put([["r",1]], opts) stores key "r,1" stored key 0 key "r,1"
put(5, "five"), put(null, 1), put(7n, "seven") keys "5", "null", "7" threw coerced
put(Symbol()) Cannot convert a Symbol value to a string Symbol(...) stored V8's error
put() parameter 1 is not of type 'string or object' Cannot convert undefined or null to object workerd's

list() and kv.list() convert ListOptions

Every field now converts as JSG converts it, so no serde text reaches a
Worker: the string fields take any value (start: 5 reads "5",
prefix: null reads "null"), reverse is a boolean coercion ("0" is
true), limit is an int ("5" → 5, 1.9 → 1, 2**31 → workerd's int32
range message, 5n → Cannot convert a BigInt value to a number,
null/{}/NaN → List limit must be positive.), an undefined field is
absent, and start with startAfter is refused with list() cannot be called with both start and startAfter values. The synchronous kv.list() shares
the conversion and names SyncKvStorage in its parameter refusal.

exec() counts input lines

workerd trims the input, splits it on newlines and sends each line as one
query, so count is one per line that carries a statement: one line holding
two statements counts once, and blank, whitespace-only, ;-only and
comment-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. before
anything 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 TABLE in a dump
works); workerd's per-line split forbids that. Documented on the D1 service
page and in the compatibility reference.

Fresh-cell last_row_id and size_after

  • last_row_id is the connection's last assignment in workerd, so a read
    after 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_after is workerd's (page_count - freelist_count) * page_size over a
    database with no control tables in it -- workerd creates _cf_KV and
    friends 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 per
    object: 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 length 0 for
every JSG interface whatever its signature reads; the D1 interface is a
TypeScript class there and keeps its declared arities. put.length was 3 and
is now 0, as are every method of DurableObjectStorage, SqlStorage,
DurableObjectState, DurableObjectNamespace, DurableObjectId,
KvNamespace, R2Bucket, Queue and Cache/CacheStorage. D1Database
keeps prepare/batch/exec/withSession/query/dump = 1/1/1/1/1/0 as
workerd does, and query() now takes one declared argument.

Not covered, each a different class of divergence: DurableObjectStorage's
prototype also carries Cello's internal _-prefixed members and lacks
workerd's getCurrentBookmark/getBookmarkForTime/onNextSessionRestoreBookmark;
SqlStorage exposes prepare/ingest and its test hooks; a DO stub is a
Proxy with no prototype (stub.fetch.length is 2); the D1 session mirrors
workerd's internal _send-style members in neither direction; and
setHibernatableWebSocketEventTimeout is missing. An array passed where
ListOptions is expected returns the reversed listing on workerd, which
reads as uninitialised state rather than a rule, so it is not reproduced.

Verification

  • Five new differential cases with fail-before against the pre-change binary:
    do/storage-put-entries, do/storage-list-fields, do/method-lengths,
    d1-exec-lines, d1-meta-fresh (a second, pristine D1 database so the
    size and row-id numbers are not disturbed by earlier cases).
  • Full gate: 223 cases agree (218 before, +5).
  • Four new unit tests in storage.rs for the line scan, the exec count, the
    tracked row id and the page subtraction.
  • cargo test --profile ci --locked -p cello --no-fail-fast, clippy with
    -D warnings, cargo fmt --check and node scripts/check-docs.mjs all
    clean.
  • Docs: D1 service page (meta, exec counting, the deviation), durable-objects
    page (put/list shapes), compatibility reference, changelog.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b5ad87f0-2a50-402b-b9ce-0a7848744a56
Commits

Reviewing files that changed from the base of the PR and between af5e3ca and cb48f2a.

Files selected for processing: 12

  • crates/cello/js/harness.js
  • crates/cello/js/services/kv.js
  • crates/cello/storage.rs
  • docs/changelog.md
  • docs/reference/cloudflare-compat.md
  • docs/services/d1.md
  • docs/services/durable-objects.md
  • scripts/workerd-diff/cases.mjs
  • scripts/workerd-diff/corpus/d1/index.js
  • scripts/workerd-diff/corpus/d1/wrangler.json
  • scripts/workerd-diff/corpus/do/index.js
  • scripts/workerd-diff/corpus/do/wrangler.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

- 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
ryuzdev force-pushed the fix/binding-leftovers-2 branch from e6f7da2 to cb48f2a Compare November 24, 2026 11:55
@ryuzdev
ryuzdev merged commit 6675ae7 into main Nov 24, 2026
9 checks passed
@ryuzdev
ryuzdev deleted the fix/binding-leftovers-2 branch November 24, 2026 12:09
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.

workerd diff: binding leftovers (DO put(Map), D1 exec count, fresh-cell last_row_id/size_after, DO list field messages, put.length)

1 participant