Summary
SqlMessageStorage reads snowflake columns (id, request_id, reply_id, last_reply_id, and joined reply ids) under SqlClient.SafeIntegers, then turns them back into ids with String / Snowflake. That is exact only when the driver returns the full 64-bit integer.
@effect/sql-sqlite-do cannot do that. Durable Object sql.exec().raw() types every SQLite INTEGER as a JavaScript number (ArrayBuffer | string | number | null), so a value above 2^53 is rounded on read. The stored integer stays exact. Default snowflakes have been above 2^53 since early 2025, so on a Durable Object nearly every id read back is wrong: a reply is saved with the rounded request_id, UPDATE ... SET processed = TRUE WHERE request_id = ... matches nothing, and the message is delivered again on every poll. requestIdForPrimaryKey and duplicate-envelope originalId return the rounded id too.
SQLite selects in this storage now use CAST(column AS TEXT). Text comes back as the exact decimal digits on every SQLite driver, including drivers that already return bigints. PostgreSQL, MySQL, and SQL Server queries are unchanged.
The worker SQL API has no bigint read, so making @effect/sql-sqlite-do honor SafeIntegers cannot recover these values. Casting at the query keeps the ids exact. The separate request to stop Snowflake.layerGenerator from overriding an outer generator is left out of this change.
Design assessment
Worth accepting: this fixes request/reply identity loss without a public API change. SQLite-only casts at the projection boundary preserve exact decimal IDs while leaving stored INTEGER values, joins, predicates, and numeric ordering unchanged. Casting nullable joined IDs preserves NULL. Other dialect projections remain unchanged.
The first takeover pass only simplifies tests; implementation refactoring and independent review remain separate follow-ups. The repeated projection lists are a candidate for simplification. Generator injection redesign remains out of scope.
Validation
- Replaced the 188-line standalone Durable Object fake test with one regression in the existing
SqlMessageStorage.integration.test.ts, reusing message fixtures and a scoped real SQLite connection. A small connection adapter converts bigint results to numbers to model number-returning drivers without a cross-package Durable Object dependency.
- The regression uses deterministic, non-representable IDs above 2^53 and checks request identity, claiming, completed-request exclusion, reply identity, duplicate identity, and primary-key lookup through public storage APIs.
- Red/green verified: temporarily restoring the pre-fix implementation fails the request ID assertion (9007199254740992 instead of 9007199254740993); the unchanged PR implementation passes.
nix develop -c env EFFECT_INTEGRATION_TESTS=1 pnpm test --run packages/platform/node/test/cluster/SqlMessageStorage.integration.test.ts -t "sqlite|preserves ids above" — 23 passed (22 existing SQLite tests + 1 regression). PostgreSQL/MySQL were not run in this pass.
nix develop -c pnpm lint-fix — passed.
nix develop -c pnpm check — passed.
Closes EFF-2423
Closes #9483