mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:40:43 +00:00
fix: use transport activity for stale health
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
|
||||
import { createConnectedChannelStatusPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
||||
import {
|
||||
createConnectedChannelStatusPatch,
|
||||
createTransportActivityStatusPatch,
|
||||
} from "openclaw/plugin-sdk/gateway-runtime";
|
||||
import { formatMatrixErrorMessage } from "../errors.js";
|
||||
import {
|
||||
isMatrixDisconnectedSyncState,
|
||||
@@ -52,12 +55,15 @@ export function createMatrixMonitorStatusController(params: {
|
||||
});
|
||||
};
|
||||
|
||||
const noteConnected = (at = Date.now()) => {
|
||||
const noteConnected = (at = Date.now(), options?: { transportActivity?: boolean }) => {
|
||||
if (status.connected === true) {
|
||||
status.lastEventAt = at;
|
||||
} else {
|
||||
Object.assign(status, createConnectedChannelStatusPatch(at));
|
||||
}
|
||||
if (options?.transportActivity) {
|
||||
Object.assign(status, createTransportActivityStatusPatch(at));
|
||||
}
|
||||
status.lastError = null;
|
||||
status.lastDisconnect = null;
|
||||
status.healthState = "healthy";
|
||||
@@ -83,7 +89,10 @@ export function createMatrixMonitorStatusController(params: {
|
||||
return {
|
||||
noteSyncState(state: MatrixSyncState, error?: unknown, at = Date.now()) {
|
||||
if (isMatrixReadySyncState(state)) {
|
||||
noteConnected(at);
|
||||
// matrix-js-sdk emits SYNCING after each successful /sync response.
|
||||
// PREPARED can be cache-backed and CATCHUP is a lifecycle bridge, so
|
||||
// neither should refresh transport liveness.
|
||||
noteConnected(at, { transportActivity: state === "SYNCING" });
|
||||
return;
|
||||
}
|
||||
if (isMatrixDisconnectedSyncState(state)) {
|
||||
|
||||
@@ -129,6 +129,42 @@ describe("createMatrixMonitorSyncLifecycle", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("only refreshes transport liveness for successful sync responses", async () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-04-10T16:21:00.000Z"));
|
||||
const { client, lifecycle, setStatus } = createSyncLifecycleHarness();
|
||||
try {
|
||||
setStatus.mockClear();
|
||||
|
||||
client.emit("sync.state", "PREPARED", null, undefined);
|
||||
expect(setStatus).toHaveBeenLastCalledWith(
|
||||
expect.not.objectContaining({
|
||||
lastTransportActivityAt: expect.any(Number),
|
||||
}),
|
||||
);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
client.emit("sync.state", "SYNCING", "PREPARED", undefined);
|
||||
const syncAt = Date.now();
|
||||
expect(setStatus).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
lastTransportActivityAt: syncAt,
|
||||
}),
|
||||
);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(3_000);
|
||||
client.emit("sync.state", "CATCHUP", "SYNCING", undefined);
|
||||
expect(setStatus).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
lastTransportActivityAt: syncAt,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
lifecycle.dispose();
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not downgrade a fatal error to stopped during shutdown", async () => {
|
||||
const { client, lifecycle, setStatus, setStopping, statusController } =
|
||||
createSyncLifecycleHarness({
|
||||
|
||||
Reference in New Issue
Block a user