Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

send queued messages after interrupt (#2426)

kte2fb7bfa1372
diff --git a/packages/coding-agent/.changes/eng-5991-send-queued-after-interrupt.md b/packages/coding-agent/.changes/eng-5991-send-queued-after-interrupt.md
new file mode 100644
index 0000000000..86aa977625
--- /dev/null
+++ b/packages/coding-agent/.changes/eng-5991-send-queued-after-interrupt.md
@@ -0,0 +1 @@
+- Fixed Escape and Ctrl+C while steering messages are queued: the active run aborts and all queued user steering messages now start together in one new agent turn, preserving order and consuming the queue; an empty queue stays abort-only and the steering mode setting is unchanged.
diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts
index 53d350f456..92b2427680 100644
--- a/packages/coding-agent/src/core/agent-session.ts
+++ b/packages/coding-agent/src/core/agent-session.ts
@@ -1397,6 +1397,9 @@ export class AgentSession {
/** Session-owned actions. Items are never fed into Agent.steer/followUp. */
private readonly _actionStore = new ActionStore<QueuedSessionAction>();
+ // One-shot "all" steering batch armed by abortAndSendQueued: read on selection, never
+ // consumed on read, and disarmed once the armed actions leave the steering queue.
+ private _forcedAllSteeringActionIds: ReadonlySet<string> | undefined;
private _sessionInputPump: Promise<void> = Promise.resolve();
private _sessionInputPumpRequested = false;
// Invalidates preparation when a branch pause starts and finishes before its next await resumes.
@@ -6578,13 +6581,20 @@ export class AgentSession {
return;
}
- const mode = first.delivery === "next_turn_boundary" ? this.steeringMode : this.followUpMode;
+ const forcedAllSteeringActionIds = this._forcedAllSteeringBatch(first);
+ const mode =
+ forcedAllSteeringActionIds !== undefined
+ ? "all"
+ : first.delivery === "next_turn_boundary"
+ ? this.steeringMode
+ : this.followUpMode;
const actions: QueuedSessionAction[] = [first];
while (!preselected && mode === "all") {
const next = this._actionStore.queuedActions(first.delivery)[0];
if (
!next ||
next.payload.kind !== "turn" ||
+ (forcedAllSteeringActionIds !== undefined && !forcedAllSteeringActionIds.has(next.id)) ||
!turnExecutionPoliciesEqual(first.payload.executionPolicy, next.payload.executionPolicy)
) {
break;
@@ -7888,6 +7898,50 @@ export class AgentSession {
}
}
+ /**
+ * Abort the active run and deliver every queued user steering message in one new turn.
+ * Abort-only when the visible steering queue is empty or the scheduler must stay
+ * suspended; an update-restart suspension is left untouched. steeringMode is never changed.
+ */
+ abortAndSendQueued(): boolean {
+ // requestAbort would clear the restart flag, letting later admissions resume
+ // work during the restart window; abortForUpdateRestart already aborted the run.
+ if (this._sessionInputSuspendedForUpdateRestart) {
+ return false;
+ }
+ const queuedSteering = visibleSessionActionProjection(
+ this._actionStore.queuedActions("next_turn_boundary"),
+ ).filter(
+ (action) =>
+ action.payload.kind === "turn" &&
+ !action.payload.acceptedAgentMessage &&
+ primaryDeliveryRecord(action).message.role === "user",
+ );
+ const canResume =
+ !this._disposed &&
+ !this._disposing &&
+ this._sessionInputAdmissionPauses.size === 0 &&
+ this._queuedWorkPauses.size === 0;
+ if (queuedSteering.length === 0 || !canResume) {
+ this.requestAbort();
+ return false;
+ }
+ this._forcedAllSteeringActionIds = new Set(queuedSteering.map((action) => action.id));
+ this.requestAbort();
+ this.resumeQueuedWork();
+ return true;
+ }
+
+ private _forcedAllSteeringBatch(first: QueuedSessionAction): ReadonlySet<string> | undefined {
+ const armed = this._forcedAllSteeringActionIds;
+ if (armed === undefined) return undefined;
+ if (first.delivery === "next_turn_boundary" && armed.has(first.id)) return armed;
+ if (!this._actionStore.queuedActions("next_turn_boundary").some((action) => armed.has(action.id))) {
+ this._forcedAllSteeringActionIds = undefined;
+ }
+ return undefined;
+ }
+
abortForUpdateRestart(): void {
// Cancel scheduled pumps and suspend new ones: queued inputs must survive
// into the restart manifest instead of starting a turn during teardown.
diff --git a/packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts b/packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts
index 75d02f36c4..67c60fbbd8 100644
--- a/packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts
+++ b/packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts
@@ -1281,6 +1281,22 @@ export class DaemonAgentConnection implements AgentConnection {
await this.requestOk({ type: "abort", activeSessionId: this.activeSessionId });
}
+ async abortAndSendQueued(): Promise<void> {
+ if (!this.client.supportsServerCapability("abort_and_send_queued")) {
+ await this.abort();
+ return;
+ }
+ try {
+ await this.requestOk({ type: "abort_and_send_queued", activeSessionId: this.activeSessionId });
+ } catch (error) {
+ if (isUnknownDaemonCommandError(error, "abort_and_send_queued")) {
+ await this.abort();
+ return;
+ }
+ throw error;
+ }
+ }
+
async cancelRlmChild(childId: string): Promise<boolean> {
try {
const result = await this.requestData<{ cancelled: boolean }>({
diff --git a/packages/coding-agent/src/modes/agent-connection/in-process-agent-connection.ts b/packages/coding-agent/src/modes/agent-connection/in-process-agent-connection.ts
index f0ead7b0a1..bbbd3e4304 100644
--- a/packages/coding-agent/src/modes/agent-connection/in-process-agent-connection.ts
+++ b/packages/coding-agent/src/modes/agent-connection/in-process-agent-connection.ts
@@ -436,6 +436,10 @@ export class InProcessAgentConnection implements AgentConnection {
this.session.requestAbort();
}
+ async abortAndSendQueued(): Promise<void> {
+ this.session.abortAndSendQueued();
+ }
+
async cancelRlmChild(childId: string): Promise<boolean> {
return this.session.cancelRlmChildRun(childId);
}
diff --git a/packages/coding-agent/src/modes/agent-connection/types.ts b/packages/coding-agent/src/modes/agent-connection/types.ts
index fc297d4577..25edc233b2 100644
--- a/packages/coding-agent/src/modes/agent-connection/types.ts
+++ b/packages/coding-agent/src/modes/agent-connection/types.ts
@@ -747,6 +747,8 @@ export interface AgentConnection {
steer(message: string, images?: ImageContent[]): Promise<void>;
followUp(message: string, images?: ImageContent[]): Promise<void>;
abort(): Promise<void>;
+ /** Abort the active run and start all queued user steering together in one new turn; abort-only when the queue is empty. */
+ abortAndSendQueued(): Promise<void>;
cancelRlmChild(childId: string): Promise<boolean>;
waitForIdle(): Promise<void>;
waitForHeadlessCompletion(options?: AgentConnectionHeadlessCompletionOptions): Promise<AgentAutonomousStatus>;
diff --git a/packages/coding-agent/src/modes/daemon/daemon-mode.ts b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
index a4a8a01396..0f0ba4818d 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-mode.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
@@ -304,6 +304,7 @@ const DAEMON_COMMAND_TYPES: ReadonlySet<string> = new Set([
"agent_messages_resume",
"agent_messages_clear",
"abort",
+ "abort_and_send_queued",
"start_side_question",
"abort_side_question",
"execute_bash",
@@ -4752,6 +4753,12 @@ export class AgentDaemon {
return success(command.id, "abort");
}
+ case "abort_and_send_queued": {
+ const state = this.getSessionState(command.activeSessionId);
+ state.runtime.session.abortAndSendQueued();
+ return success(command.id, "abort_and_send_queued");
+ }
+
case "start_side_question": {
const state = this.getSessionState(command.activeSessionId);
if (this.sideQuestionRuns.has(command.sideQuestionId)) {
diff --git a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
index b864623536..9dd27f85ea 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
@@ -74,8 +74,9 @@ export const DAEMON_COMMAND_ENVELOPE_MIN_PROTOCOL_VERSION = 7;
// Revision 26 publishes own-session usage totals on session summary and saved-session rows.
// Revision 27 adds structured session_recovering failure info for known-but-unaddressable sessions.
// Revision 28 publishes the last recorded model on saved-session rows.
-export const DAEMON_SCHEMA_REVISION = 28;
-export const DAEMON_SCHEMA_ID = "protocol-7-schema-28-92bc5368a082";
+// Revision 29 adds the capability-gated abort_and_send_queued command.
+export const DAEMON_SCHEMA_REVISION = 29;
+export const DAEMON_SCHEMA_ID = "protocol-7-schema-29-a5c9d20f8b13";
export type DaemonProtocolName = typeof DAEMON_PROTOCOL_NAME;
export type DaemonProtocolVersion = number;
@@ -122,7 +123,8 @@ export type DaemonServerCapability =
| "session_input_pause"
| "owned_prompt_cancellation"
| "acp_mcp_servers"
- | "direct_peer_transport";
+ | "direct_peer_transport"
+ | "abort_and_send_queued";
export type DaemonReplayStatus = "complete" | "partial" | "unavailable";
@@ -167,6 +169,7 @@ export const DAEMON_DEFAULT_SERVER_CAPABILITIES: readonly DaemonServerCapability
"rlm_quiescence_barrier",
"session_input_pause",
"acp_mcp_servers",
+ "abort_and_send_queued",
];
/** Single-use short-lived credential for one direct TUI connection to one worker process incarnation. */
@@ -528,6 +531,7 @@ export type DaemonCommand =
| { id?: string; type: "agent_messages_resume"; activeSessionId?: string }
| { id?: string; type: "agent_messages_clear"; activeSessionId: string }
| { id?: string; type: "abort"; activeSessionId: string }
+ | { id?: string; type: "abort_and_send_queued"; activeSessionId: string }
| {
id?: string;
type: "start_side_question";
@@ -774,6 +778,7 @@ export const DAEMON_COMMAND_COMPATIBILITY = {
agent_messages_resume: LEGACY_DAEMON_COMMAND,
agent_messages_clear: LEGACY_DAEMON_COMMAND,
abort: LEGACY_DAEMON_COMMAND,
+ abort_and_send_queued: { minProtocol: 7, minSchemaRevision: 29, capability: "abort_and_send_queued" },
start_side_question: LEGACY_DAEMON_COMMAND,
abort_side_question: LEGACY_DAEMON_COMMAND,
execute_bash: LEGACY_DAEMON_COMMAND,
@@ -892,6 +897,7 @@ export const DAEMON_COMMAND_PLANE = {
agent_messages_resume: "control",
agent_messages_clear: "control",
abort: "session",
+ abort_and_send_queued: "session",
start_side_question: "session",
abort_side_question: "session",
execute_bash: "session",
diff --git a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
index b77a9e5b14..ab57860ec4 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
@@ -272,6 +272,7 @@ const DAEMON_COMMAND_TYPES: ReadonlySet<string> = new Set([
"agent_messages_resume",
"agent_messages_clear",
"abort",
+ "abort_and_send_queued",
"start_side_question",
"abort_side_question",
"execute_bash",
diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
index b7370196e5..d3c70ded7b 100644
--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts
+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
@@ -7358,9 +7358,7 @@ export class InteractiveMode {
void this.agentConnection.abortBash();
}
if (this.isAgentStreaming()) {
- // The queue is preserved server-side; draining resumes on the next
- // submit or queued-message edit.
- void this.agentConnection.abort().catch((error) => {
+ void this.agentConnection.abortAndSendQueued().catch((error) => {
this.showError(error instanceof Error ? error.message : String(error));
});
}
diff --git a/packages/coding-agent/test/agent-connection-daemon.test.ts b/packages/coding-agent/test/agent-connection-daemon.test.ts
index f58e392501..cb21a9cfd2 100644
--- a/packages/coding-agent/test/agent-connection-daemon.test.ts
+++ b/packages/coding-agent/test/agent-connection-daemon.test.ts
@@ -23,6 +23,8 @@ import {
type DaemonCommand,
type DaemonOutbound,
type DaemonResponse,
+ failure,
+ success,
} from "../src/modes/daemon/daemon-protocol.js";
import { DaemonRoutedClient } from "../src/modes/daemon/daemon-routed-client.js";
import type { DaemonWorkerClient } from "../src/modes/daemon/daemon-worker-client.js";
@@ -49,6 +51,7 @@ class FakeDaemonClient {
rlmChildrenGate: Promise<void> | undefined;
abortBashUnknownCommand = false;
abortAndClearQueueUnknownCommand = false;
+ abortAndSendQueuedUnknownCommand = false;
inputPauseAcquireGate: Promise<void> | undefined;
cronAddGate: Promise<void> | undefined;
promptGate: Promise<void> | undefined;
@@ -262,6 +265,8 @@ class FakeDaemonClient {
},
},
};
+ case "abort":
+ return success(command.id, command.type);
case "clear_queue":
return {
type: "response",
@@ -284,6 +289,10 @@ class FakeDaemonClient {
success: true,
data: { steering: ["aborted"], followUp: ["cleared"] },
};
+ case "abort_and_send_queued":
+ return this.abortAndSendQueuedUnknownCommand
+ ? failure(command.id, command.type, "Unknown daemon command: abort_and_send_queued")
+ : success(command.id, command.type);
case "acquire_session_input_pause":
if (this.inputPauseAcquireGate) await this.inputPauseAcquireGate;
return {
@@ -3562,4 +3571,20 @@ describe("DaemonAgentConnection deferred session events", () => {
await connection.dispose();
}
});
+
+ it("sends abort_and_send_queued only behind the advertised daemon capability", async () => {
+ const send = (client: FakeDaemonClient) =>
+ new DaemonAgentConnection(asDaemonClient(client), "active-1").abortAndSendQueued();
+ const capable = new FakeDaemonClient();
+ capable.serverCapabilities.add("abort_and_send_queued");
+ await expect(send(capable)).resolves.toBeUndefined();
+ expect(capable.requests).toEqual([{ type: "abort_and_send_queued", activeSessionId: "active-1" }]);
+ const older = new FakeDaemonClient();
+ await expect(send(older)).resolves.toBeUndefined();
+ expect(older.requests).toEqual([{ type: "abort", activeSessionId: "active-1" }]);
+ const stale = Object.assign(new FakeDaemonClient(), { abortAndSendQueuedUnknownCommand: true });
+ stale.serverCapabilities.add("abort_and_send_queued");
+ await expect(send(stale)).resolves.toBeUndefined();
+ expect(stale.requests.map(({ type }) => type)).toEqual(["abort_and_send_queued", "abort"]);
+ });
});
diff --git a/packages/coding-agent/test/daemon-protocol.test.ts b/packages/coding-agent/test/daemon-protocol.test.ts
index 1a6536ceea..d3bca27f93 100644
--- a/packages/coding-agent/test/daemon-protocol.test.ts
+++ b/packages/coding-agent/test/daemon-protocol.test.ts
@@ -29,6 +29,7 @@ describe("daemon protocol helpers", () => {
["replace_acp_mcp_servers", { minProtocol: 7, minSchemaRevision: 22, capability: "acp_mcp_servers" }, true],
["get_model_catalog", { minProtocol: 7, capability: "model_catalog" }, true],
["mutate_queued_message", { minProtocol: 7, minSchemaRevision: 15, capability: "queue_message_mutation" }, true],
+ ["abort_and_send_queued", { minProtocol: 7, minSchemaRevision: 29, capability: "abort_and_send_queued" }, true],
["get_rlm_max_depth_status", { minProtocol: 7, minSchemaRevision: 11 }, undefined],
["set_rlm_max_depth", { minProtocol: 7, minSchemaRevision: 11 }, undefined],
[
diff --git a/packages/coding-agent/test/interactive-queue-edit.test.ts b/packages/coding-agent/test/interactive-queue-edit.test.ts
index 8757b3e39a..916a70733d 100644
--- a/packages/coding-agent/test/interactive-queue-edit.test.ts
+++ b/packages/coding-agent/test/interactive-queue-edit.test.ts
@@ -586,6 +586,7 @@ describe("interactive interrupt preserves the queue", () => {
isAgentStreaming: () => true,
agentConnection: {
abort: vi.fn(async () => {}),
+ abortAndSendQueued: vi.fn(async () => {}),
abortBash: vi.fn(),
clearQueue: vi.fn(async () => ({ steering: [], followUp: [] })),
abortAndClearQueue: vi.fn(async () => ({ steering: [], followUp: [] })),
@@ -603,12 +604,13 @@ describe("interactive interrupt preserves the queue", () => {
return harness as unknown as InterruptHarness;
}
- it("aborts streaming without clearing or restoring the queue or the draft", () => {
+ it("interrupts streaming by aborting and sending the queued messages without clearing the queue or the draft", () => {
const harness = createInterruptHarness("draft");
Reflect.get(InteractiveMode.prototype, "handleCtrlC").call(harness);
- expect(harness.agentConnection.abort).toHaveBeenCalledOnce();
+ expect(harness.agentConnection.abortAndSendQueued).toHaveBeenCalledOnce();
+ expect(harness.agentConnection.abort).not.toHaveBeenCalled();
expect(harness.agentConnection.abortAndClearQueue).not.toHaveBeenCalled();
expect(harness.agentConnection.clearQueue).not.toHaveBeenCalled();
expect(harness.editor.setText).not.toHaveBeenCalled();
@@ -628,7 +630,7 @@ describe("interactive interrupt preserves the queue", () => {
handleCtrlC.call(harness);
// The interrupt runs once; the repeat exits instead of aborting again.
- expect(harness.agentConnection.abort).toHaveBeenCalledOnce();
+ expect(harness.agentConnection.abortAndSendQueued).toHaveBeenCalledOnce();
expect(harness.shutdown).toHaveBeenCalledOnce();
});
});
diff --git a/packages/coding-agent/test/suite/agent-session-queue.test.ts b/packages/coding-agent/test/suite/agent-session-queue.test.ts
index a27c3e259d..76d2ce83e8 100644
--- a/packages/coding-agent/test/suite/agent-session-queue.test.ts
+++ b/packages/coding-agent/test/suite/agent-session-queue.test.ts
@@ -1668,6 +1668,40 @@ describe("AgentSession queue regressions", () => {
}
});
+ it("ENG-5991: interrupt delivers every queued steering message in one new turn and stays abort-only at the edges", async () => {
+ const { harness, waitForToolStart, promptPromise, releaseToolExecution } = await createWaitingHarness();
+ harnesses.push(harness);
+ harness.setResponses([
+ fauxAssistantMessage(fauxToolCall("wait", {}), { stopReason: "toolUse" }),
+ fauxAssistantMessage("queued handled"),
+ fauxAssistantMessage("injected handled"),
+ fauxAssistantMessage("later handled"),
+ ]);
+ await waitForToolStart;
+ await harness.session.steer("first");
+ await completeShell(harness);
+ await harness.session.steer("second");
+ expect(harness.session.abortAndSendQueued()).toBe(true);
+ await harness.session.steer("later", undefined, { priority: "background" });
+ releaseToolExecution();
+ await Promise.all([promptPromise, harness.session.waitForIdle()]);
+ expect(getUserTexts(harness)).toEqual(["start", "first", "second", "later"]);
+ expect(getAssistantTexts(harness)).toEqual(["", "queued handled", "injected handled", "later handled"]);
+ expect(harness.session.steeringMode).toBe("one-at-a-time");
+ await harness.session.followUp("follow-up boundary");
+ expect(harness.session.abortAndSendQueued()).toBe(false);
+ expect(harness.session.getFollowUpMessages()).toEqual(["follow-up boundary"]);
+ harness.session.clearQueue();
+ harness.session.resumeQueuedWork();
+ await harness.session.steer("queued for restart");
+ harness.session.abortForUpdateRestart();
+ expect(harness.session.abortAndSendQueued()).toBe(false);
+ expect(harness.session.getSteeringMessages()).toEqual(["queued for restart"]);
+ await expect(
+ harness.session.sendCustomMessage({ customType: "g", content: "t", display: false }, { triggerTurn: true }),
+ ).rejects.toThrow("queued session input is suspended");
+ });
+
it("ENG-4531: persists sent agent messages that arrive after their Python cell completes", async () => {
const harness = await createHarness();
harnesses.push(harness);