diff --git a/server/src/__tests__/heartbeat-run-dispatch-lifecycle.test.ts b/server/src/__tests__/heartbeat-run-dispatch-lifecycle.test.ts index b6fbb7353de..f3398d828f8 100644 --- a/server/src/__tests__/heartbeat-run-dispatch-lifecycle.test.ts +++ b/server/src/__tests__/heartbeat-run-dispatch-lifecycle.test.ts @@ -71,14 +71,16 @@ describe("run dispatch obligations", () => { it("batches repeated tenant writes and passes only their company to queued dispatch", async () => { const f = fixture(); await f.worker.ready; for (let index = 0; index < 100; index++) { - await f.notify({ companyId: "company-a" }); + const source = { companyId: "company-a", issueId: `issue-${index % 2}`, + runId: `run-${index}`, agentId: `agent-${index}`, interactionBody: "not a dispatch key" }; + await f.notify(source); await vi.advanceTimersByTimeAsync(10); } expect(f.promote.mock.calls.length).toBeLessThanOrEqual(2); expect(f.dispatch.mock.calls.length).toBeLessThanOrEqual(2); await f.settle(); expect(f.dispatch).toHaveBeenLastCalledWith({ companyId: "company-a" }); - expect(f.dispatch.mock.calls.slice(1).every(([scope]) => scope?.companyId === "company-a")).toBe(true); + for (const [scope] of f.dispatch.mock.calls.slice(1)) expect(scope).toEqual({ companyId: "company-a" }); expect(f.coordinator.nextWakeAt()).toBeNull(); const count = f.dispatch.mock.calls.length; await vi.advanceTimersByTimeAsync(20 * 60_000); expect(f.dispatch).toHaveBeenCalledTimes(count); diff --git a/server/src/services/run-dispatch-notifications.ts b/server/src/services/run-dispatch-notifications.ts index 2e04e6e7531..e62b8c62105 100644 --- a/server/src/services/run-dispatch-notifications.ts +++ b/server/src/services/run-dispatch-notifications.ts @@ -3,7 +3,7 @@ import { DELIVERY_QUEUES, notifyDeliveryWork } from "./delivery-work-notificatio export type RunDispatchScope = { companyId: string }; export async function notifyRunDispatch(transaction: object, scope?: RunDispatchScope) { - const hint = scope ? JSON.stringify(scope) : "*"; + const hint = scope ? JSON.stringify({ companyId: scope.companyId }) : "*"; await notifyDeliveryWork(transaction, DELIVERY_QUEUES.scheduledRetryDispatch, hint); await notifyDeliveryWork(transaction, DELIVERY_QUEUES.queuedRunDispatch, hint); }