fix(matrix): avoid device cleanup sync races

This commit is contained in:
Gustavo Madeira Santana
2026-04-26 22:33:39 -04:00
parent 99159f89da
commit 3b74b913e3
4 changed files with 39 additions and 22 deletions

View File

@@ -96,7 +96,7 @@ describe("matrix device actions", () => {
},
],
}));
withStartedActionClientMock.mockImplementation(async (_opts, run) => {
withResolvedActionClientMock.mockImplementation(async (_opts, run) => {
return await run({
listOwnDevices: vi.fn(async () => [
{
@@ -150,5 +150,10 @@ describe("matrix device actions", () => {
current: true,
}),
]);
expect(withResolvedActionClientMock).toHaveBeenCalledWith(
{ accountId: "poe" },
expect.any(Function),
);
expect(withStartedActionClientMock).not.toHaveBeenCalled();
});
});

View File

@@ -1,5 +1,5 @@
import { summarizeMatrixDeviceHealth } from "../device-health.js";
import { withResolvedActionClient, withStartedActionClient } from "./client.js";
import { withResolvedActionClient } from "./client.js";
import type { MatrixActionClientOpts } from "./types.js";
export async function listMatrixOwnDevices(opts: MatrixActionClientOpts = {}) {
@@ -7,7 +7,7 @@ export async function listMatrixOwnDevices(opts: MatrixActionClientOpts = {}) {
}
export async function pruneMatrixStaleGatewayDevices(opts: MatrixActionClientOpts = {}) {
return await withStartedActionClient(opts, async (client) => {
return await withResolvedActionClient(opts, async (client) => {
const devices = await client.listOwnDevices();
const health = summarizeMatrixDeviceHealth(devices);
const staleGatewayDeviceIds = health.staleOpenClawDevices.map((device) => device.deviceId);