From b0ae8ad0beab6587c0ac5f9bd66b3f86b76de397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E9=98=B3?= Date: Thu, 7 May 2026 15:52:12 +0800 Subject: [PATCH] Clear stale active session ids --- frontend/app/app/api/claw/context-budget/route.ts | 6 +++++- frontend/app/components/assistant-ui/thread.tsx | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/app/app/api/claw/context-budget/route.ts b/frontend/app/app/api/claw/context-budget/route.ts index 74bc77b..098a603 100644 --- a/frontend/app/app/api/claw/context-budget/route.ts +++ b/frontend/app/app/api/claw/context-budget/route.ts @@ -14,7 +14,11 @@ export async function GET(req: Request) { if (sessionId) url.searchParams.set("session_id", sessionId); try { - const response = await fetch(url, { cache: "no-store" }); + let response = await fetch(url, { cache: "no-store" }); + if (response.status === 404 && sessionId) { + url.searchParams.delete("session_id"); + response = await fetch(url, { cache: "no-store" }); + } const payload = await response.text(); return new Response(payload, { status: response.status, diff --git a/frontend/app/components/assistant-ui/thread.tsx b/frontend/app/components/assistant-ui/thread.tsx index a24fc6e..143f9e7 100644 --- a/frontend/app/components/assistant-ui/thread.tsx +++ b/frontend/app/components/assistant-ui/thread.tsx @@ -549,7 +549,7 @@ function useComposerContextStatus() { const statePayload = stateResponse.ok ? ((await stateResponse.json()) as ClawState) : {}; - const sessionId = normalizeSessionId( + let sessionId = normalizeSessionId( normalizeSessionId(latestSessionId) || normalizeSessionId( window.localStorage.getItem("claw.activeSessionId"), @@ -567,9 +567,13 @@ function useComposerContextStatus() { cache: "no-store", }, ); - sessionPayload = sessionResponse.ok - ? ((await sessionResponse.json()) as ClawStoredSession) - : null; + if (sessionResponse.ok) { + sessionPayload = + (await sessionResponse.json()) as ClawStoredSession; + } else if (sessionResponse.status === 404) { + window.localStorage.removeItem("claw.activeSessionId"); + sessionId = null; + } } const budgetUrl = new URL( "/api/claw/context-budget",