Skip to content

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

Closed

Description

@IgnisDa

What version of Effect is running?

effect 4.0.5 and @effect/sql-pg 4.0.5. It regressed from 4.0.0 and 4.0.4. Bun 1.4.3, PostgreSQL 18.

What steps can reproduce the bug?

The setup is one process using ClusterWorkflowEngine.layer over Sharding.layer with Runners.layerNoop, SqlMessageStorage, SqlRunnerStorage and shardLockDisableAdvisory: true, on PostgreSQL.

The workload is an application e2e suite (146 tests) that runs many workflows. Most have long chains of sequential activities, some run child workflows, and some await DurableDeferreds. The same suite was run under each library version, with nothing else changed:

4.0.0 4.0.5 4.0.5 + 4.0.4 dist/cluster/Runners.js 4.0.5 + 4.0.4 dist/cluster/ClusterWorkflowEngine.js
cluster_messages inserts 70,673 133,571 48,695 133,353
— inserts that hit ON CONFLICT (message_id) (re-sent activity requests) 50,913 113,800 — —
cluster_replies inserts 23,891 24,213 — —
client activity sends for the main workflow 37,713 83,846 15,754 83,845
run executions of a child-heavy workflow 142 302 139 302
total SQL statements 670k 1,126k 593k 1,139k

New messages and replies stay flat, so the amount of real work is unchanged. What grows is the number of workflow replays: each replay re-sends every completed activity request, which then lands as an ON CONFLICT duplicate. Swapping only 4.0.4's Runners.js into 4.0.5 brings the counts back down. Swapping only 4.0.4's ClusterWorkflowEngine.js changes nothing.

I could not reproduce it in a small standalone script. I tried in-memory and Postgres storage with sequential activities, a child workflow fan-out, DurableDeferred, DurableClock.sleep, raceAll, and concurrent parents, and 4.0.0 to 4.0.5 looked the same. So it seems to need more concurrent, real-database reply latency than a toy workload produces.

What is the expected behavior?

Replay counts similar to 4.0.4, with locally owned requests answered without a storage round trip.

What do you see instead?

Roughly twice as many workflow replays, and with them twice as many message saves, statements and wall time (the suite takes 433 s on 4.0.0 and 596 s on 4.0.5).

Additional information

The change that matters is in Runners.notifyLocal, from 4.0.4 to 4.0.5. It is probably part of the fix for #9175:

-      return notifyWith(options.message, (message, duplicate) => {
+      return notifyWith(options.message, (message) => {
 ...
-        } else if (!duplicate && options.storageOnly !== true) {
-          return options.notify(Message.incomingLocalFromOutgoing(message)).pipe(
-            Effect.andThen(storage.registerReplyHandler(message)),
-            Effect.catchTag("EntityNotAssignedToRunner", () => replyFromStorage(message))
-          )
+        // The request can be processed as soon as it is saved, so replies are
+        // always read back from storage. ...
+        const readReplies = options.storageOnly
+          ? replyFromStorage(message)
+          : Effect.raceFirst(replyFromStorage(message), storage.registerReplyHandler(...))

In 4.0.4, a new, locally owned request went straight to the local entity, and its reply came back through the reply handler. In 4.0.5, the request is delivered and its replies are read back only through the storage read loop. My guess is that the added latency means activities and wakes get answered after the run has already suspended. Each suspension then costs a full replay, which re-sends every completed activity (saveRequest → Duplicate).

It would help to keep the 4.0.5 fix for the race in #9175 but bring back direct local delivery for requests that are not duplicates. Alternatively, a hint about which wake path to look at would let me narrow it further on my side.

Activity

  1. self-assigned this
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions