diff --git a/apps/web/src/components/ChatView.handoffCompaction.browser.test.tsx b/apps/web/src/components/ChatView.handoffCompaction.browser.test.tsx index ca6cc6ab95c00..40ad071fc958d 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 a731a5798e191..e6f0fc79ecb62 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 3146de25b1c45..7fd89bf48a9f5 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",