Skip to content

cli: serve's cluster-driver load registers into the CJS registry while the ESM Runtime reads the ESM one — OS_CLUSTER_DRIVER=redis silently downgrades to "not registered" (post-#10645) #13330

Description

@baozhoutao

Symptom

On the objectos-ee image (framework pinned at 502ff8b5), a 3-replica boot with OS_CLUSTER_DRIVER=redis + OS_REDIS_URL dies at kernel init:

✗ Cluster driver "redis" is not registered. Did you forget to import @objectstack/service-cluster-redis or call registerClusterDriver()? See content/docs/kernel/cluster.mdx §6.

@objectstack/service-cluster-redis IS declared by the app and IS resolvable — a bare import('@objectstack/service-cluster-redis') from the app root succeeds. #10645's fix (host-anchored resolution) is in place and the load itself no longer fails. Something else eats the registration.

Root cause — module-instance split at the importFromHost seam

serve.ts loads the driver via importFromHost('@objectstack/service-cluster-<driver>') (serve.ts:1919). For a declared package, createHostImporter (packages/types/src/node.ts) resolves it with hostRequire.resolve(pkg) — a CommonJS resolution that returns the package's main, i.e. dist/index.cjs — then does import(pathToFileURL(resolved).href).

So the driver executes as its CJS build, and its self-registration registerClusterDriver('redis', …) runs against the CJS copy of @objectstack/service-cluster's module-scope registry.

Meanwhile packages/cli is "type": "module": servenew Runtime(...)@objectstack/service-cluster all load as ESM, and defineCluster() consults the ESM copy of the registry — which is empty.

Measured inside the running image (same process, both instances probed):

ESM instance: redis REGISTERED       ← after a bare import('@objectstack/service-cluster-redis')
CJS instance: NOT registered: Cluster driver "redis" is not registered…

The silent catch { /* may already be registered by the loaded config */ } around the serve-side load (serve.ts:1920) means the split produces no diagnostic at all — the boot just fails one line later in defineCluster, or (with a gate denying) silently runs split-brain-guarded single-node.

Impact

  • OS_CLUSTER_DRIVER=redis cannot activate on any config-boot app whose driver package ships a CJS main (every tsup dual build does). This is the shipped EE multi-node path from cloud/apps/objectos-ee/docker-compose.yml (ADR-0018).
  • The same seam presumably affects any importFromHost-loaded package whose side effect must land in a module-scope registry read by the ESM chain (registerMultiNodeGate from a CJS-evaluated config has the mirror-image problem — the EE licence gate registered from config is invisible to an ESM-side reader, and vice versa).

Repro

  1. Build the EE image at this pin, run cloud/apps/objectos-ee/docker-compose.yml with --scale app=3 (redis driver env preset there).
  2. migrate exits 1 with the "not registered" error above.

Workaround (verified)

Registering from the app config lands in the ESM registry the Runtime actually reads (the config is evaluated as ESM):

// objectstack.config.ts
import '@objectstack/service-cluster-redis';

With this line, the same 3-replica compose boots, the redis driver activates, and cross-node locks (os:lock:* / os:fence:*) appear in redis.

Possible fixes

  • In createHostImporter's declared leg, resolve with ESM semantics (import.meta.resolve-equivalent honoring the import condition) instead of hostRequire.resolve, so the same build of a package is loaded on both sides; or
  • have the driver packages register into a registry that is instance-split-proof (e.g. keyed on globalThis), which also hardens every other module-scope registry against dual-build loading; or
  • at minimum, drop the silent catch: log the load error and, after the load, verify the driver is visible to the registry the Runtime will read, so the split reports itself instead of surfacing as "not registered" one line later.

Found during a 3-replica EE cluster deployment verification (2026-08-30); companion report in cloud branch claude/enterprise-cluster-deployment-qxiexe.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions