Skip to content

Commit 16aaf5b

Browse files
juliusmarmingefixfonclaude
authored
fix(web): instructed compact runs without a bare compaction first (#24008)
Co-authored-by: fixfon <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 6ba8078 commit 16aaf5b

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,14 +1102,21 @@ describe("planComposerTurn", () => {
11021102
});
11031103

11041104
it("queues behind a compaction of a stale session, except for /compact itself", () => {
1105-
expect(planComposerTurn({ ...base, resumeCompactionTokens: 120_000 })).toMatchObject({
1106-
compactBeforeSend: true,
1107-
turnDispatchMode: "queue",
1108-
shouldQueueBehindActiveRun: true,
1109-
});
1110-
expect(
1111-
planComposerTurn({ ...base, resumeCompactionTokens: 120_000, messageText: "/COMPACT" }),
1112-
).toMatchObject({ compactBeforeSend: false, turnDispatchMode: "auto" });
1105+
const stale = { ...base, resumeCompactionTokens: 120_000 };
1106+
for (const messageText of ["hello", "/compactfoo"]) {
1107+
expect(planComposerTurn({ ...stale, messageText })).toMatchObject({
1108+
compactBeforeSend: true,
1109+
turnDispatchMode: "queue",
1110+
shouldQueueBehindActiveRun: true,
1111+
});
1112+
}
1113+
for (const messageText of ["/COMPACT", "/compact keep the API notes", "/compact\n tests"]) {
1114+
expect(planComposerTurn({ ...stale, messageText })).toMatchObject({
1115+
compactBeforeSend: false,
1116+
turnDispatchMode: "auto",
1117+
shouldQueueBehindActiveRun: false,
1118+
});
1119+
}
11131120
});
11141121

11151122
it("queues behind a running turn only when asked to", () => {

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,10 @@ export function shouldShowPlanFollowUpPrompt(input: {
931931
);
932932
}
933933

934+
// A typed `/compact`, with or without instructions, is already the compaction. Queueing a
935+
// bare one ahead of it would run an uninstructed compaction first and charge for two.
936+
const COMPACT_COMMAND_PATTERN = /^\/compact(?:\s|$)/i;
937+
934938
const sessionDismissedBranchMismatchKeys = new Set<string>();
935939

936940
export function dismissBranchMismatchForSession(key: string): void {
@@ -1541,7 +1545,7 @@ export function planComposerTurn(input: {
15411545
const compactBeforeSend =
15421546
input.resumeCompactionTokens !== null &&
15431547
!input.keepFullHistory &&
1544-
input.messageText.toLowerCase() !== "/compact";
1548+
!COMPACT_COMMAND_PATTERN.test(input.messageText);
15451549
return {
15461550
// In worktree mode, require an explicit base branch so we don't silently
15471551
// fall back to local execution when branch selection is missing.

0 commit comments

Comments
 (0)