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
30 changes: 30 additions & 0 deletions apps/desktop/src/state/autoCompact.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@ describe("requested compaction", () => {
expect(isRunning(thread)).toBe(false);
});

test("a queued turn that runs after a requested compaction can request the next one", async () => {
const id = await openClaudeThread(10);
const first = runPrompt(id, "yolo, finish this task first", emptyExtras);
expect(requestCompaction(id, false)).toBe(true);
void runPrompt(id, "yolo, the queued wake", emptyExtras);
await until(
() =>
isRunning(useApp.getState().threads[id]) &&
(useApp
.getState()
.threads[id]?.items.some((item) => item.kind === "user" && item.text === "yolo, the queued wake") ??
false),
10_000,
);

expect(requestCompaction(id, true)).toBe(true);
await first;
const thread = useApp.getState().threads[id]!;
const compactions = thread.items.filter(
(item) => item.kind === "notice" && item.text.startsWith("Context compacted"),
);
expect(compactions).toHaveLength(2);
await until(
() =>
useApp.getState().threads[id]?.items.some((item) => item.kind === "user" && item.continued) ?? false,
10_000,
);
await cancel(id);
}, 30_000);

test("continues once when requested", async () => {
const id = await openClaudeThread(10);
expect(requestCompaction(id, true)).toBe(true);
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop/src/state/autoCompactRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ export async function runRequestedCompaction(id: string): Promise<void> {
}
}

/**
* The requested `/compact` turn itself ended. `runPrompt` goes on to start the thread's queue before it
* returns, and a turn from that queue may ask for its own compaction.
*/
export function requestedCompactionEnded(id: string): void {
requestedCompactionsRunning.delete(id);
}

export function cancelRequestedCompaction(id: string): void {
requestedCompactions.delete(id);
}
Expand Down
6 changes: 5 additions & 1 deletion apps/desktop/src/state/promptRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { uploadPromptImages } from "./attachmentTransfer";
import {
beginAutoCompactIdle,
cancelRequestedCompaction,
requestedCompactionEnded,
runRequestedCompaction,
scheduleAutoCompact,
} from "./autoCompactRun";
Expand Down Expand Up @@ -351,7 +352,10 @@ export async function runPrompt(
...(options.requestedCompaction && previousQueueHold ? { queueHeld: true } : {}),
...(rawFailure !== failure ? { errorDetail: rawFailure } : {}),
}));
if (options.requestedCompaction) updateThread(id, (t) => settleCompaction(t, null));
if (options.requestedCompaction) {
updateThread(id, (t) => settleCompaction(t, null));
requestedCompactionEnded(id);
}
// Steers the turn never read wait as turns of their own, and carry the links they came from.
if (!options.autoCompact) requeueUnreadSteers(id, unused);
// The stop is settled first: a turn it stopped is reported as the stop, not twice.
Expand Down
Loading