From 481c4b3709532c1b4723eb1ea98febb61232771b Mon Sep 17 00:00:00 2001 From: viktorce Date: Wed, 18 Nov 2026 10:56:41 +0000 Subject: [PATCH] fix(web): the Compact chip no longer shows after /clear On a Claude thread left idle past its prompt cache, the composer shows a Compact chip and gives Send the accessible name "Compact and send". After /clear, the next message starts a fresh session, which never compacts, yet the chip and that name stayed. Mobile already hides its chip in this state, and web now does too. The offer hides until the next message is sent, and comes back if the user keeps the current session. At phone width, the collapsed composer's button now sends in this state instead of opening the composer to offer a compaction. The web fake environment advertises freshContext, as the real server does, so browser tests can use /clear. --- ...hatView.handoffCompaction.browser.test.tsx | 46 ++++++++++++++++++- apps/web/src/components/ChatView.tsx | 13 ++++-- apps/web/test/fakeEnvironment.ts | 2 +- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/ChatView.handoffCompaction.browser.test.tsx b/apps/web/src/components/ChatView.handoffCompaction.browser.test.tsx index ca6cc6ab95c0..40ad071fc958 100644 --- a/apps/web/src/components/ChatView.handoffCompaction.browser.test.tsx +++ b/apps/web/src/components/ChatView.handoffCompaction.browser.test.tsx @@ -47,8 +47,8 @@ const CLAUDE = ProviderInstanceId.make("claudeAgent"); const CLAUDE_DRIVER = ProviderDriverKind.make("claudeAgent"); /** A Claude thread whose 250k-token context went cold long ago, with its native thread kept for handoff. */ -function coldClaudeThread() { - const thread = threadWithHistory("thread-claude", 3, { +function coldClaudeThread(threadId = "thread-claude") { + const thread = threadWithHistory(threadId, 3, { instanceId: CLAUDE, model: "claude-opus-4-6", }); @@ -123,3 +123,45 @@ it("sends a Codex follow-up on a cold Claude thread without compacting first", a await vi.waitFor(() => expect(messages()).toContainEqual(sent)); expect(messages()).toEqual([sent]); }); + +it("drops the compact offer on a cold Claude thread while /clear is armed", async () => { + // At phone width, dismissing the fresh-session notice collapses the composer and hides the chip. + const viewport = { width: window.innerWidth, height: window.innerHeight }; + await page.viewport(1280, 800); + await using _viewport = { + [Symbol.asyncDispose]: () => page.viewport(viewport.width, viewport.height), + }; + // The first test's model pick stays on thread-claude's draft, so this one uses its own thread. + const thread = coldClaudeThread("thread-claude-cleared"); + using _environment = installFakeEnvironment([thread], { providers: [CLAUDE_PROVIDER] }); + __setClientSettingsForTests({ + ...DEFAULT_CLIENT_SETTINGS, + onboardingCompletedAt: "2026-01-01T00:00:00.000Z", + }); + const router = getRouter( + createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${thread.id}`] }), + ); + await router.load(); + await using _app = await render(, { + // AppRoot brings its own router. + router: false, + }); + await expect.element(page.getByText(`Answer 2 for ${thread.id}.`)).toBeVisible(); + const chip = page.getByRole("button", { name: "Compact 250k tokens of history before sending" }); + const compactAndSend = page.getByRole("button", { name: "Compact and send" }); + await expect.element(chip).toBeVisible(); + await expect.element(compactAndSend).toBeVisible(); + + const editor = page.getByTestId("composer-editor"); + await userEvent.click(editor); + await userEvent.type(editor, "/clear"); + await userEvent.keyboard("{Enter}"); + await expect.element(page.getByText("Your next message starts a fresh session")).toBeVisible(); + await expect.element(chip).not.toBeInTheDocument(); + await expect.element(compactAndSend).not.toBeInTheDocument(); + await expect.element(page.getByRole("button", { name: "Submit message" })).toBeVisible(); + + await page.getByRole("button", { name: "Keep the current session" }).click(); + await expect.element(chip).toBeVisible(); + await expect.element(compactAndSend).toBeVisible(); +}); diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index a731a5798e19..e6f0fc79ecb6 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -2540,10 +2540,16 @@ export default function ChatView(props: ChatViewProps) { pendingApprovals.length > 0 || pendingUserInputs.length > 0; const compactDisabled = compactThreadUnavailable; - // The context window is the current conversation's, so a handoff destination never inherits it. + const freshSessionAvailable = + activeMessageCount > 0 && serverConfig?.environment.capabilities.freshContext === true; + const freshSessionArmed = useFreshSessionArmed(routeThreadKey); + const freshSessionPending = freshSessionAvailable && freshSessionArmed; + // The context window is the current conversation's, so neither a handoff destination nor + // the fresh session armed by /clear inherits it. const resumeCompactionTokens = activeContextWindow && pendingHandoff === null && + !freshSessionPending && resolveIdleCompaction( settings, activeProviderInstanceId ?? ProviderInstanceId.make("claudeAgent"), @@ -2575,12 +2581,9 @@ export default function ChatView(props: ChatViewProps) { return next; }); }; - const freshSessionAvailable = - activeMessageCount > 0 && serverConfig?.environment.capabilities.freshContext === true; // While a question or approval owns the composer, its text answers that, not the agent. const freshSessionCommandAvailable = freshSessionAvailable && activePendingApproval === null && pendingUserInputs.length === 0; - const freshSessionArmed = useFreshSessionArmed(routeThreadKey); const toggleKeepFullHistory = () => setKeepFullHistory(routeThreadKey, !keepFullHistory); const toggleKeepFullHistoryStable = useStableCallback(toggleKeepFullHistory); const armFreshSessionStable = useStableCallback(() => armFreshSession(routeThreadKey)); @@ -2690,7 +2693,7 @@ export default function ChatView(props: ChatViewProps) { const projectCloneItems = projectCloneBannerItem === null ? [] : [projectCloneBannerItem]; // An approval's feedback goes to that approval; the armed session waits for the next message. const freshSessionItems = - freshSessionAvailable && freshSessionArmed && activePendingApproval === null + freshSessionPending && activePendingApproval === null ? [freshSessionBannerItem(() => disarmFreshSession(routeThreadKey), messages)] : []; if (!localCheckoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) { diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts index 3146de25b1c4..7fd89bf48a9f 100644 --- a/apps/web/test/fakeEnvironment.ts +++ b/apps/web/test/fakeEnvironment.ts @@ -67,7 +67,7 @@ const descriptor = { // A matching version, since a mismatch adds an update banner a typical user never sees. serverVersion: APP_VERSION, orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION, - capabilities: { repositoryIdentity: true, sideChats: true }, + capabilities: { repositoryIdentity: true, sideChats: true, freshContext: true }, }; const auth = { policy: "loopback-browser",