Skip to content

fix(session): reject non-positive PIDs in daemon health responses - #1222

Open
ShryukGrandhi wants to merge 1 commit into
modem-dev:mainfrom
ShryukGrandhi:fix/issue-765-validate-session-broker-health-responses
Open

ShryukGrandhi wants to merge 1 commit into
modem-dev:mainfrom
ShryukGrandhi:fix/issue-765-validate-session-broker-health-responses

Conversation

@ShryukGrandhi

Copy link
Copy Markdown
Contributor

Summary

Most of #765 is already handled on main. readSessionBrokerHealth goes through probeSessionBrokerHealth, which reads a bounded body and decodes it with parseSessionBrokerHealth (exact keys, ok: true, safe integers, strings, and the legacy paths shape). The one acceptance criterion still open was the PID: the decoder used the generic safe-integer check with a minimum of 0, so a health payload with "pid": 0 decoded as healthy. process.kill(0, ...) signals the caller's whole process group, so a zero PID should never get through.

Changes

  • parseSessionBrokerHealth now requires pid to be a safe integer >= 1. That matches the check the launch-metadata decoder already does. The other counters still accept 0.
  • Extended the health decoder test to reject zero, negative, fractional, string, and unsafe (MAX_SAFE_INTEGER + 1) PIDs.
  • Added a patch Changeset.

The restart path in hunk daemon restart (daemonCommands.ts) signals only the PID from the validated launch metadata (parseSessionBrokerLaunchMetadata, which also requires a minimum of 1). It never uses the health payload's PID, so no restart code changes were needed.

Testing

  • bun test packages/hunk/src/session/broker/brokerLauncher.test.ts: the new pid: 0 case fails before the fix and passes after it.
  • bun test packages/hunk/src/session: 443 pass, 1 fail. The failing test is a timing-sensitive daemon-server test (keeps a silent session past the stale TTL...). It is not related to this change: it and other daemon-server tests also failed intermittently on unmodified main on the same machine.
  • bun run typecheck, oxlint, and oxfmt on the touched files are clean.
  • Tested on macOS arm64 only.

Fixes #765

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@ShryukGrandhi is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate session broker health responses before using their PID

1 participant