Skip to content

Answer fresh local cluster requests without a storage readback - #9336

Merged
tim-smart merged 12 commits into
mainfrom
agent/architect-effect-bot/1d3e961eba3c
Oct 16, 2026
Merged

tim-smart merged 12 commits into
mainfrom
agent/architect-effect-bot/1d3e961eba3c

Conversation

@effect-bot

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

Copy link
Copy Markdown
Contributor

In 4.0.5, Runners.notifyLocal started reading every local reply back from storage, as part of the fix for lost replies in #9175. That added a SQL round trip to every reply of a locally owned request. This PR brings back direct local delivery for fresh requests and keeps the #9175 fix.

Change

For a persisted, non-stream request that isn't discarded and whose entity is on a local shard:

  • The reply handler is registered before saveRequest. The request can be processed as soon as it is saved, so registering first closes the cluster: a local persisted request can wait forever when its reply is saved before registerReplyHandler (Runners.notifyLocal) #9175 race: no reply can be saved before the handler exists. A fresh request gets its reply from the handler, with no storage read and no polling.
  • This relies on registerReplyHandler registering as soon as its effect starts. Every storage built with MessageStorage.make already does, and ClusterWorkflowEngine.awaitRunReply and RunnerServer already depend on it. The contract is now documented on MessageStorage.registerReplyHandler. A storage wrapper that suspends before registering, like the one in the cluster: a local persisted request can wait forever when its reply is saved before registerReplyHandler (Runners.notifyLocal) #9175 reproduction, is not supported.
  • A duplicate request interrupts the pre-registered handler and keeps the 4.0.5 path: replies are read from storage under the original request id, and a local handler wakes the storage loop. A waiter that joins a request already waiting on storage reads immediately, so a reply committed without a notification doesn't wait for the next poll.
  • If the handler is dropped (EntityNotAssignedToRunner, for example when a shard moves or a commit error hides the notification), the request reads storage straight away. 4.0.4 did this; 4.0.5 waited for entityReplyPollInterval. A shutdown abandon interrupt still propagates to the caller.

Stream requests and requests for entities on other runners stay on the storage loop, so chunk ordering and acks don't change. Terminal replies still notify at the outer commit (TransactionNotifications), so the commit boundary holds.

Tests

The new tests in packages/effect/test/cluster/Runners.test.ts:

  • a fresh local reply is delivered without a storage readback: fails on 4.0.5;
  • a parked fresh local request is never read from storage across poll intervals: fails on 4.0.5;
  • storage fallback after the handler is dropped: fails on 4.0.5;
  • a storage-only waiter joining a parked request reads storage immediately: fails on 4.0.5.

The two #9175 tests still pass, including the reply saved before saveRequest returns; both fail with the 4.0.4 Runners.ts.

The cluster, workflow and platform-node suites pass (744 tests; the cluster suite passed 3 more repeated runs), pnpm check is clean, and lint is clean on the changed files.

On a Postgres workload (30 concurrent parent workflows with activity chains, children and externally completed deferreds), a prototype of this handler-first path issued 2 repliesFor queries, against about 430 to 530 on 4.0.5. Parent runs were 84, against 85 to 88 with the 4.0.4 Runners.ts. I haven't re-measured the final commit.

Replay amplification is not confirmed

I could not reproduce the doubled workflow replays from #9335. In-memory runs with injected reply latency, and Postgres runs, showed the same or slightly fewer replays on 4.0.5 than on 4.0.4. This PR removes the per-reply storage round trip for local requests, which the issue identifies as the change that matters. Whether that also brings the reporter's replay counts back down still needs confirming on their workload.

Closes #9335
Closes EFF-2308

@changeset-bot

changeset-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e1a1da3

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

This PR includes changesets to release 33 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/graphql-generator 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 the 4.0 label Oct 16, 2026
@github-actions

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.99 KB 38.99 KB 0.00 KB (0.00%)
basic.ts 7.02 KB 7.02 KB 0.00 KB (0.00%)
batching.ts 10.73 KB 10.73 KB 0.00 KB (0.00%)
brand.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
cache.ts 11.26 KB 11.26 KB 0.00 KB (0.00%)
config.ts 22.41 KB 22.41 KB 0.00 KB (0.00%)
differ.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
http-client.ts 23.93 KB 23.93 KB 0.00 KB (0.00%)
http-router.ts 35.48 KB 35.48 KB 0.00 KB (0.00%)
logger.ts 11.60 KB 11.60 KB 0.00 KB (0.00%)
metric.ts 9.08 KB 9.08 KB 0.00 KB (0.00%)
optic.ts 6.93 KB 6.93 KB 0.00 KB (0.00%)
pubsub.ts 15.68 KB 15.68 KB 0.00 KB (0.00%)
queue.ts 12.52 KB 12.52 KB 0.00 KB (0.00%)
schedule.ts 11.73 KB 11.73 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.76 KB 13.76 KB 0.00 KB (0.00%)
schema-binary.ts 40.46 KB 40.46 KB 0.00 KB (0.00%)
schema-class.ts 21.20 KB 21.20 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.24 KB 32.24 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.41 KB 27.41 KB 0.00 KB (0.00%)
schema-string-transformation.ts 14.93 KB 14.93 KB 0.00 KB (0.00%)
schema-string.ts 12.02 KB 12.02 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.19 KB 16.19 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.51 KB 38.51 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.53 KB 25.53 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.45 KB 20.45 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.65 KB 20.65 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.75 KB 20.75 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.38 KB 25.38 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.74 KB 20.74 KB 0.00 KB (0.00%)
schema.ts 20.39 KB 20.39 KB 0.00 KB (0.00%)
stm.ts 13.79 KB 13.79 KB 0.00 KB (0.00%)
stream.ts 10.05 KB 10.05 KB 0.00 KB (0.00%)

tim-smart and others added 4 commits October 16, 2026 10:39
Register a storage waiter with the reply loop from `replyFromStorage`
instead of the pump's first pass. The entry no longer carries a mutable
`readNow` flag, `readStorageRequest` goes away, and a waiter that joins
an entry is in its message set before any immediate read runs, so it
receives the reply as well.

A dropped reply handler is now observed with `Fiber.join`, so a handler
interrupted during shutdown propagates the abandon interrupt to the
caller as the storage-read path already did.
Comment thread packages/effect/src/cluster/Runners.ts Outdated
message: Message.OutgoingRequest<any>,
notifyEntity: (message: Message.Outgoing<any>) => Effect.Effect<void>
) =>
Effect.gen(function*() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Effect.fnUntraced

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cluster: 4.0.5 Runners.notifyLocal reads every local reply from storage and roughly doubles workflow replays

2 participants