From f2aef32767ba5b99173e48638a71678c724dd25d Mon Sep 17 00:00:00 2001 From: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:48:09 -0700 Subject: [PATCH] fix(session): reject non-positive PIDs in daemon health responses Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com> --- .changeset/daemon-health-positive-pid.md | 5 +++++ .../hunk/src/session/broker/brokerLauncher.test.ts | 12 +++++++++++- packages/hunk/src/session/broker/brokerLauncher.ts | 9 ++------- 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 .changeset/daemon-health-positive-pid.md diff --git a/.changeset/daemon-health-positive-pid.md b/.changeset/daemon-health-positive-pid.md new file mode 100644 index 000000000..0ad93117e --- /dev/null +++ b/.changeset/daemon-health-positive-pid.md @@ -0,0 +1,5 @@ +--- +"hunkdiff": patch +--- + +Reject session daemon health responses that advertise a zero PID. diff --git a/packages/hunk/src/session/broker/brokerLauncher.test.ts b/packages/hunk/src/session/broker/brokerLauncher.test.ts index c597e9609..9b6bcba41 100644 --- a/packages/hunk/src/session/broker/brokerLauncher.test.ts +++ b/packages/hunk/src/session/broker/brokerLauncher.test.ts @@ -129,7 +129,17 @@ describe("session daemon launcher", () => { paths: { health: "/health", socket: "/session" }, }), ).toMatchObject({ ok: true, pid: 123, sessions: 1 }); - for (const value of [null, [], { ok: "yes" }, { ok: true, pid: 1.5 }, { ok: true, extra: 1 }]) { + for (const value of [ + null, + [], + { ok: "yes" }, + { ok: true, pid: 0 }, + { ok: true, pid: -1 }, + { ok: true, pid: 1.5 }, + { ok: true, pid: "123" }, + { ok: true, pid: Number.MAX_SAFE_INTEGER + 1 }, + { ok: true, extra: 1 }, + ]) { expect(parseSessionBrokerHealth(value)).toBeNull(); } }); diff --git a/packages/hunk/src/session/broker/brokerLauncher.ts b/packages/hunk/src/session/broker/brokerLauncher.ts index aabf50fc4..1e734d021 100644 --- a/packages/hunk/src/session/broker/brokerLauncher.ts +++ b/packages/hunk/src/session/broker/brokerLauncher.ts @@ -497,13 +497,8 @@ export function parseSessionBrokerHealth(value: unknown): SessionBrokerHealth | ); if (record.ok !== true) return null; const parsed: SessionBrokerHealth = { ok: true }; - for (const key of [ - "pid", - "sessions", - "pendingCommands", - "uptimeMs", - "staleSessionTtlMs", - ] as const) { + if (record.pid !== undefined) parsed.pid = parseBrokerSafeInteger(record.pid, { minimum: 1 }); + for (const key of ["sessions", "pendingCommands", "uptimeMs", "staleSessionTtlMs"] as const) { if (record[key] !== undefined) parsed[key] = parseBrokerSafeInteger(record[key]); } for (const key of [