Skip to content

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

Rust

fix(coding-agent): survive kernel cold boots and stop leaking raw zmq EAGAIN (#1587)

Sebastian Müller55277ff38677
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 0f7510c5a3..d02e2bc545 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fixed first IPython calls after an upgrade failing with a raw "Operation was not possible or timed out": kernel startup now tolerates cold venv boots (30s budget; crashes still fail fast via the exit handler), and zmq socket-teardown rejections surface as actionable retriable kernel errors.
- Fixed headless completion reporting a clean finish when a post-compaction continuation failed to start: ACP and print-mode idle waiters now see the failure, while interactive idle behavior is unchanged.
- Added a pre-imported generic MCP API and shell/TUI commands to manage persistent Streamable HTTP and stdio servers in user settings.
- **Breaking**: removed the documented catalog-name override — an `mcpServers` entry named after a built-in integration (e.g. `linear`) no longer repoints the built-in at a custom `url`/`bearerTokenEnvVar`; it now disables the built-in skill and is not served by the generic runtime. Rename the entry (e.g. `linear-proxy`) to keep using a custom endpoint via the generic API. This closes a credential-replay surface where name-keyed tokens could be sent to an override URL.
diff --git a/packages/coding-agent/src/core/kernel/index.ts b/packages/coding-agent/src/core/kernel/index.ts
index 13e23e4837..51c3b6b1dd 100644
--- a/packages/coding-agent/src/core/kernel/index.ts
+++ b/packages/coding-agent/src/core/kernel/index.ts
@@ -24,8 +24,12 @@ import {
const DELIM = Buffer.from("<IDS|MSG>");
const PROTOCOL_VERSION = "5.3";
-const PORTS_RESOLVE_TIMEOUT_MS = 5000;
-const READY_TIMEOUT_MS = 5000;
+// Generous backstop for a kernel that is alive but wedged: crashes are detected
+// within one 25ms poll via the exit handler, warm boots return in under a second,
+// and a cold first boot after a venv (re)provision may legitimately need tens of
+// seconds of imports before it binds ports and answers the ready probe.
+const PORTS_RESOLVE_TIMEOUT_MS = 30_000;
+const READY_TIMEOUT_MS = 30_000;
// Loopback PUB/SUB subscription propagation is usually sub-ms, but keep a small guard before first execute.
const IOPUB_SUBSCRIBE_DELAY_MS = 50;
const DEFAULT_MAX_OUTPUT_CHARS = 65536;
@@ -846,7 +850,7 @@ export class KernelManager {
const msg = buildMessage("kernel_info_request", {}, this.session, this.options.username);
const requestMsgId = msg.header.msg_id;
- await shell.send(encode(msg, conn.key));
+ await this.translateSocketClosure(shell.send(encode(msg, conn.key)));
const startedAt = Date.now();
while (Date.now() - startedAt < READY_TIMEOUT_MS) {
@@ -857,7 +861,7 @@ export class KernelManager {
const remaining = READY_TIMEOUT_MS - (Date.now() - startedAt);
const winner = await Promise.race([
- shell.receive().then((frames) => ({ kind: "frames" as const, frames })),
+ this.translateSocketClosure(shell.receive()).then((frames) => ({ kind: "frames" as const, frames })),
sleep(remaining).then(() => ({ kind: "timeout" as const })),
]);
if (winner.kind === "timeout") break;
@@ -876,6 +880,26 @@ export class KernelManager {
);
}
+ /**
+ * A zmq operation interrupted by socket teardown rejects with the raw libzmq
+ * EAGAIN text ("Operation was not possible or timed out"); surface the kernel
+ * lifecycle instead so callers see an actionable, retriable failure.
+ */
+ private async translateSocketClosure<T>(operation: Promise<T>): Promise<T> {
+ try {
+ return await operation;
+ } catch (error) {
+ const message = error instanceof Error ? error.message : String(error);
+ if (message.includes("not possible or timed out") || message.includes("Socket is closed")) {
+ const tail = this.kernelStderr.slice(-1024);
+ throw new Error(
+ `IPython kernel channel closed while ${this.state === "starting" ? "starting up" : "communicating"} (retriable). stderr tail:\n${tail || "(empty)"}`,
+ );
+ }
+ throw error;
+ }
+ }
+
async execute(code: string, opts: ExecuteOptions = {}): Promise<ExecuteResult> {
const result = await this.enqueueExecute(code, opts);
// Refresh the on-disk snapshot after real work so a later resume (or a
@@ -1011,7 +1035,7 @@ export class KernelManager {
this.lastCellCode = code;
}
try {
- const sendPromise = shell.send(encode(msg, conn.key));
+ const sendPromise = this.translateSocketClosure(shell.send(encode(msg, conn.key)));
sendPromise.catch(() => undefined);
await Promise.race([sendPromise, result.promise.then(() => undefined)]);
if (this.activeExecution === execution && execution.status !== "aborted") {
diff --git a/packages/coding-agent/test/kernel-socket-closure.test.ts b/packages/coding-agent/test/kernel-socket-closure.test.ts
new file mode 100644
index 0000000000..22b96da906
--- /dev/null
+++ b/packages/coding-agent/test/kernel-socket-closure.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from "vitest";
+import { KernelManager } from "../src/core/kernel/index.js";
+
+type Translator = {
+ translateSocketClosure<T>(this: unknown, operation: Promise<T>): Promise<T>;
+};
+
+function makeManager(state: string, stderr = ""): KernelManager {
+ const manager = Object.create(KernelManager.prototype) as KernelManager;
+ Object.assign(manager, { state, kernelStderr: stderr, options: {} });
+ return manager;
+}
+
+const translate = (KernelManager.prototype as unknown as Translator).translateSocketClosure;
+
+describe("KernelManager zmq closure translation", () => {
+ it("passes successful operations through untouched", async () => {
+ await expect(translate.call(makeManager("running"), Promise.resolve("frames"))).resolves.toBe("frames");
+ });
+
+ it("rethrows unrelated errors verbatim", async () => {
+ await expect(translate.call(makeManager("running"), Promise.reject(new Error("boom")))).rejects.toThrow("boom");
+ });
+
+ it("translates the raw libzmq EAGAIN text during startup into a retriable kernel error", async () => {
+ const rejection = Promise.reject(new Error("Operation was not possible or timed out"));
+ await expect(translate.call(makeManager("starting", "ImportError: mcp"), rejection)).rejects.toThrow(
+ /IPython kernel channel closed while starting up \(retriable\)[\s\S]*ImportError: mcp/,
+ );
+ });
+
+ it("translates a closed-socket rejection outside startup", async () => {
+ const rejection = Promise.reject(new Error("Socket is closed"));
+ await expect(translate.call(makeManager("running"), rejection)).rejects.toThrow(
+ /IPython kernel channel closed while communicating \(retriable\)/,
+ );
+ });
+});