Skip to content

fix(engine-manager): resolve process images on macOS via lsof - #242

Open
stevbev wants to merge 1 commit into
NVIDIA:developfrom
stevbev:fix/macos-proc-image
Open

stevbev wants to merge 1 commit into
NVIDIA:developfrom
stevbev:fix/macos-proc-image

Conversation

@stevbev

@stevbev stevbev commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Description

On macOS, procImage could never resolve a process's executable: it read only Linux's /proc, yet sat in the //go:build !windows file. The orphan-reclaim identity check in doStop therefore always saw an empty image and failed closed — so engine:stop and uninstall refused a PAIR-managed orphan left on PAIR's own managed port, with a decline error that couldn't even name the image (... under external management (pid 92530, )). It also left TestUninstall_TerminatesRunningInstance red on macOS and the lifecycle_stop_test.go reclaim/decline tests permanently skipping.

The fix gives the darwin build a trustworthy image lookup: lsof -a -p <pid> -d txt -Fn returns the executables the kernel actually mapped, whose first entry is the binary that was exec'd — vnode info, not the argv a process can rewrite (ps was evaluated and rejected as spoofable). Since macOS reports the image canonically (/private/var/...) while managed paths can be spelled through the /var symlink, isOurEngineImage gains a canonicalised retry. User-visible outcome: stopping or uninstalling an engine reclaims its own orphans on macOS again, and declines of foreign listeners name the real executable.

Closes #17.

Release intent

Changelog title

Engine orphan reclaim works on macOS

Changelog body

The stop and uninstall ownership check can now identify the executable a
process is actually running on macOS, from the kernel's mapped-executable
record rather than only Linux's /proc. A PAIR-managed engine process left
on PAIR's own managed port by an earlier run is reclaimed by stop and
uninstall again, and a decline of a foreign listener now names the real
executable path. Script-run engines (a venv invoked through its interpreter)
still decline on macOS, as before; an unresolvable image still fails closed.

Bumps

  • services: patch
  • nvpair-cluster-manager: none
  • nvpair-engine-manager: patch
  • nvpair-errors: none
  • nvpair-job-scheduler: none
  • nvpair-manual-nodes: none
  • nvpair-node-info: none
  • nvpair-node-scanner: none
  • nvpair-node-settings: none
  • nvpair-proxy: none
  • nvpair-tui: none
  • nvpair-ui-broker: none
  • nvpair-workload-manager: none

Scope

Included:

  • procImage / procRunsScript split out of proc_unix.go into proc_linux.go (verbatim /proc logic) and proc_darwin.go (lsof lookup, bounded by the existing portLookupTimeout; -Fn so spaces in paths need no column parsing).
  • Canonicalised retry in isOurEngineImage: EvalSymlinks on both sides, with a directory-resolve fallback for replaced-but-still-running binaries, mirroring Linux's " (deleted)" match. Platform-neutral; a no-op on every path Linux already matched.
  • Darwin tests: identity of a managed copy under a symlinked, space-containing temp root; fail-closed for exited and bogus PIDs; parser tests pinned to verbatim lsof -Fn captures (plain binary, path with spaces, Python framework bundle, empty/header-only).
  • Wording fixes: README stop/reclaim prose and the lifecycle_stop_test.go skip-guard comment no longer claim macOS cannot resolve an image.

Excluded:

Validation

Environment: macOS 26.7.3 (25G342), Apple Silicon, Go 1.27.4.

  1. Pre-fix baseline on a detached worktree at develop 7a8c524 (the branch
    was later rebased onto dfac16a with no conflicts and re-validated): go test -count=1 -v -run 'TestUninstall_TerminatesRunningInstance|TestStop_ReclaimsOurOrphanOnManagedPort|TestStop_DoesNotReclaimSameExternalImage|TestStop_RejectsForeignListenerWithActionableError' . → the uninstall test FAILs with (pid 92530, ) (empty image), the three reclaim/decline tests SKIP.
  2. After: same command → all four PASS.
  3. New darwin tests: go test -count=1 -v -run 'TestProcImage|TestParseLsofExecName' . → PASS.
  4. Full module suite on the rebased branch: go test -count=1 ./... (189 s) → passes, 0 skips (pre-fix baseline on this machine: 16 skips; PR test: make the macOS Go test suite pass, including cross-process tests beside a running installation #230, now in the base, separately fixed the TestHFToolPath darwin failure).
  5. Cross-platform: go vet ./... plus GOOS=linux go vet ./... and GOOS=windows go vet ./... → only the pre-existing lostcancel warning in install_artifacts_test.go, unchanged on clean develop.
  6. Hygiene: gofmt -l clean on all touched files; node scripts/spdx-headers.mjs → 0 missing.

Not run: the Linux module suite (no Linux host here). The Linux code path is a verbatim move under //go:build linux plus a retry branch that only runs after the exact string compare fails; CI covers Linux.

Risk

  • Security posture: the identity gate before SIGKILL keeps failing closed — empty image, unintrospectable PID (other users' processes), lsof timeout, and unresolvable canonical paths all decline. The chosen primitive is kernel vnode info; ps-style argv views were rejected because they are spoofable. A byte-identical copy of the engine elsewhere is still declined (tested), and reclaim additionally still requires isManagedInstallPath.
  • Behavior change: stops on macOS can now terminate a process they previously refused — only one that runs the managed binary inside PAIR's install directory, which is the documented contract. Decline errors change shape (the image field is now populated, and empty-image declines remain only for genuinely unintrospectable listeners).
  • Dependencies: no new ones; lsof is already invoked by pidOnPort on this exact code path, under the same timeout budget. No wire, payload, or contract changes, so no service-contracts impact and no desktop-side change.

Checklist

  • I have read the Contributing Guidelines.
  • Every commit is signed off (git commit -s), certifying the Developer Certificate of Origin.
  • New or existing tests cover the change.
  • Relevant documentation is updated.
  • I checked the diff, changed filenames, and commit messages for credentials, private data, internal URLs, internal issue identifiers, and generated artifacts.
  • I recorded the validation commands and results above.
  • I declared version bumps in the release-intent block above. services/versions.json is written by automation — do not edit it by hand.

Orphan reclaim in Stop compares the executable the kernel mapped for the
port's PID against our managed binary, but procImage read only Linux's
/proc, so on macOS the image was always empty and the fail-closed check
declined even a clearly managed orphan: TestUninstall_TerminatesRunningInstance
failed there and the lifecycle_stop reclaim/decline tests skipped.

Give procImage and procRunsScript per-platform homes. Linux keeps the
/proc reads verbatim; darwin asks lsof for the process's txt mappings
(-Fn, one path per line), whose first entry is the exec'd binary - that
is kernel vnode info, unlike ps, which echoes spoofable argv. A venv
script engine (vLLM) keeps declining on macOS, as before: no trustworthy
command line is readable there.

isOurEngineImage gains a canonicalised retry so macOS's canonical
/private/var/... image spelling matches a managed path written through
the /var symlink; anything unresolvable still fails closed.

Signed-off-by: Steven Beverly <thestevbev@gmail.com>
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.

[Bug]: procImage is /proc-only on a !windows build, so macOS never resolves an engine image (reclaim declines, one test fails)

1 participant