mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(gateway): refresh health after account removal (#122620)
This commit is contained in:
committed by
GitHub
parent
beb576c2ad
commit
bdc595d1bd
@@ -33,17 +33,6 @@ function shouldScheduleRequestRefresh(
|
||||
return true;
|
||||
}
|
||||
|
||||
function cachedAccountForRuntimeSnapshot(params: {
|
||||
cachedChannel: ChannelHealthSummary | undefined;
|
||||
accountId: string | undefined;
|
||||
}): ChannelHealthSummary | undefined {
|
||||
const accountId = params.accountId;
|
||||
if (accountId && params.cachedChannel?.accounts?.[accountId]) {
|
||||
return params.cachedChannel.accounts[accountId];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function cachedLifecycleDiffersFromRuntime(params: {
|
||||
cachedAccount: ChannelHealthSummary | undefined;
|
||||
runtimeSnapshot: ChannelAccountSnapshot;
|
||||
@@ -82,16 +71,19 @@ function cachedHealthDiffersFromRuntime(
|
||||
continue;
|
||||
}
|
||||
const cachedChannel = cached.channels[channelId];
|
||||
const cachedAccounts = cachedChannel?.accounts;
|
||||
if (
|
||||
Object.keys(cachedAccounts ?? {}).some((accountId) => !Object.hasOwn(accounts, accountId))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
for (const [accountId, runtimeSnapshot] of Object.entries(accounts)) {
|
||||
if (!runtimeSnapshot) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
cachedLifecycleDiffersFromRuntime({
|
||||
cachedAccount: cachedAccountForRuntimeSnapshot({
|
||||
cachedChannel,
|
||||
accountId,
|
||||
}),
|
||||
cachedAccount: cachedAccounts?.[accountId],
|
||||
runtimeSnapshot,
|
||||
})
|
||||
) {
|
||||
|
||||
@@ -4839,6 +4839,43 @@ describe("gateway healthHandlers.health cache freshness", () => {
|
||||
});
|
||||
expect(respond).toHaveBeenCalledWith(true, fresh, undefined);
|
||||
});
|
||||
|
||||
it("refreshes cached health after hot reload removes a runtime account", async () => {
|
||||
const current = createSingleChannelHealthSnapshot({
|
||||
channelId: "discord",
|
||||
label: "Discord",
|
||||
running: true,
|
||||
connected: true,
|
||||
});
|
||||
const cached = {
|
||||
...current,
|
||||
channels: {
|
||||
discord: {
|
||||
...current.channels.discord,
|
||||
accounts: {
|
||||
...current.channels.discord.accounts,
|
||||
work: channelHealthAccount({ accountId: "work", running: true, connected: true }),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const { respond, refreshHealthSnapshot } = await requestHealthSnapshot({
|
||||
cached,
|
||||
fresh: current,
|
||||
runtimeSnapshot: {
|
||||
channels: {},
|
||||
channelAccounts: {
|
||||
discord: { default: { accountId: "default", running: true, connected: true } },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(refreshHealthSnapshot).toHaveBeenCalledWith({
|
||||
probe: false,
|
||||
includeSensitive: false,
|
||||
});
|
||||
expect(respond).toHaveBeenCalledWith(true, current, undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("logs.tail", () => {
|
||||
|
||||
Reference in New Issue
Block a user