fix: Callbacks can't see the resolved _session from monitor_phase_loop (#200)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ba8bb5637e
commit
e853949b47
2 changed files with 8 additions and 3 deletions
|
|
@ -290,15 +290,15 @@ gardener_phase_callback() {
|
||||||
log "WARNING: tmux session died unexpectedly — attempting recovery"
|
log "WARNING: tmux session died unexpectedly — attempting recovery"
|
||||||
rm -f "$RESULT_FILE"
|
rm -f "$RESULT_FILE"
|
||||||
touch "$RESULT_FILE"
|
touch "$RESULT_FILE"
|
||||||
if create_agent_session "$SESSION_NAME" "$PROJECT_REPO_ROOT" 2>/dev/null; then
|
if create_agent_session "${_MONITOR_SESSION:-$SESSION_NAME}" "$PROJECT_REPO_ROOT" 2>/dev/null; then
|
||||||
agent_inject_into_session "$SESSION_NAME" "$PROMPT"
|
agent_inject_into_session "${_MONITOR_SESSION:-$SESSION_NAME}" "$PROMPT"
|
||||||
log "Recovery session started"
|
log "Recovery session started"
|
||||||
else
|
else
|
||||||
log "ERROR: could not restart session after crash"
|
log "ERROR: could not restart session after crash"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
PHASE:done|PHASE:failed|PHASE:needs_human|PHASE:merged)
|
PHASE:done|PHASE:failed|PHASE:needs_human|PHASE:merged)
|
||||||
agent_kill_session "$SESSION_NAME"
|
agent_kill_session "${_MONITOR_SESSION:-$SESSION_NAME}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,8 @@ inject_formula() {
|
||||||
|
|
||||||
# Monitor a phase file, calling a callback on changes and handling idle timeout.
|
# Monitor a phase file, calling a callback on changes and handling idle timeout.
|
||||||
# Sets _MONITOR_LOOP_EXIT to the exit reason (idle_timeout, done, failed, break).
|
# Sets _MONITOR_LOOP_EXIT to the exit reason (idle_timeout, done, failed, break).
|
||||||
|
# Sets _MONITOR_SESSION to the resolved session name (arg 4 or $SESSION_NAME).
|
||||||
|
# Callbacks should reference _MONITOR_SESSION instead of $SESSION_NAME directly.
|
||||||
# Args: phase_file idle_timeout_secs callback_fn [session_name]
|
# Args: phase_file idle_timeout_secs callback_fn [session_name]
|
||||||
# session_name — tmux session to health-check; falls back to $SESSION_NAME global
|
# session_name — tmux session to health-check; falls back to $SESSION_NAME global
|
||||||
monitor_phase_loop() {
|
monitor_phase_loop() {
|
||||||
|
|
@ -68,6 +70,9 @@ monitor_phase_loop() {
|
||||||
local idle_timeout="$2"
|
local idle_timeout="$2"
|
||||||
local callback="$3"
|
local callback="$3"
|
||||||
local _session="${4:-${SESSION_NAME:-}}"
|
local _session="${4:-${SESSION_NAME:-}}"
|
||||||
|
# Export resolved session name so callbacks can reference it regardless of
|
||||||
|
# which session was passed to monitor_phase_loop (analogous to _MONITOR_LOOP_EXIT).
|
||||||
|
export _MONITOR_SESSION="$_session"
|
||||||
local poll_interval="${PHASE_POLL_INTERVAL:-10}"
|
local poll_interval="${PHASE_POLL_INTERVAL:-10}"
|
||||||
local last_mtime=0
|
local last_mtime=0
|
||||||
local idle_elapsed=0
|
local idle_elapsed=0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue