perf(skills): optimize sleeps and modularize duplication with multi-agent consensus PASS

- OP-1: Implement reactive _wait_session_gone in lib.sh and stop_session.sh with set -e || true guard
- OP-2: Event-driven MQTT subscribe handshake with sub_pid liveness in delegate-job
- OP-3: Replace CPU time.sleep(0.5) spin with threading.Event wait in reconcile.sh
- OP-4: Define mam_tmux dispatcher targeting resolved _REAL_TMUX_PATH to prevent recursion
- OP-6 & OP-7: Add token variables and bash version source check in lib.sh
- Integrate approved optimization plan and PASS review reports from all agents
This commit is contained in:
2026-07-11 10:08:41 +09:00
parent 25de01eaad
commit 7eeb4b709a
11 changed files with 1148 additions and 24 deletions
@@ -239,17 +239,29 @@ if not state['connected']:
client.loop_stop()
sys.exit(3)
import threading
stop_event = threading.Event()
start = time.time()
try:
while True:
now = time.time()
if timeout and (now - start) >= timeout:
print(f"MQTT Monitor: --timeout {timeout}s reached, exiting", flush=True)
wall_left = (timeout - (now - start)) if timeout else None
idle_left = (idle_timeout - (now - state['last_msg'])) if idle_timeout else None
next_timeout = 5.0
if wall_left is not None:
next_timeout = min(next_timeout, wall_left)
if idle_left is not None:
next_timeout = min(next_timeout, idle_left)
if next_timeout <= 0:
if wall_left is not None and wall_left <= 0:
print(f"MQTT Monitor: --timeout {timeout}s reached, exiting", flush=True)
else:
print(f"MQTT Monitor: --idle-timeout {idle_timeout}s reached, exiting", flush=True)
break
if idle_timeout and (now - state['last_msg']) >= idle_timeout:
print(f"MQTT Monitor: --idle-timeout {idle_timeout}s reached, exiting", flush=True)
break
time.sleep(0.5)
stop_event.wait(timeout=next_timeout)
finally:
client.loop_stop()
try: