Skip to content

fix(continuum): break auto-save loop on empty psmux output (follow-up to #24)#28

Open
TrvoDK wants to merge 1 commit into
psmux:mainfrom
TrvoDK:fix/continuum-break-on-empty
Open

fix(continuum): break auto-save loop on empty psmux output (follow-up to #24)#28
TrvoDK wants to merge 1 commit into
psmux:mainfrom
TrvoDK:fix/continuum-break-on-empty

Conversation

@TrvoDK

@TrvoDK TrvoDK commented Jun 23, 2026

Copy link
Copy Markdown

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, and psmux ls 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.

This treats empty output as "no server" too: if ($LASTEXITCODE -ne 0 -or -not $sessions.Trim()). (Same emptiness signal save.ps1's own capture-retry loop already trusts.) $sessions is only used for the liveness check, never saved.

Also fixes a latent #24 regression. auto_save.ps1 is generated on every plugin load by a here-string in psmux-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 regenerate auto_save.ps1 without #24's mutex, silently reverting it. This PR re-syncs the here-string to match the committed auto_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 committed auto_save.ps1 and 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 confirm psmux -L <no server> ls returns 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.

… 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>
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