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 '''