fix(continuum): break auto-save loop on empty psmux output (follow-up to #24)#28
Open
TrvoDK wants to merge 1 commit into
Open
fix(continuum): break auto-save loop on empty psmux output (follow-up to #24)#28TrvoDK wants to merge 1 commit into
TrvoDK wants to merge 1 commit into
Conversation
… to psmux#24) psmux#24 made the auto-save loop single-instance, but the loop still decides "server gone" only from $LASTEXITCODE -ne 0. psmux returns exit 0 with empty output when no server is running, so the surviving loop never exits; while the server is down it keeps invoking save.ps1 every interval, which (before the resurrect-side 0-session guard) wrote empty snapshots that evicted good ones. Treat empty output as "no server" too: if ($LASTEXITCODE -ne 0 -or -not $sessions.Trim()) (the same emptiness signal save.ps1's own capture-retry loop already trusts). $sessions is only used for the liveness check, never saved. Also re-sync the here-string in psmux-continuum.ps1 with the committed auto_save.ps1. That here-string regenerates auto_save.ps1 with -Force on every plugin load but was never updated for psmux#24 -- it still lacked the single-instance mutex -- so a reload would regenerate the file WITHOUT psmux#24's mutex, silently reverting it. The here-string now matches the committed file byte-for-byte (mutex + try/finally + break-on-empty); a test asserts that equality to prevent future drift. Did not refactor away the generate-on-load duplication (committed file vs here-string); happy to file that separately. Tests: tests/test_continuum_guard.ps1 -- break-on-empty present in both copies, here-string regenerates byte-identical, both retain the psmux#24 mutex, the break decision is unit-tested (incl. exit 0 + empty -> break), and a premise test uses the real psmux binary on a throwaway socket to confirm psmux returns exit 0 + empty with no server. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #26. Follow-up to #24.
#24 made the auto-save loop single-instance (one per session). But the loop still decides "server gone" only from
$LASTEXITCODE -ne 0, andpsmux lsreturns exit 0 with empty output when no server is running — so the surviving loop never exits. While the server is down it keeps invokingsave.ps1every interval, which (before the resurrect-side 0-session guard) wrote empty snapshots that evicted good ones.This treats empty output as "no server" too:
if ($LASTEXITCODE -ne 0 -or -not $sessions.Trim()). (Same emptiness signalsave.ps1's own capture-retry loop already trusts.)$sessionsis only used for the liveness check, never saved.Also fixes a latent #24 regression.
auto_save.ps1is generated on every plugin load by a here-string inpsmux-continuum.ps1(Set-Content ... -Force). That here-string was never updated for #24 — it still lacked the single-instance mutex — so a plugin reload would regenerateauto_save.ps1without #24's mutex, silently reverting it. This PR re-syncs the here-string to match the committedauto_save.ps1(mutex + try/finally + this break-on-empty change), so the generated file is byte-identical to the committed one. A test asserts that byte-for-byte equality to prevent future drift.I did not refactor away the generate-on-load duplication (committed file vs here-string) — that's a larger change; happy to file it separately if you'd like a single source of truth.
Tests:
tests/test_continuum_guard.ps1— break-on-empty present in both the committedauto_save.ps1and the here-string; the here-string regenerates byte-identical to the committed file; both retain the #24 mutex; the break decision is unit-tested (incl. the bug case: exit 0 + empty → break); and a premise test uses the real psmux binary on a throwaway socket to confirmpsmux -L <no server> lsreturns exit 0 + empty. The running loop itself isn't executed end-to-end (it sleeps then holds a process-wide mutex, so it can't be isolated in a unit test) — the premise + decision + static-presence asserts cover that gap.Pairs with the psmux-resurrect PR in #26: that 0-session guard is the keystone data-loss fix; this PR stops the loop that drives it.