Skip to content

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

Rust

fix(coding-agent): echo salvaged command id in daemon parse failures (#592)

Sebastian Müllere4a590984f0b
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 9cdb165eec..804544d535 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fixed daemon parse rejections dropping the command id, which left older clients waiting for a timeout instead of seeing the protocol error.
- Changed large daemon session loads to stream JSONL history and avoid retaining a second full-file copy in memory.
- Changed the agents view to render explicit session names in bold and the "(no messages)" placeholder in italics.
- Fixed the blank line between the recap and the working hint so they render directly above each other.
diff --git a/packages/coding-agent/src/modes/daemon/daemon-mode.ts b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
index 80d1aadfd9..e09563fe57 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-mode.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
@@ -149,6 +149,7 @@ import {
isDaemonCommandEnvelope,
isDaemonDialogExtensionUiRequest,
isDaemonMutatingCommand,
+ salvageDaemonCommandId,
success,
UPDATE_RESTART_DRAIN_COMMANDS,
} from "./daemon-protocol.js";
@@ -2660,7 +2661,7 @@ export class AgentDaemon {
}
command = parsed as DaemonCommand;
} catch (error) {
- this.write(client, failure(undefined, "parse", error, serializeDaemonError(error)));
+ this.write(client, failure(salvageDaemonCommandId(line), "parse", error, serializeDaemonError(error)));
return;
}
diff --git a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
index a22e6643d5..bd13063d09 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
@@ -964,6 +964,25 @@ export function isDaemonCommandEnvelope(value: unknown): value is DaemonCommandE
);
}
+/**
+ * Best-effort id salvage for rejected command lines, so parse failures reach
+ * the sender as correlatable responses instead of client-side timeouts.
+ * Deliberately ignores everything but the id itself: whatever made the line
+ * unparseable (rejected protocol version, missing or invalid type), the
+ * sender still correlates the failure by id.
+ */
+export function salvageDaemonCommandId(line: string): string | undefined {
+ try {
+ const candidate = JSON.parse(line) as { id?: unknown };
+ if (!candidate || typeof candidate !== "object") {
+ return undefined;
+ }
+ return typeof candidate.id === "string" ? candidate.id : undefined;
+ } catch {
+ return undefined;
+ }
+}
+
const READ_ONLY_DAEMON_COMMANDS: ReadonlySet<DaemonCommand["type"]> = new Set([
"ack_result",
"list",
diff --git a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
index 9b43aac5e8..ffce3270d5 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts
@@ -61,6 +61,7 @@ import {
failure,
isDaemonCommandEnvelope,
isDaemonMutatingCommand,
+ salvageDaemonCommandId,
success,
UPDATE_RESTART_DRAIN_COMMANDS,
} from "./daemon-protocol.js";
@@ -1064,7 +1065,7 @@ export class DaemonSupervisor {
try {
preParsed = this.parseCommandAndRegisterPromptAdmission(client, line);
} catch (error) {
- this.write(client, failure(undefined, "parse", error));
+ this.write(client, failure(salvageDaemonCommandId(line), "parse", error));
return;
}
const command = preParsed.command;
diff --git a/packages/coding-agent/test/daemon-protocol.test.ts b/packages/coding-agent/test/daemon-protocol.test.ts
index 979c7fa5c3..bc3f52715f 100644
--- a/packages/coding-agent/test/daemon-protocol.test.ts
+++ b/packages/coding-agent/test/daemon-protocol.test.ts
@@ -18,6 +18,7 @@ import {
type DaemonOutbound,
isDaemonCommandEnvelope,
isDaemonMutatingCommand,
+ salvageDaemonCommandId,
} from "../src/modes/daemon/daemon-protocol.js";
describe("daemon protocol helpers", () => {
@@ -214,4 +215,17 @@ describe("daemon protocol helpers", () => {
toCursor: { generation: "new", sequence: 0 },
});
});
+
+ it("salvages command ids from rejected lines regardless of shape validity", () => {
+ const oldEnvelope = JSON.stringify(
+ createDaemonCommandEnvelope({ type: "list" } as DaemonCommand, "list-1", "old-client", 6),
+ );
+ expect(salvageDaemonCommandId(oldEnvelope)).toBe("list-1");
+ expect(salvageDaemonCommandId(JSON.stringify({ type: "list", id: "bare-1" }))).toBe("bare-1");
+ expect(salvageDaemonCommandId(JSON.stringify({ type: null, id: "typeless-1" }))).toBe("typeless-1");
+ expect(salvageDaemonCommandId(JSON.stringify({ id: "no-type" }))).toBe("no-type");
+ expect(salvageDaemonCommandId(JSON.stringify({ type: "command", id: 7 }))).toBeUndefined();
+ expect(salvageDaemonCommandId(JSON.stringify("command"))).toBeUndefined();
+ expect(salvageDaemonCommandId("{ not json")).toBeUndefined();
+ });
});
diff --git a/packages/coding-agent/test/daemon-supervisor-side-question.test.ts b/packages/coding-agent/test/daemon-supervisor-side-question.test.ts
index 9b2529f0d3..6e966359b6 100644
--- a/packages/coding-agent/test/daemon-supervisor-side-question.test.ts
+++ b/packages/coding-agent/test/daemon-supervisor-side-question.test.ts
@@ -115,6 +115,7 @@ describe("daemon supervisor side-question routing", () => {
expect(write).toHaveBeenCalledWith(
client,
expect.objectContaining({
+ id: "state-1",
command: "parse",
success: false,
error: expect.stringContaining("require protocol 7"),
@@ -166,6 +167,7 @@ describe("daemon supervisor side-question routing", () => {
await expect(messages).resolves.toEqual([
expect.objectContaining({ type: "daemon_hello" }),
expect.objectContaining({
+ id: "state-1",
type: "response",
command: "parse",
success: false,