From 60f3af4af916a4a7bbc067f665a7d4e95748e8e5 Mon Sep 17 00:00:00 2001 From: Godopu Date: Sun, 12 Jul 2026 14:24:02 +0900 Subject: [PATCH] refactor(monitor): keep sessions alive on job completion, kill only on errors - Modify reconcile.sh mutation logic to clear delegate_job_id instead of calling tmux kill-session on 'completed' events - Retain process termination behavior on 'error' events for safety --- .../scripts/reconcile.sh | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.agents/skills/multi-agent-mux-monitor/scripts/reconcile.sh b/.agents/skills/multi-agent-mux-monitor/scripts/reconcile.sh index cb1f728..720cb90 100755 --- a/.agents/skills/multi-agent-mux-monitor/scripts/reconcile.sh +++ b/.agents/skills/multi-agent-mux-monitor/scripts/reconcile.sh @@ -118,16 +118,21 @@ _now = datetime.now(timezone.utc) _changed = False for s in d.get('tmux_sessions', []): if s.get('delegate_job_id') == _jid and s.get('status') == 'running': - s['status'] = 'terminated' - s['terminated_at'] = _now.strftime('%Y-%m-%dT%H:%M:%SZ') - s['terminated_at_epoch'] = int(_now.timestamp()) - s['termination_mode'] = 'auto-detected (MQTT ' + _event + ')' _name = s.get('name') _srv = s.get('tmux_server') or 'default' - _cmd = ['tmux'] + (['-L', _srv] if _srv != 'default' else []) + ['kill-session', '-t', _name] - subprocess.run(_cmd, capture_output=True) - print('MQTT Monitor: terminated + killed ' + str(_name) + ' on ' + str(_srv), flush=True) - _changed = True + if _event == 'completed': + s['delegate_job_id'] = None + print('MQTT Monitor: job completed on ' + str(_name) + ' — session kept alive', flush=True) + _changed = True + else: + s['status'] = 'terminated' + s['terminated_at'] = _now.strftime('%Y-%m-%dT%H:%M:%SZ') + s['terminated_at_epoch'] = int(_now.timestamp()) + s['termination_mode'] = 'auto-detected (MQTT ' + _event + ')' + _cmd = ['tmux'] + (['-L', _srv] if _srv != 'default' else []) + ['kill-session', '-t', _name] + subprocess.run(_cmd, capture_output=True) + print('MQTT Monitor: terminated + killed ' + str(_name) + ' on ' + str(_srv) + ' due to MQTT ' + _event, flush=True) + _changed = True if not _changed: raise SystemExit(0) # nothing matched — skip the write entirely '''