Skip to content

feat(service-cluster): split-brain startup guard for memory driver (ADR-0010 path A)#1841

Merged
xuyushun441-sys merged 1 commit into
mainfrom
feat/cluster-splitbrain-guard
Jun 14, 2026
Merged

feat(service-cluster): split-brain startup guard for memory driver (ADR-0010 path A)#1841
xuyushun441-sys merged 1 commit into
mainfrom
feat/cluster-splitbrain-guard

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

Implements ADR-0010 (D6) path A — the memory-driver split-brain startup guard.

Problem

The memory cluster driver keeps PubSub/Lock/KV/Counter state per process. Across multiple replicas each process holds its own state → ILock grants to every replica (no mutual exclusion), ICounter/IKV versions diverge, IPubSub doesn'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 when OS_EXPECT_MULTI_NODE=true or OS_CLUSTER_REPLICAS>1.
  • assertClusterDriverSafeForTopology(driver, env) — throws when multi-node is declared and the resolved driver is in-process memory, unless OS_ALLOW_MEMORY_CLUSTER_MULTINODE=true.
  • ClusterServicePlugin.init calls it before registering the service, so a misconfig fails fast with an actionable message (points at service-cluster-redis / a DB-backed driver, and cites ADR-0010).

Both helpers are pure and exported for reuse.

Verification

  • vitest run40/40 pass (10 new guard tests + 30 existing).
  • tsup build green (CJS + ESM + DTS).
  • tsc --noEmit: zero errors in the changed files (the one pre-existing error in memory/memory.contract.test.ts is 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

…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>
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 14, 2026 7:12am

Request Review

@xuyushun441-sys
xuyushun441-sys merged commit c89e8b3 into main Jun 14, 2026
12 checks passed
@xuyushun441-sys
xuyushun441-sys deleted the feat/cluster-splitbrain-guard branch June 14, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants