Skip to content

fix(cli/windows): exclude parent process chain from concurrent-instance detection (salvage of #31712)#31806

Merged
teknium1 merged 2 commits into
mainfrom
salvage/pr31712-windows-parent-chain
May 25, 2026
Merged

fix(cli/windows): exclude parent process chain from concurrent-instance detection (salvage of #31712)#31806
teknium1 merged 2 commits into
mainfrom
salvage/pr31712-windows-parent-chain

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

hermes update on Windows no longer aborts with a false "another hermes.exe is running" when the only "other" instance is the setuptools .exe launcher that spawned the running Python interpreter. Salvage of #31712 (@Strontvod) with a test + hardening follow-up on top.

Root cause

The setuptools-generated hermes.exe is a separate native process that spawns python.exe (which actually runs the update code). os.getpid() returns the Python PID; the launcher (which holds the file lock that blocks the .exe rename) is the parent. The old code excluded only the Python PID, so the launcher was always flagged as a concurrent instance.

Changes

  • hermes_cli/main.py: walk psutil.Process.parent() upward and add every ancestor to the exclusion set. Includes a loop-detection break so a broken parent chain can't hang the walk. (Contributor commit, authorship preserved.)
  • hermes_cli/main.py (follow-up): broaden the outer except on the parent-walk to bare Exception. The original (NoSuchProcess, AccessDenied, ValueError) tuple is evaluated lazily during exception matching — if psutil is a partial stub without those attributes, the handler itself raises AttributeError that escapes. The helper documents itself as "never raises"; the broader catch keeps the contract regardless of how the dependency is shaped.
  • tests/hermes_cli/test_update_concurrent_quarantine.py (follow-up): 5 new tests covering the parent-walk — launcher excluded, unrelated sibling still reported, 3-deep ancestry, PID-cycle handled without hang, partial psutil stub degrades gracefully. New _fake_psutil_with_parent_chain helper models the fuller psutil surface (Process / NoSuchProcess / AccessDenied + process_iter).
  • scripts/release.py: AUTHOR_MAP entry mapping schepers.zander1@gmail.comStrontvod.

Validation

Before After
hermes update on Windows false-abort proceeds
Sibling hermes.exe outside tree (still works) still reported
test_update_concurrent_quarantine.py 4 fail* 18/18 pass

*4 existing tests would have failed CI against the bare contributor commit because their fake_psutil = SimpleNamespace(process_iter=...) stub lacks Process/NoSuchProcess/AccessDenied, which the new parent-walk code now references. The bare-Exception hardening makes them pass without touching the tests themselves.

tests/hermes_cli/test_update_concurrent_quarantine.py  18 passed in 0.77s

Notes

Infographic

windows-parent-chain-exclusion

Strontvod and others added 2 commits May 24, 2026 19:38
…on Windows

On Windows, the setuptools-generated hermes.exe launcher is a separate native
process that spawns python.exe (the interpreter running the update code).
os.getpid() returns the Python PID, but the launcher (which holds the file
lock) is the parent. Without walking the parent chain, every 'hermes update'
reports its own launcher as a concurrent instance - a false positive.

This patch builds an exclusion set containing the Python process and its
entire ancestor chain, so the running invocation never reports itself.
…ction

Follow-up to @Strontvod's fix.

Tests:
- Five new tests in test_update_concurrent_quarantine.py cover the parent-
  chain exclusion: the .exe launcher is excluded, an unrelated sibling
  hermes.exe is still reported, multi-level ancestry is fully excluded,
  PID cycles in the parent chain don't hang, and a partially-stubbed
  psutil (no Process attribute) degrades gracefully instead of crashing.
- New _fake_psutil_with_parent_chain helper builds a fuller stand-in
  (Process / NoSuchProcess / AccessDenied + process_iter) than the
  process_iter-only SimpleNamespace the older tests use.

Hardening:
- Broaden the except in the parent-walk to bare Exception. The original
  fix listed (NoSuchProcess, AccessDenied, ValueError), but those names
  are evaluated lazily during exception matching — if psutil is a partial
  stub without the attribute, the exception handler itself raises
  AttributeError that escapes. The function is documented as 'never raises'
  (the surrounding update flow depends on it), so the broader catch keeps
  the contract regardless of how the dependency is shaped.

AUTHOR_MAP:
- Map schepers.zander1@gmail.com -> Strontvod so the salvaged commit
  resolves to @Strontvod in the release notes.

All 18 detect_concurrent + quarantine tests pass.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/pr31712-windows-parent-chain vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9116 on HEAD, 9116 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4862 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1 teknium1 merged commit 46f8948 into main May 25, 2026
26 checks passed
@teknium1 teknium1 deleted the salvage/pr31712-windows-parent-chain branch May 25, 2026 02:51
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels May 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Salvage of closed #31712. Competing with #29358 and #31808 — all three fix #29341 (Windows launcher shim PID not excluded from concurrent-instance detection).

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

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants