Skip to content

emrg: stop_all Restart Manager lock-owner kill (generic DeleteFile code 5 fix) - #827

Merged
argszero merged 1 commit into
masterfrom
feature/stop-lock-owners-restart-manager
Aug 17, 2026
Merged

emrg: stop_all Restart Manager lock-owner kill (generic DeleteFile code 5 fix)#827
argszero merged 1 commit into
masterfrom
feature/stop-lock-owners-restart-manager

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

Fixes the generic Windows installer DeleteFile failed; code 5 root cause (rant 2026-08-17T17:55:42, supersedes the EMRG-cmdline-scan fallback #826).

Background

Installing v0.2.43 on Windows failed with DeleteFile failed; code 5 on install\lib\websockets\speedups.cp313-win_amd64.pyd. A find_lock_owner.ps1 (Restart Manager API) probe showed the actual lock owner was an external process — the browser-harness daemon (standalone uv CPython under AppData\Roaming\uv\tools, -m browser_harness.daemon). emrgd.pid/emrgd.port were empty and no -m emrg process existed, so the existing EMRG cmdline scan (17:03:38 / #826) could never see it. Root cause: a foreign process locking files under install\ — Restart Manager's lock-owner report is the general solution covering both EMRG and foreign owners.

Changes (emrg/_stop_all.py, pure stdlib — installer runs it standalone)

  1. New stop_lock_owners() step — inserted in stop_all() after stop_bundled_git(), before verify():
    • PowerShell + Restart Manager (rstrtmgr.dll, C# wrapper ported from the verified find_lock_owner.ps1) scans $env:USERPROFILE\.emrg\install\ recursively for locked-file owners, deduped PID set.
    • Performance: batches of 500 files per RmRegisterResources in one session; RmGetList retries on ERROR_MORE_DATA (234) with a grown buffer — no per-file session (10k+ files under install).
    • Safety: excludes self + the full ancestor chain (the running install\python-dist\python.exe loads python313.dll etc. from install; ancestors include the Inno setup.exe — never killed) via Win32_Process ParentProcessId walk.
    • Remaining PIDs: Stop-Process -Force, printing PID name cmdline (truncated 150 chars) — clearly telling the user a non-EMRG process (e.g. browser-harness daemon) was stopped; emits a restart hint when browser-harness was killed.
    • RM unavailable (permissions/API failure) → silently skipped, best-effort like every other stop step.
  2. _verify_windows() extension — re-runs the same Restart Manager scan; any remaining non-self/ancestor lock owner is appended as file-lock owner (pid N, name) → exit 1 (installer abort semantics R125 unchanged).
  3. Template is fully static (no str.format) so the literal PowerShell/C# braces need no {{ }} escaping.

Tests

+9 (Agent.md 885→893): TestLockOwners (POSIX no-op, tab-output parsing, subprocess-failure → empty, kill-flag rendering, template key elements incl. RM API/batch/234/ancestor-exclusion/truncation/hint, no-format render safety, verify residual) + order wiring (lock owners after bundled-git before verify) + installer textual wiring pin.

Full pytest 892 passed + 1 skipped (893 collected), import + CLI green.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 594 (1/3). Re-verified: Restart Manager lock-owner scan (rstrtmgr.dll, batched 500-file RmRegisterResources, ERROR_MORE_DATA 234 retry), self+ancestor-chain exclusion (ParentProcessId walk — protects the running install\python-dist\python.exe and Inno setup.exe), Stop-Process -Force with PID/name/cmdline(150) logging + browser-harness restart hint; verify() extension reports survivors → exit 1 (R125 intact); stop order bundled-git → lock-owners → verify. Full pytest 892+1 (893), import + CLI green; CI test + test-windows PASS (32018793024).

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 595 (2/3). Re-verified head 00a27f4 unchanged (4 files +308/−2): static PS/C# template (no str.format escaping), Restart Manager scan of $env:USERPROFILE.emrg\install with batched 500-file RmRegisterResources + ERROR_MORE_DATA(234) retry; self+ancestor-chain exclusion (ParentProcessId walk protects running python-dist python + Inno setup.exe); Stop-Process -Force with PID/name/cmdline(150) logging + browser-harness restart hint; stop order bundled-git → lock-owners → verify; _verify_windows() reports surviving file-lock owners → exit 1 (R125 intact). CI test + test-windows PASS (32018793024). Awaiting 3rd LGTM.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 596 (3/3). Re-verified head 00a27f4 unchanged (4 files +308/−2), CI test + test-windows PASS (32018793024), MERGEABLE/CLEAN. Three consecutive LGTMs from cycles 594/595/596 with no ❌ in between — merging.

@argszero
argszero merged commit b1e0c8a into master Aug 17, 2026
2 checks passed
@argszero
argszero deleted the feature/stop-lock-owners-restart-manager branch August 17, 2026 10:31
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