feat(service-cluster): split-brain startup guard for memory driver (ADR-0010 path A)#1841
Merged
Merged
Conversation
…DR-0010 path A) The memory cluster driver keeps PubSub/Lock/KV/Counter state per-process. Across multiple replicas each process holds its own state → locks grant to everyone, counters/KV versions diverge, pub/sub doesn't fan out. This fails silently: single-node tests/dev pass, only production multi-replica corrupts. Add a conservative startup guard (ADR-0010 path A): when a multi-node topology is *declared* (OS_EXPECT_MULTI_NODE=true or OS_CLUSTER_REPLICAS>1) but the resolved driver is in-process "memory", ClusterServicePlugin throws at init (before registering the service) with an actionable message. Escape hatch OS_ALLOW_MEMORY_CLUSTER_MULTINODE=true for the rare "replicas declared but cluster primitives unused cross-node" case. Pure, unit-tested decision (declaresMultiNode / assertClusterDriverSafeForTopology), exported for reuse. Path B (active DB-presence detection) is deferred per ADR-0010. Refs: cloud ADR-0010 (D6). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements ADR-0010 (D6) path A — the memory-driver split-brain startup guard.
Problem
The
memorycluster driver keeps PubSub/Lock/KV/Counter state per process. Across multiple replicas each process holds its own state →ILockgrants to every replica (no mutual exclusion),ICounter/IKVversions diverge,IPubSubdoesn't fan out. It fails silently: single-node tests and dev pass; only production multi-replica corrupts.Change
A conservative, declaration-based guard (no active peer discovery — that's the optional path B, deferred):
declaresMultiNode(env)— true whenOS_EXPECT_MULTI_NODE=trueorOS_CLUSTER_REPLICAS>1.assertClusterDriverSafeForTopology(driver, env)— throws when multi-node is declared and the resolved driver is in-processmemory, unlessOS_ALLOW_MEMORY_CLUSTER_MULTINODE=true.ClusterServicePlugin.initcalls it before registering the service, so a misconfig fails fast with an actionable message (points atservice-cluster-redis/ a DB-backed driver, and cites ADR-0010).Both helpers are pure and exported for reuse.
Verification
vitest run— 40/40 pass (10 new guard tests + 30 existing).tsupbuild green (CJS + ESM + DTS).tsc --noEmit: zero errors in the changed files (the one pre-existing error inmemory/memory.contract.test.tsis untouched by this PR).Scope
4 files:
split-brain-guard.ts(new),split-brain-guard.test.ts(new),cluster-service-plugin.ts(call guard),index.ts(export). No behavior change for single-node or remote-driver deployments.Refs: cloud ADR-0010.
🤖 Generated with Claude Code