Skip to content

fix(persist): a restart or live handoff keeps a suspended pane suspended while its old program may run - #137

Closed
colangelo wants to merge 12 commits into
masterfrom
fix/369-suspended-double-start
Closed

colangelo wants to merge 12 commits into
masterfrom
fix/369-suspended-double-start

Conversation

@colangelo

Copy link
Copy Markdown
Owner

Summary

A pane suspended while its agent still ran could start a second copy of that agent after a server restart or a live handoff. Now a suspended pane stays suspended across both, until its old program is confirmed gone.

restore / live handoff
  for each saved pane
    suspended and old program may still run -> stay suspended, schedule a check
  decide every held pane before handing out any agent resume plan
    -> one session id is resumed by at most one pane
suspended pane check
  probes each program once; cannot confirm -> checks again by itself
pane respawn
  waits for a suspended pane's old program unless --force
history fingerprint
  ignores the saved suspension, so older builds keep their history

Commits: refactor (dead-program check is a method of the suspension), the restore/handoff fix with its tests and docs, then the five review fixes (probe once, self re-check, respawn guard, reservation before resume plans, fingerprint unchanged) and docs.

Evidence

  • Before: restore of a suspended pane with its old agent alive started a second agent.
  • After: src/persist/restore_suspended_tests.rs restore and live-handoff cases stay suspended; full cargo nextest run --no-fail-fast and just check green (6187 passed). Codex adversarial review: 3 P1 + 2 P2 found, all fixed in this branch.

Follow-ups filed: https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/424 (TUI respawn text), 425 (respawn guard for core-waiting panes), 426 (in-server duplicate session resume), 427 (history fingerprint field set).

Merge Danger

Door: two-way (no wire change; the saved suspension field is optional and kept out of the history fingerprint)

Blast Radius: restore and live handoff of suspended panes; pane respawn

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369

…ended pane

Characterization before the fix for fork issue 369: a suspended core pane
saves its link and waits while its program may run; a suspended pane keeps
its place, label, launch command and resume plan in the save; and once its
old program is gone it restores as any pane does, its agent by its plan,
else a shell.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
`resume_block` moves from the app's suspension module onto `Suspension`,
so a restore can run the same check before it starts a pane (fork issue
369). No behaviour change.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…ded while its old program may run

A pane suspended outside herdr-core (a stopped pane job, a logout, a move
whose replacement did not start) held its old program's identity only in
memory, so a restore or live handoff started it fresh beside an old
program that ignores the hangup. The save now records the suspension's
cause and the pid and start token of its program and its detected agent
(`PaneSnapshot.suspension`, optional: older builds ignore it, older files
load). A restore runs the dead-program check first: while either may run,
or cannot be confirmed gone, the pane comes back suspended with that
reason, starts nothing, and reserves its agent session; the server checks
it again at once and resumes it in place once both are gone. Proven gone,
it restores as before. A file without the record restores as before; a
core pane's link decides for it, as before.

core-phase3 D2: a program is never started twice.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…start and a live handoff

Rows of fork issue 369: the record round-trips and older files load; a
restart with the old program or its agent running, or not confirmed gone,
brings the pane back suspended with nothing started and saves it again; a
session without the record restores as before; a live handoff keeps the
pane suspended; and a restored suspended pane resumes in place by its plan
once its old program is gone.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…tart and a handoff

D3 accepted that a restore or live handoff starts every suspended pane,
which contradicts core-phase3 D2. It now records the saved suspension and
the dead-program check a restore runs first.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…ram once

The check asked the process table twice for the same program: once to
find one that runs, once more to find one that may run. A probe that
failed on the first lookup and found the program on the second answered
neither, so a restore or a resume started the pane beside its old
program. Each recorded program is now probed once and that answer
decides: one that runs or cannot be confirmed gone blocks the start;
only both gone let it start.

Test: a_probe_that_fails_and_then_finds_the_program_blocks_the_start.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
… is checked again by itself

A resume round that found an old program running asked to look again;
one that could not confirm it gone (a failed probe) cleared its deadline,
so the pane stayed suspended after the probe recovered and the program
exited, until an attach or another loss asked again. Such a check now
keeps a deadline: the wait starts at the 10 s retry and doubles up to
5 minutes, and resets once a round confirms every old program. A program
that still runs keeps the 10 s retry.

Tests: a_pane_whose_probe_failed_resumes_by_itself_once_probing_recovers,
an_unconfirmed_check_waits_longer_each_time_up_to_a_bound; the never
recorded case of a_suspended_pane_resumes_only_after_its_old_program_is_gone
now expects the later check.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…s forced

A suspended pane has no runtime, so `pane respawn`, with or without
--resume, saw nothing running and started the pane, its saved agent
included, beside an old program that may still run: a pane restored
suspended after a restart or live handoff, or one suspended in this
server. Without --force a respawn of a suspended pane now makes the
check its resume makes first: while the program it ran or its detected
agent still runs, or cannot be confirmed gone, it answers
confirmation_required naming that and starts nothing. --force respawns
it anyway, as before.

Tests: a_respawn_of_a_restored_suspended_pane_waits_for_its_old_program_unless_forced,
a_respawn_of_a_suspended_pane_starts_it_once_its_old_program_is_gone.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…gent resume plans

A pane held suspended reserved its agent session only when the restore
reached it, so an ordinary pane earlier in the layout, or in an earlier
tab or workspace, that named the same session had already been given a
plan, and resumed the agent beside the held pane's old agent that may
still run. Two held panes that named one session both kept their plans.
The restore now decides, for the whole session and before any pane gets
a plan, which panes come back suspended, and takes the sessions their
old agents may hold (by the reported resume command and by the session
record). Any other pane naming one is a duplicate and gets no plan; of
two held panes only the first in layout order keeps its plan.

Tests: a_held_pane_keeps_its_agent_session_from_a_pane_before_or_after_it,
two_held_panes_that_name_one_session_keep_one_plan.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
…t unchanged

The pane history file names the session layout by a fingerprint of the
whole saved session. An older build drops the new suspension record when
it reads the session, so it computed another fingerprint and discarded
the history of every pane, an unrelated shell's scrollback included; its
next save made that loss permanent. The fingerprint now leaves each
pane's suspension out, so both builds compute the same one.

Test: a_pane_suspension_leaves_the_history_fingerprint_as_it_is.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/369
Work-Ref: WORK-05
@colangelo

Copy link
Copy Markdown
Owner Author

Landed on master after all-green CI and a passing just check.

@colangelo colangelo closed this Nov 29, 2026
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