Skip to content

fix: harden daemon and embed-lock process identity on Windows - #924

Open
ilepn wants to merge 1 commit into
tobi:mainfrom
ilepn:fix/windows-process-identity
Open

ilepn wants to merge 1 commit into
tobi:mainfrom
ilepn:fix/windows-process-identity

Conversation

@ilepn

@ilepn ilepn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

PR: fix: harden daemon and embed-lock process identity on Windows

Summary

  • Replace bare daemon/embed PIDs with qmd-process/v1 records containing the
    PID, role, and an OS-issued process-start token.
  • Use Windows CIM process creation timestamps with hidden PowerShell execution,
    Linux /proc/<pid>/stat field 22, and ps lstart on other POSIX systems.
  • Publish daemon identity only after the HTTP listener binds, observe early
    child exit, and verify the exact same identity immediately before signalling.
  • Treat live pre-upgrade numeric state as unverifiable and fail closed instead
    of orphaning a daemon or stealing an active embed lock; role-specific POSIX
    command-line checks retain safe recognition where the owner can be proven.
  • Pass the TSX loader as a file URL and hide spawned Windows process windows.
  • Publish embed locks atomically, fail closed on fresh malformed state, and
    reclaim only an unchanged malformed lock after a 30-second grace period.

If the Windows CIM probe cannot obtain a process-start token, QMD writes a
legacy PID record and deliberately leaves it untouched while that PID remains
live. This degraded mode favors avoiding signals or lock theft against an
unrelated process; normal lifecycle management resumes after the process exits
or its ownership is independently reconciled.

Why

The previous command-line inspection could not identify native Windows QMD
processes reliably. Bare PIDs are also unsafe after PID reuse and allowed
status/start/stop and embed-lock recovery to act on unrelated processes.

Review-driven hardening

Two earlier adversarial Opus passes challenged upgrade compatibility, PID
reuse, protected-process probes, lock publication/recovery, runtime-specific
daemon launching, and Windows test coverage. A final Claude ultrareview then
found and verified two POSIX/signal-exit defects; both were corrected, and a
second ultrareview of the amended candidate completed with no findings. The
revision uses role-aware legacy checks, CIM creation timestamps, atomic lock
publication with a non-hardlink fallback, guarded malformed-state recovery,
and a Bun-native TypeScript child path.

Verification

  • bun run lint
  • bun run test:types
  • Node/Vitest and Bun 1.4.0-canary.1 process-identity and embed-lock tests:
    17 passed under each runtime
  • native Windows mcp http daemon group: 13 passed under Node and 13 under
    Bun 1.4.0-canary.1
  • git diff --check

Local branch

  • base: dbfd0b4736aeaf761d1a16ca8e424f071df8feb9
  • commit: 355f4c8
  • branch: fix/windows-process-identity

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.

1 participant