Skip to content

Commit bf2f75f

Browse files
yanmo42siewcapital
andcommitted
fix: queued chat follow-ups stay stuck after missed terminal events
Co-authored-by: Siew's Capital Jarvis <[email protected]>
1 parent f24bd8a commit bf2f75f

9 files changed

Lines changed: 1226 additions & 8 deletions

‎.github/workflows/ci.yml‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,13 +1780,26 @@ jobs:
17801780
--configLoader runner
17811781
ui/src/e2e/mcp-app-conformance.e2e.test.ts
17821782
1783-
- name: Test Control UI auth transports with a real Gateway
1783+
- name: Test Control UI browser flows with a real Gateway
1784+
env:
1785+
OPENCLAW_CAPTURE_UI_PROOF: "1"
1786+
OPENCLAW_UI_E2E_ARTIFACT_DIR: .artifacts/control-ui-e2e/chat-flow-real-gateway
17841787
run: >-
17851788
node scripts/run-vitest.mjs run
17861789
--config test/vitest/vitest.ui-e2e.config.ts
17871790
--configLoader runner
1791+
ui/src/e2e/chat-flow.real-gateway.e2e.test.ts
17881792
ui/src/e2e/control-ui-auth-transports.e2e.test.ts
17891793
1794+
- name: Upload Control UI real-Gateway behavior proof
1795+
if: always()
1796+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
1797+
with:
1798+
name: control-ui-real-gateway-proof-${{ github.run_attempt }}
1799+
path: .artifacts/control-ui-e2e/chat-flow-real-gateway
1800+
if-no-files-found: warn
1801+
retention-days: 7
1802+
17901803
control-ui-i18n:
17911804
permissions:
17921805
contents: read

‎test/scripts/ci-workflow-guards.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6597,7 +6597,7 @@ printf '%s\n' "\${CURL_SUCCESS_IP:-203.0.113.7}"
65976597
.map((step: WorkflowStep) => step.run);
65986598
expect(realGatewayRuns).toEqual([
65996599
"node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/mcp-app-conformance.e2e.test.ts",
6600-
"node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/control-ui-auth-transports.e2e.test.ts",
6600+
"node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.real-gateway.e2e.test.ts ui/src/e2e/control-ui-auth-transports.e2e.test.ts",
66016601
]);
66026602
const realGatewayRunContract = realGatewayRuns.join("\n");
66036603
expect(realGatewayRunContract).not.toContain("--retry");

‎test/vitest/vitest.ui-e2e.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { UiE2eSequencer } from "./vitest.ui-e2e.sequencer.ts";
66

77
const uiE2eIncludePatterns = ["ui/src/**/*.e2e.test.ts"];
88
const uiE2eRealGatewayTestFiles = [
9+
"ui/src/e2e/chat-flow.real-gateway.e2e.test.ts",
910
"ui/src/e2e/control-ui-auth-transports.e2e.test.ts",
1011
"ui/src/e2e/mcp-app-conformance.e2e.test.ts",
1112
];

‎ui/src/e2e/chat-flow.follow-ups.e2e.test.ts‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
chatSessionListResponse,
55
createChatFlowE2eSuite,
66
installMockGateway,
7+
pauseVirtualClock,
78
requireRecord,
89
requireString,
910
waitForRequests,
@@ -12,6 +13,112 @@ import {
1213
const suite = createChatFlowE2eSuite();
1314

1415
suite.define(() => {
16+
it("recovers a queued follow-up when terminal events are missed", async () => {
17+
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
18+
const context = await suite.newBrowserContext({
19+
locale: "en-US",
20+
serviceWorkers: "block",
21+
viewport: { height: 900, width: 1280 },
22+
});
23+
const page = await context.newPage();
24+
await page.clock.install();
25+
const gateway = await installMockGateway(page, {
26+
methodResponses: {
27+
"agent.wait": { status: "ok", endedAt: Date.now() },
28+
},
29+
sessionInfo: { hasActiveRun: false, key: "main", status: "done" },
30+
});
31+
32+
try {
33+
await page.goto(`${suite.server.baseUrl}settings/appearance`);
34+
await page.locator("[data-settings-follow-up-mode]").selectOption("queue");
35+
await page.goto(`${suite.server.baseUrl}chat?session=main`);
36+
await expect.poll(() => new URL(page.url()).pathname).toMatch(/\/chat\/main$/);
37+
38+
await page.locator(".agent-chat__composer-combobox textarea").fill("finish silently");
39+
await page.getByRole("button", { name: "Send message" }).click();
40+
const initialSend = await gateway.waitForRequest("chat.send");
41+
const activeRunId = requireString(
42+
requireRecord(initialSend.params).idempotencyKey,
43+
"active chat run id",
44+
);
45+
await gateway.setMethodResponse("chat.history", {
46+
messages: [
47+
{
48+
__openclaw: { idempotencyKey: `${activeRunId}:user` },
49+
content: [{ text: "finish silently", type: "text" }],
50+
role: "user",
51+
timestamp: Date.now(),
52+
},
53+
],
54+
sessionId: "control-ui-e2e-session",
55+
sessionInfo: { hasActiveRun: false, key: "global", status: "done" },
56+
thinkingLevel: null,
57+
});
58+
await gateway.emitGatewayEvent("session.message", {
59+
activeRunIds: [activeRunId],
60+
clientRunId: activeRunId,
61+
hasActiveRun: true,
62+
message: {
63+
__openclaw: {
64+
id: "persisted-silent-user",
65+
idempotencyKey: `${activeRunId}:user`,
66+
seq: 1,
67+
},
68+
content: [{ text: "finish silently", type: "text" }],
69+
role: "user",
70+
timestamp: Date.now(),
71+
},
72+
messageId: "persisted-silent-user",
73+
messageSeq: 1,
74+
session: {
75+
activeRunIds: [activeRunId],
76+
hasActiveRun: true,
77+
key: "main",
78+
kind: "direct",
79+
status: "running",
80+
updatedAt: Date.now(),
81+
},
82+
sessionKey: "main",
83+
});
84+
await page.getByRole("button", { name: "Stop generating" }).waitFor({ timeout: 10_000 });
85+
await gateway.setMethodResponse("chat.send", { runId: "recovered-run", status: "ok" });
86+
87+
await pauseVirtualClock(page);
88+
const followUp = "send after the missed terminal";
89+
await page.locator(".agent-chat__composer-combobox textarea").fill(followUp);
90+
await page.getByRole("button", { name: "Queue message" }).click();
91+
const queue = page.locator(".chat-queue");
92+
await queue.getByText(followUp).waitFor({ timeout: 10_000 });
93+
expect(await gateway.getRequests("chat.send")).toHaveLength(1);
94+
if (artifactDir) {
95+
await page.screenshot({
96+
path: `${artifactDir}/missed-terminal-queued.png`,
97+
fullPage: true,
98+
});
99+
}
100+
101+
await page.clock.fastForward(15_000);
102+
103+
await gateway.waitForRequest("agent.wait");
104+
await page.clock.runFor(1_000);
105+
const sends = await waitForRequests(gateway, "chat.send", 2);
106+
expect(requireRecord(sends[1]?.params)).toMatchObject({
107+
message: followUp,
108+
sessionKey: "main",
109+
});
110+
await queue.waitFor({ state: "detached", timeout: 10_000 });
111+
if (artifactDir) {
112+
await page.screenshot({
113+
path: `${artifactDir}/missed-terminal-recovered.png`,
114+
fullPage: true,
115+
});
116+
}
117+
} finally {
118+
await suite.closeBrowserContext(context);
119+
}
120+
});
121+
15122
it("opens a git-backed agent draft from the sidebar new-session action", async () => {
16123
const context = await suite.newBrowserContext({
17124
locale: "en-US",

0 commit comments

Comments
 (0)