Skip to content

Commit d662ae8

Browse files
committed
fix(ui): keep reconnect-uncertain sends inline and prove delivery by run id
After a reconnect lost the chat.send ack, the outbox reconcile only accepted the transcript idempotency marker as delivery proof, so a send whose run was actively streaming parked as a red 'Delivery uncertain' composer chip for the whole run. The reconcile now also retires a queued send when the session row reports its run id in activeRunIds or as lastRunId — the same fact live terminal-event retirement already trusts. Attempted unconfirmed messages now stay in the conversation as ordinary bubbles with an amber 'Delivery unconfirmed · Retry' footer (failed keeps the red 'Not sent'); the duplicate pane banner is suppressed for them since the bubble owns the outcome. Command chips, never-attempted failures, and storage errors keep their existing surfaces. Calmer copy for the remaining honest uncertainty case.
1 parent bcb5403 commit d662ae8

13 files changed

Lines changed: 355 additions & 95 deletions

‎docs/web/control-ui.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@ automatically when the Gateway returns. Live controls and slash commands remain
609609
offline, except that **Stop** can queue an exact local run ID for replay. A session-only stop
610610
is not replayed because newer work may start in that session before the connection returns.
611611

612+
If the connection drops before a send is acknowledged, reconnect checks the transcript and
613+
the session's active or last run ID for delivery proof. A matching run confirms receipt even
614+
before its transcript row appears. Without proof, an attempted message stays in the conversation
615+
with an amber **Delivery unconfirmed** footer and **Retry**. Check the conversation and retry only
616+
if the message did not arrive. Unconfirmed local commands keep their retry/discard queue controls.
617+
612618
First opens and reloads show a small animated OpenClaw mark while the Gateway resolves the initial
613619
connection, including when authentication comes from a trusted proxy or Tailscale instead of a
614620
browser-stored credential. The login gate appears only after the initial connection fails or the

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,22 +592,24 @@ suite.define(() => {
592592

593593
await gateway.closeLatest(1006, "lost ack");
594594

595-
const queue = page.locator(".chat-queue");
596-
await queue.getByText("Delivery uncertain").waitFor({ timeout: 10_000 });
595+
const deliveryStatus = page.locator('.chat-send-status[data-send-state="unconfirmed"]');
596+
await deliveryStatus.getByText("Delivery unconfirmed").waitFor({ timeout: 10_000 });
597+
expect(await page.locator(".chat-queue").count()).toBe(0);
598+
await page.locator(".chat-group.user").getByText(prompt, { exact: true }).waitFor();
597599
expect(await gateway.getRequests("chat.send")).toHaveLength(1);
598-
await queue.locator(".chat-queue__retry").click();
600+
await deliveryStatus.getByRole("button", { name: "Retry queued message" }).click();
599601

600602
const sends = await waitForRequests(gateway, "chat.send", 2);
601603
const secondParams = requireRecord(sends[1]?.params);
602604
expect(secondParams.idempotencyKey).toBe(runId);
603605
expect(secondParams.message).toBe(prompt);
604-
await queue.waitFor({ state: "detached", timeout: 10_000 });
606+
await deliveryStatus.waitFor({ state: "detached", timeout: 10_000 });
605607
} finally {
606608
await suite.closeBrowserContext(context);
607609
}
608610
});
609611

610-
it("dismisses an ACK-lost banner after exact authoritative history proof", async () => {
612+
it("clears inline delivery uncertainty after exact authoritative history proof", async () => {
611613
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
612614
const context = await suite.newBrowserContext({
613615
locale: "en-US",
@@ -644,8 +646,11 @@ suite.define(() => {
644646
);
645647
await gateway.closeLatest(1006, "lost ack");
646648

647-
const queue = page.locator(".chat-queue");
648-
await queue.getByText("Delivery uncertain").waitFor({ timeout: 10_000 });
649+
const deliveryStatus = page.locator('.chat-send-status[data-send-state="unconfirmed"]');
650+
await deliveryStatus.getByText("Delivery unconfirmed").waitFor({ timeout: 10_000 });
651+
expect(await page.locator(".chat-queue").count()).toBe(0);
652+
const userBubble = page.locator(".chat-group.user").getByText(prompt, { exact: true });
653+
await userBubble.waitFor();
649654
if (artifactDir) {
650655
await page.screenshot({ path: `${artifactDir}/01-delivery-uncertain.png`, fullPage: true });
651656
}
@@ -665,7 +670,7 @@ suite.define(() => {
665670
sessionKey: "main",
666671
status: "done",
667672
});
668-
await queue.getByText("Delivery uncertain").waitFor({ timeout: 10_000 });
673+
await deliveryStatus.getByText("Delivery unconfirmed").waitFor({ timeout: 10_000 });
669674
expect(await gateway.getRequests("chat.send")).toHaveLength(1);
670675
if (artifactDir) {
671676
await page.screenshot({
@@ -691,8 +696,9 @@ suite.define(() => {
691696
status: "running",
692697
});
693698

694-
await queue.waitFor({ state: "detached", timeout: 10_000 });
695-
await page.locator(".chat-group.user").getByText(prompt).waitFor({ timeout: 10_000 });
699+
await deliveryStatus.waitFor({ state: "detached", timeout: 10_000 });
700+
await userBubble.waitFor({ timeout: 10_000 });
701+
expect(await userBubble.count()).toBe(1);
696702
expect(await gateway.getRequests("chat.send")).toHaveLength(1);
697703
if (artifactDir) {
698704
await page.screenshot({ path: `${artifactDir}/03-delivery-proven.png`, fullPage: true });

‎ui/src/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,6 +5721,7 @@ export const en: TranslationMap = {
57215721
},
57225722
queue: {
57235723
notSent: "Not sent",
5724+
deliveryUnconfirmed: "Delivery unconfirmed",
57245725
retry: "Retry",
57255726
retryQueuedMessage: "Retry queued message",
57265727
steer: "Steer",

‎ui/src/pages/chat/chat-composer-queue.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,44 @@ afterEach(async () => {
1313
});
1414

1515
describe("chat composer steering queue", () => {
16+
it("keeps attempted unconfirmed messages inline while local commands retain retry and discard", () => {
17+
const onQueueRetry = vi.fn();
18+
const onQueueRemove = vi.fn();
19+
const container = renderQueue({
20+
queue: [
21+
{
22+
id: "message",
23+
text: "Already attempted",
24+
createdAt: 1,
25+
sendState: "unconfirmed",
26+
sendAttempts: 1,
27+
},
28+
{
29+
id: "reset",
30+
text: "/reset",
31+
localCommandName: "reset",
32+
createdAt: 2,
33+
sendState: "unconfirmed",
34+
sendError: "Check the conversation before retrying the command.",
35+
sendAttempts: 1,
36+
},
37+
],
38+
onQueueRetry,
39+
onQueueRemove,
40+
});
41+
42+
const rows = container.querySelectorAll(".chat-queue__item");
43+
expect(rows).toHaveLength(1);
44+
expect(rows[0]?.getAttribute("data-chat-queue-item")).toBe("reset");
45+
expect(rows[0]?.querySelector(".chat-queue__badge")?.textContent?.trim()).toBe(
46+
t("chat.queue.states.needsReview"),
47+
);
48+
rows[0]?.querySelector<HTMLButtonElement>(".chat-queue__retry")?.click();
49+
rows[0]?.querySelector<HTMLButtonElement>(".chat-queue__remove")?.click();
50+
expect(onQueueRetry).toHaveBeenCalledWith("reset");
51+
expect(onQueueRemove).toHaveBeenCalledWith("reset");
52+
});
53+
1654
it("renders the durable steer mode without a run-bound state", () => {
1755
const container = document.createElement("div");
1856
document.body.append(container);

‎ui/src/pages/chat/chat-outbox-drain.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type StoredChatOutboxClientState = {
101101
const STORED_OUTBOX_CONFIRMATION_GRACE_MS = 5_000;
102102
const STORED_OUTBOX_RETRY_DEFAULT_MS = 500;
103103
export const UNCONFIRMED_CHAT_SEND_ERROR =
104-
"Delivery could not be confirmed after reconnect. Check the conversation before retrying.";
104+
"Reconnected before delivery was confirmed. Check the conversation — retry only if your message didn't arrive.";
105105
const UNCERTAIN_CLEAR_SUCCESSOR_ERROR =
106106
"A preceding /clear may have completed. Review the current conversation before retrying.";
107107

@@ -156,6 +156,17 @@ function queuedDeliveryVersion(item: ChatQueueItem): string {
156156
return `${item.id}\u0000${item.sendRunId ?? ""}\u0000${item.sendAttempts ?? 0}`;
157157
}
158158

159+
function sessionRunProvesQueuedDelivery(
160+
sessionInfo: ChatHistoryResult["sessionInfo"],
161+
item: ChatQueueItem,
162+
): boolean {
163+
return Boolean(
164+
item.sendRunId &&
165+
(sessionInfo?.activeRunIds?.includes(item.sendRunId) ||
166+
sessionInfo?.lastRunId === item.sendRunId),
167+
);
168+
}
169+
159170
async function readCurrentStoredChatHistory(
160171
host: ChatHost,
161172
outbox: StoredChatOutbox,
@@ -209,6 +220,10 @@ async function readCurrentStoredChatHistory(
209220
outbox.sessionKey,
210221
outbox.agentId,
211222
parked ? error : OFFLINE_QUEUE_STORAGE_ERROR,
223+
// A parked attempted message owns its inline bubble footer; the pane
224+
// banner would duplicate it. Never-attempted failures, command chips,
225+
// and storage failures keep the banner — they render no bubble.
226+
{ inline: Boolean(parked && attempted && !item.localCommandName) },
212227
);
213228
return parked && !attempted ? "continue" : "blocked";
214229
}
@@ -221,7 +236,12 @@ async function readCurrentStoredChatHistory(
221236
return "continue";
222237
}
223238
syncVisibleChatQueueProjection(host);
224-
if (chatMessagesContainQueuedSend(history.messages, item)) {
239+
// Gateway chat run IDs equal client idempotency keys; terminal-event retirement
240+
// uses the same delivery proof, even before the transcript marker is persisted.
241+
if (
242+
chatMessagesContainQueuedSend(history.messages, item) ||
243+
sessionRunProvesQueuedDelivery(history.sessionInfo, item)
244+
) {
225245
// Materialize server history locally before removing the queue bubble.
226246
preserveQueuedUserTurn(host, item);
227247
const removed = removeQueuedMessageWithoutReleasing(host, item.id, outbox.sessionKey);
@@ -260,7 +280,7 @@ async function reconcileStoredChatOutboxHead(
260280
// recorded into the session row. Skipping the 1000-message chat.history here
261281
// stops one full-history RPC per transcript event while a run streams.
262282
// Attempted items keep the fetch: delivered-detection must retire their
263-
// bubbles even mid-run, and a missing row falls through conservatively.
283+
// bubbles even mid-run; missing transcript and run proof falls through conservatively.
264284
const neverAttempted =
265285
(item.sendAttempts ?? 0) === 0 && item.sendRequestStartedAtMs === undefined;
266286
if (neverAttempted && item.queueMode) {
@@ -337,6 +357,9 @@ async function reconcileStoredChatOutboxHead(
337357
outbox.sessionKey,
338358
outbox.agentId,
339359
UNCONFIRMED_CHAT_SEND_ERROR,
360+
// The parked bubble's inline footer is the visible outcome; hidden
361+
// panes still get the named toast. Command chips never park here.
362+
{ inline: !item.localCommandName },
340363
);
341364
}
342365
return "blocked";

‎ui/src/pages/chat/chat-progress.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ export function isQueuedSendInlineState(item: ChatQueueItem): boolean {
167167
return (
168168
queuedSendStarted(item) &&
169169
!item.localCommandName &&
170-
(item.sendState === "failed" || (item.sendState === "waiting-idle" && Boolean(item.sendError)))
170+
(item.sendState === "failed" ||
171+
item.sendState === "unconfirmed" ||
172+
(item.sendState === "waiting-idle" && Boolean(item.sendError)))
171173
);
172174
}
173175

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,6 +3818,60 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
38183818
}
38193819
});
38203820

3821+
it.for(["dark", "light"])(
3822+
"keeps unconfirmed footers and Retry amber while failed sends stay red in %s mode",
3823+
async (theme, context) => {
3824+
const page = await openBrowserPage(390, 844);
3825+
try {
3826+
await page.setContent(`<!doctype html><html data-theme-mode="${theme}"><head><style>${readUiCss()}</style></head><body>
3827+
<span id="warning-color-probe" style="color: var(--warn)">Warning</span>
3828+
<span id="danger-color-probe" style="color: var(--danger)">Failure</span>
3829+
${[
3830+
{ state: "unconfirmed", label: "Delivery unconfirmed" },
3831+
{ state: "failed", label: "Not sent" },
3832+
]
3833+
.map(
3834+
({ state, label }) => `<div class="chat-group user chat-group--with-footer">
3835+
<div class="chat-group-messages"><div class="chat-bubble">Attempted message</div></div>
3836+
<div class="chat-group-footer chat-group-footer--send-failure">
3837+
<div class="chat-group-footer__meta"><span class="chat-sender-name">You</span>
3838+
<span class="chat-send-status" data-send-state="${state}">
3839+
<span>·</span><span>${label}</span><span>·</span>
3840+
<button class="chat-send-status__retry" type="button">Retry</button>
3841+
</span>
3842+
</div>
3843+
</div>
3844+
</div>`,
3845+
)
3846+
.join("")}
3847+
</body></html>`);
3848+
3849+
for (const [state, probe] of [
3850+
["unconfirmed", "warning"],
3851+
["failed", "danger"],
3852+
]) {
3853+
const status = page.locator(`.chat-send-status[data-send-state="${state}"]`);
3854+
const expectedColor = await page
3855+
.locator(`#${probe}-color-probe`)
3856+
.evaluate((element) => getComputedStyle(element).color);
3857+
expect(await status.evaluate((element) => getComputedStyle(element).color)).toBe(
3858+
expectedColor,
3859+
);
3860+
const retry = status.locator("button");
3861+
expect(await retry.evaluate((element) => getComputedStyle(element).color)).toBe(
3862+
expectedColor,
3863+
);
3864+
await retry.hover();
3865+
await context.expect
3866+
.poll(() => retry.evaluate((element) => getComputedStyle(element).color))
3867+
.toBe(expectedColor);
3868+
}
3869+
} finally {
3870+
await closeBrowserPage(page);
3871+
}
3872+
},
3873+
);
3874+
38213875
it("covers every reachable queue presentation cell without repeating global state", async () => {
38223876
const page = await openBrowserPage(1520, 2400);
38233877
const reachableCells = QUEUE_MATRIX_MODES.flatMap((mode) =>
@@ -3856,11 +3910,11 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
38563910
'<span class="chat-queue__error"><span class="chat-queue__badge">Failed</span><span class="chat-queue__error-text">Request rejected</span></span>',
38573911
),
38583912
queueExceptionCellHtml(
3859-
"unconfirmed",
3913+
"unconfirmed-local-command",
38603914
"",
38613915
"chat-queue__item--failed",
38623916
"",
3863-
'<span class="chat-queue__error"><span class="chat-queue__badge">Delivery uncertain</span><span class="chat-queue__error-text">Review before retrying</span></span>',
3917+
'<span class="chat-queue__error"><span class="chat-queue__badge">Delivery uncertain</span><span class="chat-queue__error-text">Reconnected before delivery was confirmed. Check the conversation — retry only if your message didn\'t arrive.</span></span>',
38643918
),
38653919
queueExceptionCellHtml(
38663920
"applying-settings",
@@ -3932,7 +3986,7 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
39323986
"item-reconnect",
39333987
"running-command",
39343988
"failed",
3935-
"unconfirmed",
3989+
"unconfirmed-local-command",
39363990
"applying-settings",
39373991
]) {
39383992
await page.locator(`[data-queue-exception="${key}"]`).screenshot({

0 commit comments

Comments
 (0)