Repository navigation
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Problem
In remote mode (remote: true), the D1 binding accepts withSession(), but it does not keep the D1 session contract:
app code remote D1 binding today
----------------------------------------- ------------------------------------------
db.withSession('first-primary') → returns the same binding; constraint ignored
session.prepare(sql).run() → proxy request has binding/sql/params/method only
session.getBookmark() → always null
db.withSession(savedBookmark) → bookmark ignored
Each statement is a separate proxy call that runs on the deployed binding without a session. void/db and auth work (#402 added withSession() so they no longer crash). But code that depends on bookmarks sees a different contract in remote development than in production. For example, it cannot carry a bookmark between requests, and getBookmark() never returns a value.
Code: packages/void/src/runtime/remote/d1.ts (ProxyD1Database.withSession, getBookmark) and the proxy handler platform/packages/proxy/src/d1.ts.
What a fix needs
client proxy (deployed binding)
ProxyD1DatabaseSession ── query/batch ─► db.withSession(constraint or bookmark)
{ constraint | bookmark } run the statement(s)
◄──────── result + bookmark ───── session.getBookmark()
store the new bookmark
withSession()returns a new session object for each call. Two sessions do not share state.- Each
queryandbatchrequest sends the session's constraint (first call) or its latest bookmark. - The proxy handler runs the request in
db.withSession(...)and returnssession.getBookmark()with the result. The client stores it. - An older proxy that does not know sessions fails with a clear error. The client must not act as if bookmarks work.
Tests
first-primary,first-unconstrained, and a bookmark from an earlier request.- A query and then a batch move the bookmark forward.
- Two sessions keep separate bookmarks.
- A real client → proxy round trip, and the error against an older proxy.
References
- D1 session API: https://developers.cloudflare.com/d1/worker-api/d1-database/#withsession
- fix: high-severity bugs in the CLI, runtime and adapters #402 added the
withSession()method sovoid/dband auth work in remote mode.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Fields
Priority
None yet
Activity
fix: high-severity bugs in the CLI, runtime and adapters (#402)