mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-13 02:01:16 +00:00
fix(matrix): ignore shutdown sync-state noise
This commit is contained in:
@@ -114,6 +114,36 @@ describe("createMatrixMonitorSyncLifecycle", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("ignores non-terminal sync states emitted during intentional shutdown", async () => {
|
||||
const client = createClientEmitter();
|
||||
const setStatus = vi.fn();
|
||||
let stopping = false;
|
||||
const statusController = createMatrixMonitorStatusController({
|
||||
accountId: "default",
|
||||
statusSink: setStatus,
|
||||
});
|
||||
const lifecycle = createMatrixMonitorSyncLifecycle({
|
||||
client: client as never,
|
||||
statusController,
|
||||
isStopping: () => stopping,
|
||||
});
|
||||
|
||||
const waitPromise = lifecycle.waitForFatalStop();
|
||||
stopping = true;
|
||||
client.emit("sync.state", "ERROR", "RECONNECTING", new Error("shutdown noise"));
|
||||
lifecycle.dispose();
|
||||
statusController.markStopped();
|
||||
|
||||
await expect(waitPromise).resolves.toBeUndefined();
|
||||
expect(setStatus).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
accountId: "default",
|
||||
healthState: "stopped",
|
||||
lastError: null,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not downgrade a fatal error to stopped during shutdown", async () => {
|
||||
const client = createClientEmitter();
|
||||
const setStatus = vi.fn();
|
||||
|
||||
@@ -47,6 +47,12 @@ export function createMatrixMonitorSyncLifecycle(params: {
|
||||
if (fatalError) {
|
||||
return;
|
||||
}
|
||||
// Operator-initiated shutdown can still emit transient sync states before
|
||||
// the final STOPPED. Ignore that churn so intentional stops do not look
|
||||
// like runtime failures.
|
||||
if (params.isStopping?.() && !isMatrixTerminalSyncState(state)) {
|
||||
return;
|
||||
}
|
||||
params.statusController.noteSyncState(state, error);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user