A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix(coding-agent): release print session on SIGINT (#604)
Sebastian Müller276b6404e6e7
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex 22fbfec006..cceeec315d 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -3,6 +3,7 @@## [Unreleased]- Fixed `stop` and `rename` rejecting custom daemon socket options.+- Fixed SIGINT in print mode leaving the session active until liveness reclaim.## [0.5.1] - 2026-08-04diff --git a/packages/coding-agent/src/modes/print-mode.ts b/packages/coding-agent/src/modes/print-mode.tsindex 5435c6f166..c586de9cb0 100644--- a/packages/coding-agent/src/modes/print-mode.ts+++ b/packages/coding-agent/src/modes/print-mode.ts@@ -77,11 +77,16 @@ async function runPrintModeWithConnectionInternal(await connection.dispose();};- for (const signal of ["SIGTERM", ...(process.platform === "win32" ? [] : ["SIGHUP"])] as NodeJS.Signals[]) {+ for (const signal of [+ "SIGINT",+ "SIGTERM",+ ...(process.platform === "win32" ? [] : ["SIGHUP"]),+ ] as NodeJS.Signals[]) {const handler = () => {killTrackedDetachedChildren();void disposeConnection().finally(() => {- process.exit(signal === "SIGHUP" ? 129 : 143);+ const exitCode = signal === "SIGINT" ? 130 : signal === "SIGHUP" ? 129 : 143;+ process.exit(exitCode);});};process.on(signal, handler);diff --git a/packages/coding-agent/test/print-mode.test.ts b/packages/coding-agent/test/print-mode.test.tsindex 1c64bb1438..100a03be8d 100644--- a/packages/coding-agent/test/print-mode.test.ts+++ b/packages/coding-agent/test/print-mode.test.ts@@ -16,6 +16,9 @@ vi.mock("../src/core/output-guard.js", () => ({writeRawStdout: output.write,flushRawStdout: output.flush,}));+vi.mock("../src/utils/shell.js", () => ({+ killTrackedDetachedChildren: vi.fn(),+}));type EmitEvent = SessionShutdownEvent;@@ -145,6 +148,36 @@ describe("runPrintMode", () => {expect(session.extensionRunner.emit).toHaveBeenCalledWith({ type: "session_shutdown", reason: "quit" });});+ it("disposes the connection before exiting on SIGINT", async () => {+ const runtimeHost = createRuntimeHost(createAssistantMessage({ text: "done" }));+ const { session } = runtimeHost;+ let resolvePrompt: (() => void) | undefined;+ session.promptAndWait.mockImplementation(+ () =>+ new Promise<void>((resolve) => {+ resolvePrompt = resolve;+ }),+ );+ const onSpy = vi.spyOn(process, "on");+ const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => undefined) as typeof process.exit);++ const runPromise = runPrintMode(runtimeHost as unknown as Parameters<typeof runPrintMode>[0], {+ mode: "text",+ initialMessage: "Wait",+ });+ await vi.waitFor(() => expect(session.promptAndWait).toHaveBeenCalled());+ const handler = onSpy.mock.calls.find(([event]) => event === "SIGINT")?.[1];+ if (typeof handler !== "function") throw new Error("SIGINT handler was not registered");++ handler();++ await vi.waitFor(() => expect(exitSpy).toHaveBeenCalledWith(130));+ expect(runtimeHost.dispose).toHaveBeenCalledTimes(1);+ expect(session.extensionRunner.emit).toHaveBeenCalledWith({ type: "session_shutdown", reason: "quit" });+ resolvePrompt?.();+ await expect(runPromise).resolves.toBe(0);+ });+it("prints successful session command results in text mode", async () => {const result = createSessionSlashCommandResultMessage("No active goal.", {command: { name: "goal", args: "status", text: "/goal status" },