diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts index f9545f333f9..42dffb9802d 100644 --- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts +++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts @@ -4044,10 +4044,12 @@ export class InteractiveMode { await this.session.prompt(message.text); } - // Send first prompt (starts streaming) - const promptPromise = this.session.prompt(firstPrompt.text).catch((error) => { - restoreQueue(error); - }); + // Start a prompt when idle, or queue it into a run still finishing compaction. + const promptPromise = this.session + .prompt(firstPrompt.text, { streamingBehavior: firstPrompt.mode }) + .catch((error) => { + restoreQueue(error); + }); // Queue remaining messages for (const message of rest) { diff --git a/packages/coding-agent/test/interactive-mode-compaction.test.ts b/packages/coding-agent/test/interactive-mode-compaction.test.ts index 39bcb511df4..dd019f8f4dd 100644 --- a/packages/coding-agent/test/interactive-mode-compaction.test.ts +++ b/packages/coding-agent/test/interactive-mode-compaction.test.ts @@ -56,4 +56,30 @@ describe("InteractiveMode compaction events", () => { ); expect(fakeThis.flushCompactionQueue).toHaveBeenCalledWith({ willRetry: false }); }); + + test("preserves steering behavior when flushing into an active agent run", async () => { + const fakeThis = { + compactionQueuedMessages: [{ text: "change direction", mode: "steer" as const }], + session: { + clearQueue: vi.fn(), + prompt: vi.fn().mockResolvedValue(undefined), + steer: vi.fn().mockResolvedValue(undefined), + followUp: vi.fn().mockResolvedValue(undefined), + }, + isExtensionCommand: vi.fn().mockReturnValue(false), + updatePendingMessagesDisplay: vi.fn(), + showError: vi.fn(), + }; + + const flushCompactionQueue = Reflect.get(InteractiveMode.prototype, "flushCompactionQueue") as ( + this: typeof fakeThis, + options?: { willRetry?: boolean }, + ) => Promise; + + await flushCompactionQueue.call(fakeThis, { willRetry: false }); + + expect(fakeThis.session.prompt).toHaveBeenCalledWith("change direction", { streamingBehavior: "steer" }); + expect(fakeThis.compactionQueuedMessages).toEqual([]); + expect(fakeThis.showError).not.toHaveBeenCalled(); + }); });