fix(cluster): skip persistence scheduling until initialize has run

schedulePersist and scheduleControlPersist can fire from configure() and
the public scheduling paths before initialize() has completed. Without a
guard, those queued microtasks call persistState/persistControlState,
which try to mkdir PATHS.DATA_DIR and write state files from tests and
short-lived scripts that never meant to touch the data directory. That
produced async-leak warnings in the Cluster manager unit tests and
left orphan directories on hosts that only constructed a ClusterManager
to inspect it.

Add an `initialized` flag set at the end of initialize() and early-return
from both schedulers when it is false. Real runtime paths always call
initialize() during Daemon startup, so this changes no production
behavior.
This commit is contained in:
2026-04-21 12:39:50 +00:00
parent 952bf394d3
commit 9f7308498c
+11
View File
@@ -13,6 +13,7 @@ import type {
import { CLUSTER, PATHS } from '../constants.ts';
export class ClusterManager {
private initialized = false;
private config: IClusterConfig = {
enabled: false,
nodeName: 'modelgrid-local',
@@ -63,6 +64,8 @@ export class ClusterManager {
} catch {
// No persisted control state yet.
}
this.initialized = true;
}
public configure(config: IClusterConfig): void {
@@ -384,6 +387,10 @@ export class ClusterManager {
}
private schedulePersist(): void {
if (!this.initialized) {
return;
}
if (this.persistQueued) {
return;
}
@@ -396,6 +403,10 @@ export class ClusterManager {
}
private scheduleControlPersist(): void {
if (!this.initialized) {
return;
}
if (this.controlPersistQueued) {
return;
}