Skip to content

Commit d708507

Browse files
authored
fix(ui): main-session queued follow-ups use the wrong recovery history (#133067)
* fix(ui): keep queued messages bound to their conversation Give mocked Gateway sessions one per-key identity and metadata owner while preserving explicit stale-response fault injection. Separate selected routes from configured main and maintain canonical pin/archive timestamps. Repair the main/global outbox alias collapse exposed by truthful fixtures. Preserve browser queues, drafts, attachments and original send attempts during migration; retain ambiguous legacy destinations unsent for explicit recovery. Keep captured identity, generation, connection and newer-input CAS fences. Fix async committed-state browser probes and remove redundant identity and routing adapters. Full mocked-browser proof passes 322 files / 1305 tests, complete changed checks and the normal Linux UI build before integration. * fix(ui): preserve scoped metadata and queued-edit custody Honor advertised main-session identity and carry canonical per-agent metadata into the composer. Preserve immutable queued-edit ownership across routing and recovery changes without discarding unsaved corrections or weakening replacement CAS. Migrate affected fixture and storage assertions, with real history/reconnect boundary regressions. * fix(ui): type queued-edit recovery through the client contract * test(ui): align session fixtures with typed gateway contracts * test(ui): keep incoming session fixtures coherent Keep Work quota list and startup facts in one fixture, route split tool-title scenarios explicitly, and emit typing events for their actual owning agent. Preserve generation, freshness, pruning and sender-provenance assertions. * fix(ui): keep attachment types outside storage runtimes
1 parent a8c8c82 commit d708507

168 files changed

Lines changed: 6156 additions & 2610 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/web/control-ui.md‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ offline, except that **Stop** can queue an exact local run ID for replay. A sess
665665
is not replayed because newer work may start in that session before the connection returns.
666666

667667
Queued attachments use binary Blobs in the browser's IndexedDB; the outbox keeps only delivery
668-
metadata and payload references in session storage. Attachment bytes stay with the queued input
669-
when session aliases resolve or change; the queue metadata owns its destination. All attachments
668+
metadata and payload references in session storage. Attachment bytes stay with the queued input;
669+
the captured queue metadata owns its destination, even when configured main-session defaults change. All attachments
670670
must be stored before the message is admitted, and all must be readable before sending. Failed admission leaves the draft
671671
unsent. Missing or unreadable queued payloads leave a visible row with recovery guidance; the
672672
browser never sends just the remaining attachments. Binary outbox storage requires browser
@@ -699,6 +699,32 @@ before its transcript row appears. Without proof, an attempted message stays in
699699
with an amber **Delivery unconfirmed** footer and **Retry**. Check the conversation and retry only
700700
if the message did not arrive. Unconfirmed local commands keep their retry/discard queue controls.
701701

702+
Queued messages and drafts keep the conversation and agent selected when they were created.
703+
Switching agents, opening a split pane, or reloading does not move them to another destination.
704+
A literal `global` conversation keeps its captured agent; an agent's main conversation stays
705+
separate unless the Gateway is configured with global session scope.
706+
707+
Older browser state may have combined several destinations into one bucket. The Control UI uses
708+
metadata version 4 (`openclaw.control.chatComposer.v4:`), migrating version 1, 2, and 3 records
709+
directly when their destination is still identifiable. It verifies the new metadata before
710+
removing an older source, retaining complete sources when storage or recovery capacity blocks
711+
migration. This metadata change does not change the IndexedDB schema or durable-draft keys. Ambiguous records appear under
712+
**Saved messages need a destination** and remain unsent. Open the intended non-Incognito conversation with
713+
an empty composer and queue, expand the notice, and choose **Restore here for review**. Confirm
714+
the displayed conversation key and agent. Recovered queued messages stay paused: check for
715+
previous delivery before using **Retry**. Recovered attachment drafts return to the composer
716+
without sending. Reconnect, a replacement session, or enabling Incognito while confirmation is
717+
open cancels the transfer; confirm again in the intended conversation. Older attachment drafts
718+
whose destination is known stay cleared when that destination has a newer clear. Ambiguous saved
719+
data remains available for review. Queued Blob references and original submission IDs survive
720+
both automatic migration and explicit destination recovery. Credential-bound messages are shown
721+
only under their original Gateway credential scope, including when an older bucket contains
722+
messages from several scopes. Moving a message into or out of recovery does not delete its bytes;
723+
cleanup follows verified delivery or discard and accounts for retained recovery messages too.
724+
If the destination changes, a newer draft appears, or storage fails, recovery keeps the source
725+
available rather than overwriting newer input. Do not clear browser site data
726+
while you still have saved messages or attachment drafts to recover.
727+
702728
First opens and reloads show a small animated OpenClaw mark while the Gateway resolves the initial
703729
connection, including when authentication comes from a trusted proxy or Tailscale instead of a
704730
browser-stored credential. The login gate appears only after the initial connection fails or the

‎scripts/control-ui-mock-dev.ts‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import { buildUpdateRestartSentinelPayload } from "../src/infra/update-restart-s
2121
import type { UpdateRunResult } from "../src/infra/update-runner.js";
2222
import type { UpdateAvailable, UpdateScheduleState } from "../ui/src/api/types.ts";
2323
import {
24+
controlUiSessionPath,
2425
createControlUiMockBootstrapConfig,
2526
createControlUiMockGatewayInitScript,
2627
type ControlUiMockGatewayScenario,
2728
} from "../ui/src/test-helpers/control-ui-e2e.ts";
29+
import { createControlUiSessionRow } from "../ui/src/test-helpers/control-ui-session-fixtures.ts";
2830
import {
2931
resolveExternalPackageAliasesForVite,
3032
resolveSourcePackageAliasesForVite,
@@ -391,23 +393,15 @@ function sessionRow(
391393
options: { model?: string; modelProvider?: string } & Record<string, unknown> = {},
392394
) {
393395
const { model, modelProvider, ...extra } = options;
394-
return {
396+
return createControlUiSessionRow(key, label, updatedAt, {
395397
contextTokens: 200_000,
396-
displayName: label,
397-
hasActiveRun: false,
398-
key,
399-
kind: "direct",
400-
label,
401398
model: (model as string | undefined) ?? "gpt-5.6-luna",
402399
modelProvider: (modelProvider as string | undefined) ?? "openai",
403-
status: "done",
404-
totalTokens: 0,
405-
updatedAt,
406400
...extra,
407-
};
401+
});
408402
}
409403

410-
function sessionsListResponse(sessions: unknown[], options: SessionListOptions) {
404+
function sessionsListResponse(sessions: Array<{ key: string }>, options: SessionListOptions) {
411405
return {
412406
count: sessions.length,
413407
defaults: {
@@ -421,14 +415,15 @@ function sessionsListResponse(sessions: unknown[], options: SessionListOptions)
421415
...(options.owners ? { owners: options.owners } : {}),
422416
offset: options.offset ?? 0,
423417
path: "",
424-
sessions,
418+
// Cases select membership; canonical metadata comes from the scenario's rows.
419+
sessions: sessions.map(({ key }) => ({ key })),
425420
totalCount: options.totalCount,
426421
ts: Date.now(),
427422
};
428423
}
429424

430425
function pagedSessionsListResponse(
431-
sessions: unknown[],
426+
sessions: Array<{ key: string }>,
432427
offset: number,
433428
owners?: readonly SessionActorFixture[],
434429
) {
@@ -465,7 +460,7 @@ function buildSessionRows(params: {
465460
}
466461

467462
function buildSessionListCases(
468-
sessions: unknown[],
463+
sessions: Array<{ key: string }>,
469464
matchBase: Record<string, unknown> = {},
470465
owners?: readonly SessionActorFixture[],
471466
): Array<{ match: Record<string, unknown>; response: unknown }> {
@@ -484,7 +479,7 @@ function buildSessionListCases(
484479
}
485480

486481
function buildSearchSessionListCases(
487-
sessions: unknown[],
482+
sessions: Array<{ key: string }>,
488483
searchTerms: string[],
489484
): Array<{ match: Record<string, unknown>; response: unknown }> {
490485
return searchTerms.flatMap((search) => buildSessionListCases(sessions, { search }));
@@ -1974,7 +1969,7 @@ async function createChatPickerScenario(
19741969
};
19751970
const planChatHistory = {
19761971
messages: historyMessages,
1977-
sessionId: "control-ui-e2e-session",
1972+
sessionId: "session:agent:main:main",
19781973
sessionInfo: planSessionInfo,
19791974
inFlightRun: planInFlightRun,
19801975
thinkingLevel: null,
@@ -3095,6 +3090,7 @@ async function createChatPickerScenario(
30953090
],
30963091
},
30973092
sessionArchiveFiltering: true,
3093+
sessions: [...sessions, ...archivedSessions, mainChildRow, taxChildRow],
30983094
sessionKey: fixture === "workboard" ? workboardMocks.sessionKey : "agent:main:main",
30993095
workspace: "/Users/peter/Projects/openclaw",
31003096
workspaceGit: true,
@@ -3426,7 +3422,9 @@ const server = await createServer({
34263422
});
34273423

34283424
await server.listen();
3429-
console.log(`[control-ui-mock] ${resolveServerUrl(server, options.host)}`);
3425+
console.log(
3426+
`[control-ui-mock] ${resolveServerUrl(server, options.host, controlUiSessionPath(scenario.sessionKey ?? "agent:main:main"))}`,
3427+
);
34303428
console.log(
34313429
`[control-ui-mock] board fixture: ${resolveServerUrl(server, options.host, boardFixturePath)}`,
34323430
);

‎ui/src/app/app-host.deleted-session.test.ts‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { afterEach, describe, expect, it, vi } from "vitest";
55
import { createDeferred } from "../../../test/helpers/promise.js";
66
import type { GatewayBrowserClient } from "../api/gateway.ts";
77
import type { RouteId } from "../app-routes.ts";
8-
import { storageTargetForGateway } from "../lib/chat/outbox-store.ts";
8+
import {
9+
readStoredOutboxStore,
10+
storageTargetForGateway,
11+
storedChatOutboxScopeKey,
12+
} from "../lib/chat/outbox-store.ts";
913
import { createSessionCapability } from "../lib/sessions/index.ts";
1014
import {
1115
createGatewayHarness,
@@ -258,7 +262,8 @@ describe("OpenClaw shell deleted-session recovery", () => {
258262
storage.setItem(
259263
storageKey,
260264
JSON.stringify({
261-
version: 3,
265+
version: 4,
266+
recovery: {},
262267
gatewayOwner: gatewayUrl,
263268
sessions: {
264269
[`${h.alpha.key}\u0000agent:main`]: {
@@ -302,7 +307,17 @@ describe("OpenClaw shell deleted-session recovery", () => {
302307
} else {
303308
h.sessions.reconcileChanged(currentDelete);
304309
}
305-
await vi.waitFor(() => expect(storage.getItem(storageKey)).not.toContain("B draft"));
310+
const target = storageTargetForGateway(gatewayUrl);
311+
const scopeKey = storedChatOutboxScopeKey({ sessionKey: h.alpha.key, agentId: "main" });
312+
const retired = h.sessions.state.deletedSessions.find(({ key }) => key === h.alpha.key)!;
313+
await vi.waitFor(() => {
314+
const tombstone = readStoredOutboxStore(storage, target).sessions[scopeKey];
315+
expect(tombstone).toEqual({
316+
draftRevision: expect.any(Number),
317+
updatedAt: expect.any(Number),
318+
});
319+
expect(tombstone?.draftRevision).toBeGreaterThan(retired.retireBeforeRevision);
320+
});
306321
expect(h.sessions.state.result?.sessions).toEqual([h.sibling]);
307322
expect(h.sessions.deletionState(h.alpha.key)).toBe("confirmed");
308323
expect(h.sessions.deletionState(h.sibling.key)).toBeUndefined();
@@ -322,7 +337,8 @@ describe("OpenClaw shell deleted-session recovery", () => {
322337
storage.setItem(
323338
storageKey,
324339
JSON.stringify({
325-
version: 3,
340+
version: 4,
341+
recovery: {},
326342
gatewayOwner: gatewayUrl,
327343
sessions: {
328344
[`${deletedKey}\u0000agent:main`]: {
@@ -367,13 +383,18 @@ describe("OpenClaw shell deleted-session recovery", () => {
367383
shell.observeDeletedSessions(state);
368384

369385
await vi.waitFor(() => {
370-
const stored = JSON.parse(storage.getItem(storageKey) ?? "{}") as {
371-
sessions?: Record<string, { draft?: string; queue?: unknown[] }>;
372-
};
373-
expect(stored.sessions?.[`${deletedKey}\u0000agent:main`]).toEqual({
386+
expect(
387+
storage.getItem(`openclaw.control.chatComposer.v2:${encodeURIComponent(gatewayUrl)}`),
388+
).toBeNull();
389+
const stored = readStoredOutboxStore(storage, storageTargetForGateway(gatewayUrl));
390+
const scopeKey = storedChatOutboxScopeKey({ sessionKey: deletedKey, agentId: "main" });
391+
expect(stored.sessions[scopeKey]).toEqual({
374392
draftRevision: expect.any(Number),
375393
updatedAt: expect.any(Number),
376394
});
395+
expect(stored.sessions[scopeKey]?.draftRevision).toBeGreaterThan(
396+
deletedSessions[0]!.retireBeforeRevision,
397+
);
377398
expect(toast.textContent).toContain(
378399
"Session deleted; browser draft remains. Clear site data.",
379400
);

0 commit comments

Comments
 (0)