Skip to content

Fix cluster shutdown waiting on queued persisted workflow activities - #9817

Merged
tim-smart merged 10 commits into
mainfrom
agent/effect-bot/c716c5b9c926
Oct 23, 2026
Merged

tim-smart merged 10 commits into
mainfrom
agent/effect-bot/c716c5b9c926

Conversation

@effect-bot

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

Copy link
Copy Markdown
Contributor

Summary

During cluster shutdown, a workflow could hold the entity drain until entityTerminationTimeout when its run handler was waiting on a persisted activity request that had been saved but not started.

The run handler is uninterruptible. It waits on the local reply handler for the activity, so the entity's RpcServer never sends ClientEnd, and the drain waits on endLatch until the timeout. The only shutdown step that released that waiter (unregisterShardReplyHandlers(shardId, { interrupt: true })) runs after the drain finishes, so the two waited on each other.

Changes

  • Once a retiring entity has issued its termination interrupts, and before it writes Eof, the entity manager calls a new internal abandonUndelivered hook. Only during runner shutdown, Sharding abandons local callers parked on persisted requests to that address that the entity never started. This uses the same ClusterAbandon interrupt that sendOutgoing already uses for new sends that cannot be served. Callers on a runner that keeps running, for example when only the target entity type's registration closes, are not touched and stay durable. The hook runs before Eof so it is not skipped when the drain's end latch is already open, for example after a handler crash.
  • If a persisted request's exit carries a cluster abandonment and its entity is retired or no longer owned, that exit is neither answered nor retried on this owner. The request stays in storage and replays under the next owner. This also covers ordinary persisted handlers, not only Uninterruptible ones.
  • Requests the entity has already started keep their waiters, so running activities still complete within the grace period before the drain finishes.
  • MessageStorage.unregisterReplyHandler accepts an optional { interrupt?: boolean }, matching unregisterShardReplyHandlers.

Known limitation

With preemptiveShutdown: false, entities drain before the runner is marked as shutting down, so the hook does not run. A workflow waiting on a queued persisted activity therefore still holds shutdown until entityTerminationTimeout, as before this PR. New persisted sends made while the target entity type is closing have the same pre-existing gap. The default configuration (preemptiveShutdown: true) is fixed.

Tests

  • ClusterWorkflowEngine.test.ts:
    • Shutdown with a queued activity completes within the grace period. After a restart, the workflow completes with the activity executed once.
    • Shutdown waits for a running activity, then finalizes the workflow scope, with the activity executed once.
  • Sharding.test.ts:
    • An ordinary durable caller abandoned on its own queued child request replays after a restart: its continuation runs and it succeeds.
    • A persisted request admitted while replacement handlers are still being acquired: shutdown completes within the grace period while acquisition stays blocked, the caller is abandoned, and after a restart the request runs once.
  • Sharding.test.ts: an ordinary durable caller survives when only its target's registration closes (preemptiveShutdown: false) and replays after a restart.
  • The existing cluster, workflow and rpc suites pass. The SQL and cluster-integration suites, which need containers, were not run.

Closes #9816
Closes EFF-2835

@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 76d1894

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

@github-actions

github-actions Bot commented Oct 23, 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 39.24 KB 39.24 KB 0.00 KB (0.00%)
basic.ts 7.15 KB 7.15 KB 0.00 KB (0.00%)
batching.ts 11.03 KB 11.03 KB 0.00 KB (0.00%)
brand.ts 6.83 KB 6.83 KB 0.00 KB (0.00%)
cache.ts 11.46 KB 11.46 KB 0.00 KB (0.00%)
config.ts 22.66 KB 22.66 KB 0.00 KB (0.00%)
differ.ts 21.80 KB 21.80 KB 0.00 KB (0.00%)
http-client.ts 26.20 KB 26.20 KB 0.00 KB (0.00%)
http-router.ts 36.24 KB 36.24 KB 0.00 KB (0.00%)
logger.ts 11.84 KB 11.84 KB 0.00 KB (0.00%)
metric.ts 9.38 KB 9.38 KB 0.00 KB (0.00%)
optic.ts 7.04 KB 7.04 KB 0.00 KB (0.00%)
pubsub.ts 15.91 KB 15.91 KB 0.00 KB (0.00%)
queue.ts 12.70 KB 12.70 KB 0.00 KB (0.00%)
schedule.ts 11.71 KB 11.71 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.95 KB 13.95 KB 0.00 KB (0.00%)
schema-binary.ts 40.85 KB 40.85 KB 0.00 KB (0.00%)
schema-class.ts 21.45 KB 21.45 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.51 KB 32.51 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.69 KB 27.69 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.20 KB 15.20 KB 0.00 KB (0.00%)
schema-string.ts 12.20 KB 12.20 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.14 KB 16.14 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.76 KB 38.76 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.85 KB 25.85 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.73 KB 20.73 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.88 KB 20.88 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.98 KB 20.98 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.61 KB 25.61 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.97 KB 20.97 KB 0.00 KB (0.00%)
schema.ts 20.65 KB 20.65 KB 0.00 KB (0.00%)
stm.ts 14.04 KB 14.04 KB 0.00 KB (0.00%)
stream.ts 10.26 KB 10.26 KB 0.00 KB (0.00%)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cluster workflow: shutdown with a queued Persisted activity waits for the full entityTerminationTimeout

2 participants