Skip to content

Commit 4969f2d

Browse files
committed
feat(ui): render queued follow-ups as transcript bubbles
A follow-up sent during an active run previously appeared only as a composer-attached queue card until it started; the transcript gave no immediate acknowledgment and the reply appeared to ignore the send. Queued messages now render as real user bubbles at the transcript tail, one bubble per submit in queue order, with the live stream continuing above them. The bubble keeps one stable identity from submit through queue reorder, admission, and durable-history handoff, so nothing remounts or jumps. The existing queue controls (steer now, edit, reorder, remove, retry) attach beneath the queued bubble; the composer-attached cards no longer duplicate message content and keep only local-command cards. Supersedes the ordinary-message placement half of #127823.
1 parent 5b605da commit 4969f2d

23 files changed

Lines changed: 569 additions & 216 deletions

‎docs/web/control-ui.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,9 @@ Chat error banners, including cloud runner failures, keep a compact preview. Ope
614614
- Click **Stop**. Runs with an exact local run ID call `chat.abort`; when selected-session state reports active work but the Control UI has no local run ID, it calls `sessions.abort` instead. For non-global sessions, that selected-session path also discards queued follow-ups so they cannot restart work after the stop.
615615
- While a run is active, normal follow-ups use the Gateway's effective `messages.queue` mode. `steer` injects into the running turn; other modes keep the browser's durable queued delivery. Steering rejection also falls back to that queue. Click **Steer** on a queued message to inject it manually. Text already streamed in an open chat stays before the steering message across history refreshes and reconnects; subsequent updates show only the continuation below it.
616616
- With **Settings → Appearance → Send shortcut** set to **Enter**, **Cmd/Ctrl+Enter** submits the opposite follow-up action while connected to an active run: queue when Enter steers, or steer when Enter queues (including inherited `collect` and `followup` modes). The send button tooltip shows both actions for the current follow-up setting. This affects only that message, not your saved preference. With the **Cmd/Ctrl+Enter** send shortcut selected, modified Enter remains the normal send action and plain Enter inserts a newline. Interrupt mode keeps its normal behavior.
617-
- Reorder the queue from the handle on the left of a queued message: drag it, or focus it and press the up and down arrow keys. The position is stored with the message, so it survives a reload and decides delivery order, not just what the list looks like. Rows already handed to a run — sending, steering, running a command, awaiting settings, or waiting on an uncertain delivery — hold their place and split the queue: a message moves only among the rows between two of them, so it can never reach the Gateway ahead of work already handed over.
618-
- Edit a queued message with the pencil on its row, or by double-clicking the row. The row becomes its own textarea and stays in place while the main composer remains independent, including any separate draft and attachments. Submit replaces the row in the same slot and preserves its attachments; Cancel or Escape discards the row-local draft and restores the queued message. A normal composer send remains a separate queued item even while a row edit is open. The queue behind an edited row waits rather than delivering a message you are still rewriting, so that row splits the queue for reordering the same way an in-flight row does. Queued slash commands keep the discard-and-retype flow.
617+
- Queued follow-ups appear immediately as user bubbles at the end of the transcript, after the current run’s content. Their queued status and controls stay beside the bubble until delivery starts; the composer does not repeat their content. Queued local commands remain attached to the composer.
618+
- Reorder the queue from the handle beneath a queued bubble: drag it, or focus it and press the up and down arrow keys. The position is stored with the message, so it survives a reload and decides delivery order, not just what the list looks like. Rows already handed to a run — sending, steering, running a command, awaiting settings, or waiting on an uncertain delivery — hold their place and split the queue: a message moves only among the rows between two of them, so it can never reach the Gateway ahead of work already handed over.
619+
- Edit a queued message from its **More queued message actions** menu, or by double-clicking the bubble. The bubble becomes its own textarea and stays in place while the main composer remains independent, including any separate draft and attachments. Submit replaces the row in the same slot and preserves its attachments; Cancel or Escape discards the row-local draft and restores the queued message. A normal composer send remains a separate queued item even while a row edit is open. The queue behind an edited row waits rather than delivering a message you are still rewriting, so that row splits the queue for reordering the same way an in-flight row does. Queued slash commands keep the discard-and-retype flow.
619620
- **Settings → Appearance → Chat → Follow-ups while the agent is working** can override that server default for the current browser. The page marks an override explicitly and offers **Reset to server default**. `Steer into the active run` sends follow-ups immediately, while `Queue until the run ends` holds them until the run finishes.
620621
- Type `/stop` (or standalone abort phrases like `stop`, `stop action`, `stop run`, `stop openclaw`, `please stop`) to abort out-of-band.
621622
- `chat.abort` supports `{ sessionKey }` (no `runId`) to abort all active runs for that session. The Control UI uses `sessions.abort` when it has no local run ID.

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

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ suite.define(() => {
642642
await composer.fill(queuedText);
643643
await composer.press("Control+Enter");
644644

645-
const queuedRow = page.locator(".chat-queue__item", { hasText: queuedText });
645+
const queuedRow = page.locator(".chat-group.user", { hasText: queuedText });
646646
await queuedRow.waitFor({ timeout: 10_000 });
647647
await expectRequestCountStable(gateway, "chat.send", 1);
648648
} finally {
@@ -688,9 +688,16 @@ suite.define(() => {
688688
}
689689
});
690690

691-
it("sends a queued follow-up after an exact terminal session publication", async () => {
691+
it("keeps two distinct queued bubbles below streaming and admits the first in place", async () => {
692+
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
693+
if (artifactDir) {
694+
await mkdir(artifactDir, { recursive: true });
695+
}
692696
const context = await suite.newBrowserContext({
693697
locale: "en-US",
698+
...(artifactDir
699+
? { recordVideo: { dir: artifactDir, size: { height: 900, width: 1280 } } }
700+
: {}),
694701
serviceWorkers: "block",
695702
viewport: { height: 900, width: 1280 },
696703
});
@@ -714,12 +721,78 @@ suite.define(() => {
714721
const activeSessionKey = requireString(initialSendParams.sessionKey, "active session key");
715722
await page.getByRole("button", { name: "Stop generating" }).waitFor({ timeout: 10_000 });
716723

724+
const transcript = page.locator(".chat-thread-inner");
725+
const streamText = "The current response is still streaming.";
726+
const emitStream = (text: string) =>
727+
gateway.emitGatewayEvent("chat", {
728+
message: { role: "assistant", content: [{ type: "text", text }] },
729+
runId: activeRunId,
730+
sessionKey: activeSessionKey,
731+
state: "delta",
732+
});
733+
const capture = async (name: string) => {
734+
if (artifactDir) {
735+
await page.screenshot({ fullPage: true, path: path.join(artifactDir, name) });
736+
}
737+
};
738+
await emitStream(streamText);
739+
await transcript.getByText(streamText, { exact: true }).waitFor();
717740
const followUp = "send after the missed terminal event";
741+
const secondFollowUp = "then review the next result";
742+
const rowKey = (bubble: Element) =>
743+
bubble.closest("[data-virtual-row-key]")?.getAttribute("data-virtual-row-key");
744+
const sameBubble = (bubble: Element, original: Element | null) => bubble === original;
745+
const firstBubble = transcript
746+
.locator(".chat-group.user", { hasText: followUp })
747+
.locator(".chat-bubble");
718748
await composer.fill(followUp);
719749
await page.getByRole("button", { name: "Queue message" }).click();
720-
const queuedRow = page.locator(".chat-queue__item", { hasText: followUp });
721-
await queuedRow.waitFor({ timeout: 10_000 });
750+
await page.getByText(followUp, { exact: true }).waitFor();
751+
await capture("queued-00-submitted.png");
752+
await firstBubble.waitFor({ timeout: 10_000 });
753+
expect(await firstBubble.count()).toBe(1);
754+
const firstElement = await firstBubble.elementHandle();
755+
expect(firstElement).not.toBeNull();
756+
const firstRowKey = await firstBubble.evaluate(rowKey);
757+
expect(firstRowKey).toBeTruthy();
758+
await capture("queued-01-first-follow-up.png");
759+
760+
await composer.fill(secondFollowUp);
761+
await page.getByRole("button", { name: "Queue message" }).click();
762+
const secondGroup = transcript.locator(".chat-group.user", { hasText: secondFollowUp });
763+
const secondBubble = secondGroup.locator(".chat-bubble");
764+
await secondBubble.waitFor({ timeout: 10_000 });
765+
expect(await secondBubble.count()).toBe(1);
766+
const secondElement = await secondBubble.elementHandle();
767+
expect(secondElement).not.toBeNull();
768+
const secondRowKey = await secondBubble.evaluate(rowKey);
769+
expect(secondRowKey).toBeTruthy();
770+
expect(secondRowKey).not.toBe(firstRowKey);
771+
const expectSecondQueuedAtTail = async () => {
772+
await secondGroup.getByText("Queued", { exact: true }).waitFor();
773+
expect(await transcript.locator(".chat-group.user .chat-queue__item").count()).toBe(1);
774+
const tail = transcript.locator(".chat-bubble").last();
775+
expect(await tail.evaluate(sameBubble, secondElement)).toBe(true);
776+
expect(await secondBubble.evaluate(rowKey)).toBe(secondRowKey);
777+
};
778+
await emitStream(`${streamText} More text arrives after both follow-ups.`);
779+
await expect
780+
.poll(() =>
781+
transcript
782+
.locator(".chat-bubble .chat-text")
783+
.evaluateAll((bubbles) => bubbles.map((bubble) => bubble.textContent?.trim() ?? "")),
784+
)
785+
.toEqual([
786+
initialText,
787+
`${streamText} More text arrives after both follow-ups.`,
788+
followUp,
789+
secondFollowUp,
790+
]);
791+
expect(await firstBubble.evaluate(sameBubble, firstElement)).toBe(true);
792+
expect(await page.locator(".chat-queue").count()).toBe(0);
793+
expect(await transcript.locator(".chat-group.user .chat-queue__item").count()).toBe(2);
722794
await expectRequestCountStable(gateway, "chat.send", 1);
795+
await capture("queued-02-stream-above-follow-ups.png");
723796

724797
await gateway.setHistoryMessages([
725798
{
@@ -745,6 +818,7 @@ suite.define(() => {
745818
await expect
746819
.poll(async () => (await gateway.getRequests("sessions.list")).length)
747820
.toBeGreaterThan(sessionListsBeforeTerminal);
821+
await gateway.deferNext("chat.send");
748822
await gateway.resolveDeferred(
749823
"sessions.list",
750824
chatSessionListResponse([
@@ -762,8 +836,50 @@ suite.define(() => {
762836
);
763837

764838
const sends = await waitForRequests(gateway, "chat.send", 2);
765-
expect(requireRecord(sends[1]?.params)).toMatchObject({ message: followUp });
766-
await queuedRow.waitFor({ state: "detached", timeout: 10_000 });
839+
const admitted = requireRecord(sends[1]?.params);
840+
expect(admitted).toMatchObject({ message: followUp });
841+
const admittedRunId = requireString(admitted.idempotencyKey, "admitted queued run id");
842+
expect(await firstBubble.evaluate(sameBubble, firstElement)).toBe(true);
843+
expect(await firstBubble.evaluate(rowKey)).toBe(firstRowKey);
844+
await gateway.resolveDeferred("chat.send", { runId: admittedRunId, status: "started" });
845+
await transcript
846+
.locator(".chat-group.user", { hasText: followUp })
847+
.locator(".chat-queue__item")
848+
.waitFor({ state: "detached" });
849+
expect(await firstBubble.evaluate(sameBubble, firstElement)).toBe(true);
850+
await expectSecondQueuedAtTail();
851+
await capture("queued-03-admitted-in-place.png");
852+
853+
await gateway.emitGatewayEvent("session.message", {
854+
activeRunIds: [admittedRunId],
855+
clientRunId: admittedRunId,
856+
hasActiveRun: true,
857+
message: {
858+
__openclaw: {
859+
id: "queued-follow-up-user",
860+
idempotencyKey: `${admittedRunId}:user`,
861+
seq: 2,
862+
},
863+
role: "user",
864+
content: [{ type: "text", text: followUp }],
865+
timestamp: Date.now(),
866+
},
867+
messageId: "queued-follow-up-user",
868+
messageSeq: 2,
869+
runId: admittedRunId,
870+
sessionKey: activeSessionKey,
871+
});
872+
await expect
873+
.poll(() => firstBubble.getAttribute("data-entry-id"))
874+
.toBe("queued-follow-up-user");
875+
expect(await firstBubble.count()).toBe(1);
876+
expect(await firstBubble.evaluate(sameBubble, firstElement)).toBe(true);
877+
expect(await firstBubble.evaluate(rowKey)).toBe(firstRowKey);
878+
await expectSecondQueuedAtTail();
879+
await expectRequestCountStable(gateway, "chat.send", 2);
880+
await capture("queued-04-history-handoff.png");
881+
await firstElement?.dispose();
882+
await secondElement?.dispose();
767883
} finally {
768884
await suite.closeBrowserContext(context);
769885
}
@@ -887,7 +1003,9 @@ suite.define(() => {
8871003
const queuedPrompt = "steer this after restoring the queue";
8881004
await page.locator(".agent-chat__composer-combobox textarea").fill(queuedPrompt);
8891005
await page.getByRole("button", { name: "Queue message" }).click();
890-
await page.locator(".chat-queue").getByText(queuedPrompt).waitFor({ timeout: 10_000 });
1006+
await page
1007+
.locator(".chat-group.user", { hasText: queuedPrompt })
1008+
.waitFor({ timeout: 10_000 });
8911009

8921010
await gateway.setMethodResponse(
8931011
"sessions.list",
@@ -915,7 +1033,7 @@ suite.define(() => {
9151033
await page.reload();
9161034
await gateway.waitForRequest("sessions.list");
9171035

918-
const queue = page.locator(".chat-queue");
1036+
const queue = page.locator(".chat-group.user", { hasText: queuedPrompt });
9191037
await queue.getByText(queuedPrompt).waitFor({ timeout: 10_000 });
9201038
await queue.getByRole("button", { name: "Steer" }).click();
9211039

‎ui/src/e2e/chat-flow.composer-shortcuts.e2e.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ suite.define(() => {
7474
await composer.press("Control+Enter");
7575

7676
if (followUpMode === "steer") {
77-
const queuedRow = page.locator(".chat-queue__item", { hasText: followUpText });
77+
const queuedRow = page
78+
.locator(".chat-group.user", { hasText: followUpText })
79+
.locator(".chat-queue__item");
7880
await queuedRow.waitFor();
7981
await expectRequestCountStable(gateway, "chat.send", 1);
8082
await gateway.setMethodResponse("chat.history", {

‎ui/src/e2e/chat-flow.history-recovery.e2e.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ suite.define(() => {
878878
expect(sendEnabled).toBe(true);
879879
await send.click();
880880

881-
const queue = page.locator(".chat-queue");
881+
const queue = page.locator(".chat-group.user:has(.chat-queue__item)", { hasText: prompt });
882882
await queue.getByText("Waiting for reconnect").waitFor({ timeout: 10_000 });
883883
await queue.getByText(prompt).waitFor({ timeout: 10_000 });
884884
const requestsBeforeReconnect = await gateway.getRequests("chat.send");

‎ui/src/e2e/chat-flow.models-reasoning.e2e.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,10 @@ suite.define(() => {
838838
await page.locator(".chat-queue").getByText("Applying chat settings").waitFor({
839839
timeout: 10_000,
840840
});
841-
await page.locator(".chat-queue").getByText(prompt).waitFor({ timeout: 10_000 });
841+
await page
842+
.locator(".chat-group.user .chat-bubble")
843+
.getByText(prompt)
844+
.waitFor({ timeout: 10_000 });
842845
expect(await gateway.getRequests("chat.send")).toHaveLength(0);
843846

844847
await gateway.resolveDeferred("sessions.patch", {});

0 commit comments

Comments
 (0)