Skip to content

Persist cluster WithTransaction failure replies after rollback - #8886

Merged
tim-smart merged 8 commits into
mainfrom
agent/effect-bot-architect/531b23645e2d
Oct 7, 2026
Merged

tim-smart merged 8 commits into
mainfrom
agent/effect-bot-architect/531b23645e2d

Conversation

@effect-bot

@effect-bot effect-bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Persisted entity RPCs annotated with ClusterSchema.WithTransaction lost their failure reply. RpcServer.handleRequest wrote the reply in an Effect.onExit and then wrapped that with onRequest, which the entity manager sets to storage.withTransaction. A failing handler rolled back its own reply and processed flag. The first caller still got the error in memory, but retries, deduplicated callers and other runners waited for a reply that was never committed, and restarts reran the handler.

Change

The fix is in the entity manager, and RpcServer is unchanged. While a WithTransaction request's transaction is open, the entity manager holds back a failure Exit reply and saves it once withTransaction has exited, after the rollback. Success replies are still saved inside the transaction, so they commit atomically with the handler's writes. Requests without a transaction, including caller-bound requests from other runners, keep their existing reply ordering.

Resulting semantics for WithTransaction entities:

Handler outcome Handler writes Reply
Success committed with the reply persisted
Typed failure rolled back persisted after rollback
Defect, disableFatalDefects rolled back Die exit persisted after rollback
Fatal defect (default) rolled back none, entity restarts and retries (unchanged)
Shutdown interrupt rolled back none, request redelivered (unchanged)

Tests

  • Sharding.test.ts, "WithTransaction persists a failure reply after rollback": memory storage is wrapped so that replies saved inside a failed transaction are cleared, the way a SQL rollback would discard them. A typed failure is retried with the same primary key and must return the stored failure without rerunning the handler. It times out without the fix.

Not covered: a caller interrupting an in-flight transactional handler. On SQLite's single connection, the open transaction holds the connection, so the Interrupt envelope can't be saved. That deadlock predates this PR and would need a pooled-database integration test.

Closes #8883
Closes EFF-1820

…plies

Regression coverage for persisted entity RPCs annotated with
ClusterSchema.WithTransaction (#8883). Typed failures and non-fatal
defects currently lose their persisted reply when the handler
transaction rolls back; these cases fail until the fix lands.
RpcServer now sends failure responses after the onRequest wrapper exits,
so a transaction it rolls back no longer discards the persisted reply.
Success responses stay inside onRequest to keep them atomic with the
handler's writes.

Closes #8883
@changeset-bot

changeset-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e56fa7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 32 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added bug Something isn't working 4.0 labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 38.79 KB 38.79 KB 0.00 KB (0.00%)
basic.ts 7.06 KB 7.06 KB 0.00 KB (0.00%)
batching.ts 10.14 KB 10.14 KB 0.00 KB (0.00%)
brand.ts 6.73 KB 6.73 KB 0.00 KB (0.00%)
cache.ts 10.89 KB 10.89 KB 0.00 KB (0.00%)
config.ts 22.25 KB 22.25 KB 0.00 KB (0.00%)
differ.ts 21.34 KB 21.34 KB 0.00 KB (0.00%)
http-client.ts 22.67 KB 22.67 KB 0.00 KB (0.00%)
http-router.ts 34.05 KB 34.05 KB 0.00 KB (0.00%)
logger.ts 11.22 KB 11.22 KB 0.00 KB (0.00%)
metric.ts 9.03 KB 9.03 KB 0.00 KB (0.00%)
optic.ts 6.96 KB 6.96 KB 0.00 KB (0.00%)
pubsub.ts 15.18 KB 15.18 KB 0.00 KB (0.00%)
queue.ts 12.13 KB 12.13 KB 0.00 KB (0.00%)
schedule.ts 11.22 KB 11.22 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.74 KB 13.74 KB 0.00 KB (0.00%)
schema-binary.ts 40.00 KB 40.00 KB 0.00 KB (0.00%)
schema-class.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.10 KB 32.10 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.28 KB 27.28 KB 0.00 KB (0.00%)
schema-string-transformation.ts 14.48 KB 14.48 KB 0.00 KB (0.00%)
schema-string.ts 12.00 KB 12.00 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.07 KB 16.07 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.32 KB 38.32 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.30 KB 25.30 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.26 KB 20.26 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.45 KB 20.45 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.57 KB 20.57 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.03 KB 25.03 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.55 KB 20.55 KB 0.00 KB (0.00%)
schema.ts 20.29 KB 20.29 KB 0.00 KB (0.00%)
stm.ts 13.24 KB 13.24 KB 0.00 KB (0.00%)
stream.ts 9.99 KB 9.99 KB 0.00 KB (0.00%)

tim-smart and others added 6 commits October 7, 2026 18:57
Replace the platform-node SQLite suite with one Sharding test that
simulates a rollback in memory storage and checks a retry receives the
persisted failure without rerunning the handler.
Non-transactional requests bound to a remote caller must receive their
failure reply before request-scope finalizers run, as on main. Fails on
the current PR head, which defers failure replies for any onRequest.
…ager

Move the failure-reply deferral from RpcServer's generic onRequest hook
into the entity manager, which knows the request is transactional.
RpcServer is back to main, so caller-bound requests without a
transaction reply before their finalizers run again.
@tim-smart
tim-smart enabled auto-merge (squash) October 7, 2026 20:58
@tim-smart
tim-smart merged commit 977096b into main Oct 7, 2026
13 checks passed
@tim-smart
tim-smart deleted the agent/effect-bot-architect/531b23645e2d branch October 7, 2026 21:04
@effect-bot effect-bot mentioned this pull request Oct 7, 2026
@bweis

bweis commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cluster: WithTransaction rolls back the reply of a failed entity handler, leaving the request unprocessed

3 participants