Skip to content

Commit c9017e2

Browse files
committed
fix(ui): keep device-token session scope stable across transient drops
1 parent 1436a75 commit c9017e2

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎ui/src/pages/custodian/custodian-page.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,37 @@ describe("custodian page", () => {
217217
expect(page.textContent).toContain("Hello from OpenClaw.");
218218
});
219219

220+
it("keeps the device-token session scope while hello is gone during a drop", async () => {
221+
const request = vi.fn().mockResolvedValue({
222+
sessionId: "control-ui-onboarding-00000000-0000-4000-8000-000000000001",
223+
reply: "Device-token conversation.",
224+
action: "none",
225+
});
226+
const { context, setGatewaySnapshot, setGatewayDeviceToken } = createContext(request);
227+
setGatewayDeviceToken("stored-device-token");
228+
const { page } = await mountPage(context);
229+
await vi.waitFor(() => expect(page.textContent).toContain("Device-token conversation."));
230+
231+
// Transient drop: the retrying client stays but hello is cleared.
232+
setGatewaySnapshot({ client: null, connected: false, reconnecting: true, hello: null });
233+
await page.updateComplete;
234+
setGatewaySnapshot({
235+
client: { request } as unknown as GatewayBrowserClient,
236+
connected: true,
237+
reconnecting: false,
238+
hello: {
239+
type: "hello-ok" as const,
240+
protocol: 1,
241+
auth: { role: "operator", scopes: ["operator.admin"], deviceToken: "stored-device-token" },
242+
features: { methods: ["openclaw.chat"] },
243+
} as ApplicationGatewaySnapshot["hello"],
244+
});
245+
await page.updateComplete;
246+
247+
expect(request).toHaveBeenCalledOnce();
248+
expect(page.textContent).toContain("Device-token conversation.");
249+
});
250+
220251
it("offers retry when a connected client is replaced mid-request", async () => {
221252
const request = vi
222253
.fn()

‎ui/src/pages/custodian/custodian-page.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class CustodianPage extends OpenClawLightDomElement {
5959
private retryParams: SystemAgentChatParams | null = null;
6060
private sessionScopeKey: string | null = null;
6161
private sessionStarted = false;
62+
private lastHelloDeviceToken = "";
6263
private readonly subscriptions = new SubscriptionsController(this).watch(
6364
() => this.context?.gateway,
6465
(gateway, notify) => gateway.subscribe(notify),
@@ -90,8 +91,15 @@ export class CustodianPage extends OpenClawLightDomElement {
9091
*/
9192
private connectionScopeKey(): string {
9293
const { gatewayUrl, token, password, bootstrapToken } = this.context.gateway.connection;
93-
const deviceToken = this.context.gateway.snapshot.hello?.auth?.deviceToken ?? "";
94-
return JSON.stringify([gatewayUrl, token, password, bootstrapToken, deviceToken]);
94+
// Hello vanishes while the client retries a transient drop; keep the last
95+
// authenticated device token so a drop alone never crosses the session
96+
// boundary, while a new hello carrying a different stored-device token
97+
// still rotates the scope (shared-browser operator change).
98+
const hello = this.context.gateway.snapshot.hello;
99+
if (hello) {
100+
this.lastHelloDeviceToken = hello.auth?.deviceToken ?? "";
101+
}
102+
return JSON.stringify([gatewayUrl, token, password, bootstrapToken, this.lastHelloDeviceToken]);
95103
}
96104

97105
private synchronizeClient(): void {

0 commit comments

Comments
 (0)