feat(swarm): bridge swarm slot dispatch to native muse_hybrid subagent sessions

This commit is contained in:
operator
2026-10-05 15:56:59 +00:00
parent 7b1998f00e
commit 447e9c1cc7
+29 -7
View File
@@ -1042,13 +1042,33 @@ def reconcile_and_dispatch_swarms(dry_run=False):
f"Reply with [RESULT {sid}/{slot_idx}] OK <summary> or FAIL <reason>." f"Reply with [RESULT {sid}/{slot_idx}] OK <summary> or FAIL <reason>."
) )
# Verified dispatch: confirm the send landed BEFORE # Native Subagent Execution Bridge:
# marking the slot running. Fire-and-forget used to # Spawns an interactive child session directly on the target worker
# freeze slots from birth -- the slot read "running" # via muse_hybrid (Option 3), ensuring an active consumer actually executes
# while no worker was ever notified (2026-10-05: dev's # the prompt and returns results.
# wedged WireGuard data path silently killed every
# gateway dispatch).
dispatch_ok = False dispatch_ok = False
subagent_sid = None
try:
import muse_hybrid
sub_res, sub_err = muse_hybrid.start_session(worker, title=f"swarm-{sid[:8]}-s{slot_idx}")
if not sub_err and sub_res and sub_res.get("session_id"):
subagent_sid = sub_res["session_id"]
send_res, send_err = muse_hybrid.send_message(worker, prompt, thread_id=subagent_sid, wait=0)
if not send_err:
dispatch_ok = True
try:
import subagent_tracker
subagent_tracker.register_session(creator, subagent_sid, title=f"{sid}-s{slot_idx}", prompt=prompt)
except Exception:
pass
print(f"[swarm] Dispatched slot {slot_idx} of {sid} to native subagent session {subagent_sid} on {worker}")
if not dispatch_ok:
sys.stderr.write(f"warning: native subagent dispatch failed for {sid} slot {slot_idx} -> {worker} (err: {sub_err or send_err})\n")
except Exception as se:
sys.stderr.write(f"warning: muse_hybrid subagent dispatch exception: {se}\n")
# Fallback to dm.py send if native session creation fails
if not dispatch_ok:
try: try:
dm_cmd = [ dm_cmd = [
sys.executable, str(BIN_DIR / "dm.py"), "send", sys.executable, str(BIN_DIR / "dm.py"), "send",
@@ -1064,7 +1084,7 @@ def reconcile_and_dispatch_swarms(dry_run=False):
dispatch_ok = (proc.returncode == 0 and "SENT" in _dout) dispatch_ok = (proc.returncode == 0 and "SENT" in _dout)
if not dispatch_ok: if not dispatch_ok:
sys.stderr.write( sys.stderr.write(
"warning: swarm dispatch unverified %s slot %d -> %s " "warning: swarm fallback dispatch unverified %s slot %d -> %s "
"(rc=%d out=%.100s err=%.100s)\n" "(rc=%d out=%.100s err=%.100s)\n"
% (sid, slot_idx, worker, proc.returncode, % (sid, slot_idx, worker, proc.returncode,
_dout, proc.stderr or "")) _dout, proc.stderr or ""))
@@ -1101,6 +1121,8 @@ def reconcile_and_dispatch_swarms(dry_run=False):
s["agent_id"] = worker s["agent_id"] = worker
s["status"] = "running" s["status"] = "running"
s["updated_ts"] = now s["updated_ts"] = now
if subagent_sid:
s["subagent_session_id"] = subagent_sid
busy_workers.add(worker) busy_workers.add(worker)
modified = True modified = True
print(f"[swarm] Dispatched slot {slot_idx} of {sid} to {worker} in sidechat {slot_target}") print(f"[swarm] Dispatched slot {slot_idx} of {sid} to {worker} in sidechat {slot_target}")