Skip to content

Commit 53f146e

Browse files
xuyushun441-sysos-zhuangclaude
authored
feat(cli): forward env-driven cluster driver to the runtime in os serve (#2226)
`os serve` constructed the Runtime without a cluster config, so it always used the in-memory cluster driver — a multi-replica deployment could not coordinate (and the split-brain guard blocked it). `os serve` now reads OS_CLUSTER_DRIVER (+ OS_REDIS_URL), dynamically imports the matching remote driver package (so it works in both config-boot and compiled-artifact mode), and forwards the cluster config to the Runtime. Open-core ships only the in-memory driver; remote drivers (e.g. @objectstack/service-cluster-redis) are provided by the EE distribution — absent ⇒ graceful fallback to in-memory. Verified via A/B boot (local redis): with OS_CLUSTER_DRIVER=redis + replicas=2 the server boots (guard passes = redis active); without it, replicas=2 trips the split-brain guard (memory). Enables the EE multi-node activation (cloud ADR-0018) of the cache-invalidation (#2213) and scheduler-leader-election (#2219) seams. Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 99bc2ad commit 53f146e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/cli/src/commands/serve.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,23 @@ export default class Serve extends Command {
531531
}),
532532
};
533533

534+
// Cluster wiring: env-driven driver selection (mirrors OS_DATABASE_URL).
535+
// The remote driver self-registers on import; import it dynamically so it
536+
// works in BOTH config-boot and compiled-artifact mode. Open-core ships
537+
// only the in-memory driver — remote drivers (e.g. redis) come from the EE
538+
// distribution; if absent we fall back to the in-memory cluster.
539+
let clusterConfig: { driver: string; url?: string } | undefined;
540+
const __clusterDriver = process.env.OS_CLUSTER_DRIVER?.trim();
541+
if (__clusterDriver && __clusterDriver !== 'memory') {
542+
try { await import(`@objectstack/service-cluster-${__clusterDriver}`); }
543+
catch { /* may already be registered by the loaded config */ }
544+
clusterConfig = { driver: __clusterDriver, url: process.env.OS_REDIS_URL };
545+
}
534546
const runtime = new Runtime({
535547
kernel: {
536548
logger: loggerConfig
537-
}
549+
},
550+
cluster: clusterConfig as any,
538551
});
539552
const kernel = runtime.getKernel();
540553

0 commit comments

Comments
 (0)