Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down Expand Up @@ -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 router={router} />, {
// 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();
});
13 changes: 8 additions & 5 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/test/fakeEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading