Feat/upgrade openclaw (#729)
This commit is contained in:
committed by
GitHub
Unverified
parent
bf5b089158
commit
d34a88e629
@@ -10,6 +10,7 @@ import type { GatewayStatus } from '../types/gateway';
|
||||
|
||||
let gatewayInitPromise: Promise<void> | null = null;
|
||||
let gatewayEventUnsubscribers: Array<() => void> | null = null;
|
||||
let gatewayReconcileTimer: ReturnType<typeof setInterval> | null = null;
|
||||
const gatewayEventDedupe = new Map<string, number>();
|
||||
const GATEWAY_EVENT_DEDUPE_TTL_MS = 30_000;
|
||||
const LOAD_SESSIONS_MIN_INTERVAL_MS = 1_200;
|
||||
@@ -283,6 +284,45 @@ export const useGatewayStore = create<GatewayState>((set, get) => ({
|
||||
},
|
||||
));
|
||||
gatewayEventUnsubscribers = unsubscribers;
|
||||
|
||||
// Periodic reconciliation safety net: every 30 seconds, check if the
|
||||
// renderer's view of gateway state has drifted from main process truth.
|
||||
// This catches any future one-off IPC delivery failures without adding
|
||||
// a constant polling load (single lightweight IPC invoke per interval).
|
||||
// Clear any previous timer first to avoid leaks during HMR reloads.
|
||||
if (gatewayReconcileTimer !== null) {
|
||||
clearInterval(gatewayReconcileTimer);
|
||||
}
|
||||
gatewayReconcileTimer = setInterval(() => {
|
||||
const ipc = window.electron?.ipcRenderer;
|
||||
if (!ipc) return;
|
||||
ipc.invoke('gateway:status')
|
||||
.then((result: unknown) => {
|
||||
const latest = result as GatewayStatus;
|
||||
const current = get().status;
|
||||
if (latest.state !== current.state) {
|
||||
console.info(
|
||||
`[gateway-store] reconciled stale state: ${current.state} → ${latest.state}`,
|
||||
);
|
||||
set({ status: latest });
|
||||
}
|
||||
})
|
||||
.catch(() => { /* ignore */ });
|
||||
}, 30_000);
|
||||
}
|
||||
|
||||
// Re-fetch status after IPC listeners are registered to close the race
|
||||
// window: if the gateway transitioned (e.g. starting → running) between
|
||||
// the initial fetch and the IPC listener setup, that event was lost.
|
||||
// A second fetch guarantees we pick up the latest state.
|
||||
try {
|
||||
const refreshed = await hostApiFetch<GatewayStatus>('/api/gateway/status');
|
||||
const current = get().status;
|
||||
if (refreshed.state !== current.state) {
|
||||
set({ status: refreshed });
|
||||
}
|
||||
} catch {
|
||||
// Best-effort; the IPC listener will eventually reconcile.
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize Gateway:', error);
|
||||
|
||||
Reference in New Issue
Block a user