Skip to content

Commit 6ed7750

Browse files
fix(web): switching a cold Claude thread to Codex no longer compacts first
ChatView offered Claude's resume compaction from the current conversation's context even when the composer's pick hands the thread off to another provider, so the send ran /compact on Codex before the message. The offer now requires that the send resumes the current conversation (no pending handoff), using the same rule as the handoff footer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7d0815f commit 6ed7750

2 files changed

Lines changed: 81 additions & 49 deletions

File tree

‎apps/web/src/components/ChatView.browser.test.tsx‎

Lines changed: 79 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { page, userEvent } from "vite-plus/test/browser";
1414
import "~/index.css";
1515

1616
import { AppRoot } from "~/AppRoot";
17+
// The thread route is code-split; loading ChatView with the file keeps that cost out of the test.
18+
import "~/components/ChatView";
1719
import { __setClientSettingsForTests } from "~/hooks/useSettings";
1820
import { getRouter } from "~/router";
1921
import {
@@ -40,27 +42,45 @@ vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
4042
trackRpcRequestSent: () => {},
4143
}));
4244

43-
const CLAUDE = ProviderInstanceId.make("claudeAgent");
44-
const CLAUDE_DRIVER = ProviderDriverKind.make("claudeAgent");
45-
46-
/** A Claude thread whose 250k-token context went cold long ago, with its native thread kept for handoff. */
47-
function coldClaudeThread() {
48-
const thread = threadWithHistory("thread-claude", 3, {
49-
instanceId: CLAUDE,
45+
const SIDES = {
46+
claude: {
47+
instanceId: ProviderInstanceId.make("claudeAgent"),
48+
driver: ProviderDriverKind.make("claudeAgent"),
5049
model: "claude-opus-4-6",
50+
label: "Claude Opus 4.6",
51+
search: "Claude",
52+
},
53+
codex: {
54+
instanceId: ProviderInstanceId.make("codex"),
55+
driver: ProviderDriverKind.make("codex"),
56+
model: "gpt-5.4",
57+
label: "GPT-5.4",
58+
search: "GPT",
59+
},
60+
};
61+
62+
/** A thread whose 250k-token context went cold long ago, with its native thread kept for handoff. */
63+
function coldThread(side: (typeof SIDES)[keyof typeof SIDES]) {
64+
const thread = threadWithHistory(`thread-${side.driver}`, 3, {
65+
instanceId: side.instanceId,
66+
model: side.model,
5167
});
5268
const updatedAt = DateTime.makeUnsafe("2026-03-17T19:12:28.000Z");
5369
return {
5470
...thread,
5571
providerThreads: [
5672
{
57-
id: ProviderThreadId.make("provider-thread-claude"),
58-
driver: CLAUDE_DRIVER,
59-
providerInstanceId: CLAUDE,
73+
id: ProviderThreadId.make(`provider-thread-${side.driver}`),
74+
driver: side.driver,
75+
providerInstanceId: side.instanceId,
6076
providerSessionId: null,
6177
appThreadId: thread.id,
6278
ownerNodeId: null,
63-
nativeThreadRef: { driver: CLAUDE_DRIVER, nativeId: "native-claude", strength: "strong" },
79+
nativeThreadRef: {
80+
driver: side.driver,
81+
nativeId: `native-${side.driver}`,
82+
strength: "strong",
83+
},
6484
nativeConversationHeadRef: null,
6585
status: "idle",
6686
firstRunOrdinal: 1,
@@ -78,44 +98,54 @@ function coldClaudeThread() {
7898
};
7999
}
80100

81-
it("sends a Codex follow-up on a cold Claude thread without compacting first", async () => {
82-
const thread = coldClaudeThread();
83-
using environment = installFakeEnvironment([thread], {
84-
providers: [CLAUDE_PROVIDER, CODEX_PROVIDER],
85-
});
86-
await page.viewport(1400, 900);
87-
__setClientSettingsForTests({
88-
...DEFAULT_CLIENT_SETTINGS,
89-
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
90-
});
91-
const router = getRouter(
92-
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${thread.id}`] }),
93-
);
94-
await router.load();
95-
const container = document.createElement("div");
96-
container.style.cssText = "height: 900px; width: 1400px;";
97-
// The app owns its router, as main.tsx does.
98-
await using _screen = await render(<AppRoot router={router} />, { container, router: false });
99-
await expect.element(page.getByText("Answer 2 for thread-claude.")).toBeVisible();
100-
await expect.element(page.getByRole("button", { name: "Compact and send" })).toBeVisible();
101+
it.each([
102+
{ from: SIDES.claude, to: SIDES.codex, offeredBefore: true },
103+
{ from: SIDES.codex, to: SIDES.claude, offeredBefore: false },
104+
])(
105+
"sends a $to.label follow-up on a cold $from.label thread without compacting first",
106+
async ({ from, to, offeredBefore }) => {
107+
const thread = coldThread(from);
108+
using environment = installFakeEnvironment([thread], {
109+
providers: [CLAUDE_PROVIDER, CODEX_PROVIDER],
110+
});
111+
await page.viewport(1400, 900);
112+
__setClientSettingsForTests({
113+
...DEFAULT_CLIENT_SETTINGS,
114+
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
115+
});
116+
const router = getRouter(
117+
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${thread.id}`] }),
118+
);
119+
await router.load();
120+
const container = document.createElement("div");
121+
container.style.cssText = "height: 900px; width: 1400px;";
122+
// The app owns its router, as main.tsx does.
123+
await using _screen = await render(<AppRoot router={router} />, { container, router: false });
124+
await expect.element(page.getByText(`Answer 2 for ${thread.id}.`)).toBeVisible();
125+
const compactAndSend = page.getByRole("button", { name: "Compact and send" });
126+
if (offeredBefore) {
127+
await expect.element(compactAndSend).toBeVisible();
128+
}
101129

102-
await userEvent.click(page.getByRole("button", { name: "Claude Opus 4.6" }));
103-
await userEvent.type(page.getByPlaceholder("Search models..."), "GPT");
104-
await userEvent.click(page.getByRole("option", { name: /GPT-5\.4/ }));
105-
await expect.element(page.getByRole("button", { name: "GPT-5.4" })).toBeVisible();
130+
await userEvent.click(page.getByRole("button", { name: from.label }));
131+
await userEvent.type(page.getByPlaceholder("Search models..."), to.search);
132+
await userEvent.click(page.getByRole("option", { name: to.label, exact: false }));
133+
await expect.element(page.getByRole("button", { name: to.label })).toBeVisible();
134+
await expect.element(compactAndSend).not.toBeInTheDocument();
106135

107-
const editor = page.getByTestId("composer-editor");
108-
await userEvent.click(editor);
109-
await userEvent.type(editor, "keep going");
110-
await userEvent.keyboard("{Enter}");
136+
const editor = page.getByTestId("composer-editor");
137+
await userEvent.click(editor);
138+
await userEvent.type(editor, "keep going");
139+
await userEvent.keyboard("{Enter}");
111140

112-
const messages = () =>
113-
environment.dispatchedCommands.flatMap((command) =>
114-
command.type === "message.dispatch"
115-
? [{ text: command.text, instanceId: command.modelSelection?.instanceId }]
116-
: [],
117-
);
118-
const sent = { text: "keep going", instanceId: "codex" };
119-
await vi.waitFor(() => expect(messages()).toContainEqual(sent));
120-
expect(messages()).toEqual([sent]);
121-
});
141+
const messages = () =>
142+
environment.dispatchedCommands.flatMap((command) =>
143+
command.type === "message.dispatch"
144+
? [{ text: command.text, instanceId: command.modelSelection?.instanceId }]
145+
: [],
146+
);
147+
const sent = { text: "keep going", instanceId: to.instanceId };
148+
await vi.waitFor(() => expect(messages()).toContainEqual(sent));
149+
expect(messages()).toEqual([sent]);
150+
},
151+
);

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,8 +2412,10 @@ export default function ChatView(props: ChatViewProps) {
24122412
? "Compaction is unavailable for this provider"
24132413
: "Compacting is unavailable right now"
24142414
: null;
2415+
// The context window is the current conversation's, so a handoff destination never inherits it.
24152416
const resumeCompactionTokens =
24162417
activeContextWindow &&
2418+
pendingHandoff === null &&
24172419
resolveIdleCompaction(
24182420
settings,
24192421
activeProviderInstanceId ?? ProviderInstanceId.make("claudeAgent"),

0 commit comments

Comments
 (0)