fix(resume): allow fresh spawn fallback and refresh epoch on 0-turn Class A resume

- Branch on Class A agents (agy, hermes, opencode) in resume_session.sh to fall back to clean spawn (CMD_FULL) when stopped before first turn (empty UUID)
- Update update_yaml_resumed.sh to support empty UUID with --cmd-full and refresh herdr_session_epoch on fresh spawn resume to prevent stale transcript capture
- Strictly preserve Class B (claude, grok) assigned UUID escape hatch and test_t8 contract
- Add regression tests test_t14, test_t15, test_t16 (Closes #3 Item 2)
This commit is contained in:
2026-08-31 10:30:44 +09:00
parent c49ee3bdd8
commit 7e15081d87
3 changed files with 204 additions and 23 deletions
@@ -51,9 +51,23 @@ esac
UUID=$(bash "$(dirname "${BASH_SOURCE[0]}")/resolve_session_id.sh" \
--workspace "$WORKSPACE" --agent "$AGENT" --session "$SESSION_NAME")
# ISSUE-3: agy/hermes/opencode (Class A) are spawned without a UUID - their
# own conversation id is only assigned by the agent itself on its first turn.
# A session stopped before any message therefore has no UUID to resolve here,
# but IS still cleanly recoverable: relaunching the agent's plain first-run
# spawn command restores the exact state multi-agent-mux-create would have
# produced. claude/grok (Class B) always resolve a UUID via the
# verify_session.py:99-101 assigned-but-unverified escape hatch (see test_t8)
# and never reach this branch - do not extend the fallback to them.
FRESH_SPAWN=0
if [ -z "$UUID" ]; then
echo "ERROR: No saved session for $WORKSPACE ($AGENT). Use multi-agent-mux-create first." >&2
exit 1
case "$AGENT" in
agy|hermes|opencode) FRESH_SPAWN=1 ;;
*)
echo "ERROR: No saved session for $WORKSPACE ($AGENT). Use multi-agent-mux-create first." >&2
exit 1
;;
esac
fi
if [ -n "$HERDR_SERVER_OPT" ]; then
@@ -96,16 +110,29 @@ if [ "$(uname)" = "Darwin" ] && [ -f "$RESOLVED_BIN" ]; then
fi
# Determine CMD_FULL via adapter
CMD_FULL="$("$(_delegate_py_bin)" -m lib_py.agents resume-spec "$AGENT" "$RESOLVED_BIN" "$UUID" "$WORKSPACE" 2>/dev/null || true)"
if [ -z "$CMD_FULL" ]; then
case "$AGENT" in
claude) CMD_FULL="${RESOLVED_BIN} --dangerously-skip-permissions -r $UUID" ;;
agy) CMD_FULL="${RESOLVED_BIN} --dangerously-skip-permissions --conversation $UUID" ;;
hermes) CMD_FULL="${RESOLVED_BIN} --resume $UUID --no-restore-cwd --yolo --accept-hooks" ;;
grok) CMD_FULL="${RESOLVED_BIN} --resume $UUID --permission-mode bypassPermissions" ;;
opencode) CMD_FULL="${RESOLVED_BIN} --session $UUID --auto --agent build" ;;
*) echo "ERROR: unsupported agent: $AGENT" >&2; exit 2 ;;
esac
if [ "$FRESH_SPAWN" = "1" ]; then
# ISSUE-3: no UUID to resume with - spawn the same plain first-run command
# multi-agent-mux-create would use (spawn-spec, not resume-spec).
CMD_FULL="$("$(_delegate_py_bin)" -m lib_py.agents spawn-spec "$AGENT" "$RESOLVED_BIN" "" 0 2>/dev/null || true)"
if [ -z "$CMD_FULL" ]; then
case "$AGENT" in
agy) CMD_FULL="${RESOLVED_BIN} --dangerously-skip-permissions" ;;
hermes) CMD_FULL="${RESOLVED_BIN} --yolo --accept-hooks" ;;
opencode) CMD_FULL="${RESOLVED_BIN} --auto --agent build" ;;
esac
fi
else
CMD_FULL="$("$(_delegate_py_bin)" -m lib_py.agents resume-spec "$AGENT" "$RESOLVED_BIN" "$UUID" "$WORKSPACE" 2>/dev/null || true)"
if [ -z "$CMD_FULL" ]; then
case "$AGENT" in
claude) CMD_FULL="${RESOLVED_BIN} --dangerously-skip-permissions -r $UUID" ;;
agy) CMD_FULL="${RESOLVED_BIN} --dangerously-skip-permissions --conversation $UUID" ;;
hermes) CMD_FULL="${RESOLVED_BIN} --resume $UUID --no-restore-cwd --yolo --accept-hooks" ;;
grok) CMD_FULL="${RESOLVED_BIN} --resume $UUID --permission-mode bypassPermissions" ;;
opencode) CMD_FULL="${RESOLVED_BIN} --session $UUID --auto --agent build" ;;
*) echo "ERROR: unsupported agent: $AGENT" >&2; exit 2 ;;
esac
fi
fi
# Validate binary exists and is executable
@@ -145,7 +172,7 @@ sleep 2
# 5. Update agent-sessions.yaml: status running, last_visible_status
bash "$(dirname "${BASH_SOURCE[0]}")/update_yaml_resumed.sh" \
--session "$SESSION_NAME" --uuid "$UUID" --agent "$AGENT" --workspace "$WORKSPACE" \
--herdr-session "$HERDR_SESSION_NAME" \
--herdr-session "$HERDR_SESSION_NAME" --cmd-full "$CMD_FULL" \
${HERDR_WORKSPACE_OPT:+--herdr-workspace "$HERDR_WORKSPACE_OPT"}
echo "Successfully resumed $SESSION_NAME ($AGENT)"