Skip to content

Deliver cluster WithTransaction replies after the transaction outcome is known - #8891

Merged
tim-smart merged 16 commits into
mainfrom
eff-1823-with-transaction-commit-replies
Oct 8, 2026
Merged

tim-smart merged 16 commits into
mainfrom
eff-1823-with-transaction-commit-replies

Conversation

@tim-smart

@tim-smart tim-smart commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #8886. A persisted ClusterSchema.WithTransaction request no longer shows anything to its caller before the transaction outcome is known.

Before this change, the reply-handler layer in MessageStorage.make delivered a success to callers while the transaction was still open, and entityManager marked the request processed inside the transaction. If COMMIT then failed, the caller already had a success and the request stayed unprocessed in storage until a restart. #8886 also sent the held failure reply when ROLLBACK died, with no proof that the database rolled back.

Changes

  • MessageStorage.make.withTransaction collects the caller notifications of WithExit replies saved inside it and runs them once the driver transaction has committed. saveReply still saves inside the transaction; only the notification moves. The context reference that carries the pending notifications is private to MessageStorage.ts. Chunks are always delivered immediately. The public MessageStorage signatures are unchanged.
  • entityManager has no notion of a reply hold. For a persisted WithTransaction request it records one settle step and runs it with the transaction's exit: committed → bookkeeping (storage already notified the caller); clean rollback after a handler failure → save and deliver the failure, as in Persist cluster WithTransaction failure replies after rollback #8886; COMMIT or ROLLBACK died, detected as the wrapper's cause not equalling the handler's → rebuild and replay through restartFrom, shared with Defect.
  • Restart and uninterruptible re-write forks run with the entity's handler context instead of inheriting the dying handler fiber's context. Previously a replay inherited whatever was in scope at the failure, including the open transaction's state; the fatal-defect-then-typed-failure regression fails without this.
  • Non-persisted WithTransaction requests use the bare storage transaction, as before Persist cluster WithTransaction failure replies after rollback #8886. Their replies are not saved, so there is nothing to wait for.
  • Docs on ClusterSchema.WithTransaction and MessageStorage.withTransaction state the invariant and its three exclusions: stream chunks, handlers that return a Deferred, and non-persisted requests.
  • effect patch changeset.

The rollback test storage now wraps the memory driver's transaction via MessageStorage.makeEncoded, which is where a real COMMIT or ROLLBACK fails, rather than wrapping the public service above the reply layer. The #8886 rollback test uses the same helper.

Out of scope, as planned in the parent issue: BEGIN failure, retries inside an aborted transaction, and real-database integration coverage.

Validation

  • packages/effect/test/cluster/Sharding.test.ts: 81/81 pass, including the four regression tests and the existing propagation, rollback-failure reply and caller-bound ordering tests
  • packages/effect/test/cluster and packages/effect/test/rpc: 18 files, 295/295 pass
  • packages/platform/node test/cluster/SocketRunner.test.ts and test/RpcServer.test.ts: 109/109 pass. The Docker-backed integration suites gated on EFFECT_CLUSTER_TESTS=1 were not run.
  • pnpm lint, pnpm check and pnpm jsdocs --check pass

Closes EFF-1823
Closes EFF-1835
Closes EFF-1836

…ion outcome

Red regression tests for EFF-1823; the implementation follows on this branch.
…utcome is known

Hold the caller delivery of a persisted request's WithExit reply until
COMMIT, defer processed/active bookkeeping until the transaction exits, and
replay the request when COMMIT or ROLLBACK fails instead of sending a reply.
@changeset-bot

changeset-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 456aae6

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
…defect replay

A fatal defect inside the transaction forks the restart with the request's
HeldReply in context, so the replayed attempt's post-rollback failure reply is
held in a stale holder and never reaches the caller. Red until the fix lands.
…r attempts

A holder closes when its transaction exits, so replies saved later (a
post-rollback failure, a late Deferred reply) are delivered immediately.
Restarts and uninterruptible re-writes no longer fork with the current
transaction's hold, so replayed handlers never start with a stale one.
@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%)

The reply hold is now provided to storage only around the single saveReply
call the entity manager makes inside the transaction, so no handler, replay
or Deferred fiber can inherit it. Settlement is one step keyed on the
transaction outcome, and wrapper-only COMMIT/ROLLBACK failures are detected
with Cause equality.
…ansaction

MessageStorage.make.withTransaction now collects the caller notifications of
WithExit replies saved inside it and runs them after the driver transaction
commits, so the entity manager no longer carries a reply hold. The entity
manager only records how a persisted reply settles once the transaction
outcome is known, and restart and re-write forks leave the dying handler's
context behind instead of inheriting it. The rollback test storage wraps the
memory driver's transaction, where COMMIT and ROLLBACK actually run.
…ctions

Reply handlers must learn of a WithExit reply saved in a nested
MessageStorage transaction only when the outermost transaction commits, and
not at all when the outer transaction fails or the inner one rolls back.
…t was reported as failed

A persisted WithTransaction request must not be replayed once its COMMIT has
applied, whether the wrapper then reports an interrupt or a failure. With a
driver that rejects a second WithExit reply, like the SQL tables do, the
replay's save fails and the entity restarts again.
…s misreported

Mask interrupts around the request transaction, restoring them only for the
handler, so an interrupt during COMMIT no longer hides a committed outcome.
When a successful handler's transaction still reports a failure, check storage
for its terminal reply before replaying: if it exists the COMMIT applied, so
complete the request and release callers to read the stored reply.
@tim-smart
tim-smart merged commit 9753be9 into main Oct 8, 2026
13 checks passed
@tim-smart
tim-smart deleted the eff-1823-with-transaction-commit-replies branch October 8, 2026 02:20
@effect-bot effect-bot mentioned this pull request Oct 8, 2026
@callajd callajd mentioned this pull request Oct 15, 2026
2 of 5 tasks
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.

1 participant