psmux-continuum - auto_save.ps1 spawns duplicate processes on every attach
plugin.conf uses a client-attached hook to launch auto_save.ps1. Since the script runs an infinite loop and the hook fires on every attach, a new process spawns each time without killing the previous one.
Reproduce
# detach, reattach a few times
tmux attach -t mysession
(Get-Process pwsh | Where-Object { $_.CommandLine -like '*auto_save*' }).Count
# count grows by 1 per attach
After normal usage I ended up 30+ concurrent auto_save.ps1 processes running.
auto_save.ps1 should only allow a single instance to run at a time.
Hey @AmshegaR, thank you for the clear report and the exact reproduction steps. You were right, and I reproduced it on the first try.
What was happening: the client-attached hook fires on every attach and ran auto_save.ps1 unconditionally. That script is a persistent while ($true) loop, so each attach started another loop that never exited. Reattaching four times left four auto_save processes running, and they kept accumulating exactly as you described.
Fix in psmux/psmux-plugins@0f46ccc: auto_save.ps1 now acquires a named mutex at startup and exits immediately if another auto-save loop already holds it. So client-attached can fire as many times as it likes and only one loop ever runs per user session. The mutex is released on exit and reclaimed automatically if a previous owner was killed.
Verified with a Win32 test that attaches a client repeatedly and counts the processes: the count grew 1, 2, 3, 4 across four attaches before the fix, and stays at exactly 1 after.
To pick it up, pull the latest psmux-plugins (or reinstall psmux-continuum). Any duplicates already running from before will stop on their own once the server goes away, or you can close them once. Thanks again for catching this.
Hey @AmshegaR, quick follow-up since a couple of things surfaced downstream of the 0f46ccc fix that are worth closing the loop on here.
First, we found the mutex fix had a gap. auto_save.ps1 is regenerated from a here-string inside psmux-continuum.ps1 on every plugin load, and that here-string never got updated when 0f46ccc landed. So a plugin reload (not just a reinstall) would silently regenerate auto_save.ps1 without the mutex and revert your fix. That's patched in #28, merge commit 2e79d2aff075e8a84cadd0266735817644f2ec92, which re-syncs the here-string to the committed file and adds a test that asserts they stay byte-identical so this can't drift again unnoticed.
Second, the surviving single loop still never actually exited when the server went away, it only checked $LASTEXITCODE, and psmux ls returns exit 0 with empty output even when no server is running. So instead of duplicate loops, you'd end up with one loop that outlives its server indefinitely. Same #28 also makes the loop treat empty output as "server gone" and break, so now the one loop your original fix guarantees also terminates correctly. That was actually the root cause of a related data-loss bug in #26, which is fixed too.
Both changes verified with tests/test_continuum_guard.ps1 (11/11 passing, including a check against the real psmux binary confirming the exit-0-empty-output behavior).
So to summarize where things stand: single loop per session (your fix), that loop now survives plugin reloads (this fix), and it now exits cleanly when the server is gone (also this fix) instead of running forever. Update to the latest psmux-plugins to pick all of it up. Thanks again for flagging the original zombie-process issue, it's what put us on this whole thread. Closing this out.