fix(issue-45): resume closes the session's own restored empty shell

After a restart with restore off, the session's saved pane comes back as an
empty shell (in $HOME when its directory is gone) holding the agent_session it
reported. A resume with a CP_PREFIX cannot reuse it, so it stayed next to the
new pane. Just before spawning, resume closes panes whose agent_session is the
id being resumed, with no live agent and only the shell in the foreground; the
registry is not consulted, since a session whose server died stays running.

tests/test_issue45_restore.py drives a real herdr server under a throwaway HOME
and session with a fake claude: restore stays off through the MAM bootstrap
(with a restore-on control), the close conditions, and create -> crash ->
resume leaving one pane.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GodopuandClaude Opus 5.5 committed 2026-10-04 10:32:49 +00:00
1 parent 933af344c2
commit fb1380fdc1
3 files changed
+438

No files matched your search

@@ -233,6 +233,14 @@ if [ "$AGENT" = "opencode" ]; then
fi
fi
# Issue #45: a restarted server brings this session's old pane back as an empty
# shell (restore-on-restart is off on MAM servers). The shim cannot reuse it when
# a CP_PREFIX is passed, nor when it fell back to $HOME, so close it first; the
# conditions live in lib_py/herdr_restore.py. Never blocks the resume.
"$(_delegate_py_bin)" -m lib_py.herdr_restore close-restored-shells --session-id "$UUID" \
--herdr "$(_resolve_real_herdr_path || true)" \
|| echo "WARNING: could not close the restored panes of $SESSION_NAME; an empty shell may remain" >&2
# 4. Spawn new agent session (delegates to herdr translation shim)
_herdr new-session -d -s "$SESSION_NAME" -c "$WORKSPACE" "$CP_PREFIX$CMD_FULL"
# Issue #24: every agent, the same call create makes. The signatures and accept