Skip to content

Commit 4e8e22f

Browse files
authored
test(gateway): assert settled run ownership by fact, not label (#129033)
The chat.run.settled assertion matched sessions.changed on its `reason` label. That label is best-effort by design: emitSessionsChanged coalesces per session key and keeps only the newest payload, so any same-key emit inside the 100ms/500ms window replaces an earlier reason while the row itself (activeRunIds/hasActiveRun/lastRunId) is still rebuilt at broadcast time. On a contended runner the test could therefore wait out its full 8s budget even though ownership settlement was published correctly. Match the published ownership fact instead - the same fields the TUI and Control UI actually consume - which is a stricter contract than the label and immune to coalescing. Producer left untouched: the settle emit sits in the dispatch tail's unconditional finally and its trailing broadcast is bounded and always rebuilt, so no settlement fact can be lost or reordered.
1 parent eca3660 commit 4e8e22f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/gateway/server.chat.gateway-server-chat.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,13 +2572,19 @@ describe("gateway server chat", () => {
25722572
});
25732573
expectAgentWaitTimeout(waitWhileChatActive);
25742574

2575+
// Match the published ownership fact, not the `reason` label: sessions.changed
2576+
// coalesces bursts per session key and keeps only the newest payload, so any
2577+
// same-key mutation inside that window legitimately replaces the label while
2578+
// the row (activeRunIds/lastRunId) is still rebuilt at broadcast time.
25752579
const settledSessionChange = onceMessage(
25762580
ws,
25772581
(event) =>
25782582
event.type === "event" &&
25792583
event.event === "sessions.changed" &&
2580-
event.payload?.reason === "chat.run.settled" &&
25812584
event.payload?.sessionKey === "agent:main:main" &&
2585+
event.payload?.hasActiveRun === false &&
2586+
Array.isArray(event.payload?.activeRunIds) &&
2587+
event.payload.activeRunIds.length === 0 &&
25822588
event.payload?.lastRunId === runId,
25832589
8_000,
25842590
);

0 commit comments

Comments
 (0)