feat(sidechats): headless gateway new channel auto-provisioning and dedicated heartbeat channel

This commit is contained in:
operator
2026-10-05 02:27:23 +00:00
parent 9f27dbd592
commit ec547b28ac
7 changed files with 200 additions and 14 deletions
+47 -4
View File
@@ -455,14 +455,57 @@ def main():
target = p_entry.get("target") or f"pipe-{pipeline_run_id.split('-')[-1]}"
else:
target = f"pipe-{pipeline_run_id.split('-')[-1]}"
elif job.get("sidechat", {}).get("create"):
sc_cfg = job.get("sidechat", {})
sc_name = render_prompt(sc_cfg.get("name_template", "job-{job_name}-{date}"), variables)
reuse_key = sc_cfg.get("reuse_key")
# Check if reuse_key exists in job-sidechats.json and thread is still alive
sc_state = load_sidechat_state()
reused_uuid = None
if reuse_key and reuse_key in sc_state:
val = sc_state[reuse_key]
cand_uuid = val.get("thread_uuid") if isinstance(val, dict) else val
if cand_uuid:
try:
import muse_hybrid
threads, err = muse_hybrid.get_threads(agent)
if not err and threads:
thread_ids = [t.get("session_id") for t in threads]
if cand_uuid in thread_ids:
reused_uuid = cand_uuid
except Exception:
pass
if reused_uuid:
target = reused_uuid
else:
# Spawn a brand new sidechat/channel via fast headless gateway!
channel_title = sc_name
try:
import muse_hybrid
res, err = muse_hybrid.start_session(agent, title=channel_title)
if res and not err and res.get("session_id"):
new_uuid = res.get("session_id")
key_to_save = reuse_key or sc_name
sc_state[key_to_save] = {
"thread_uuid": new_uuid,
"agent": agent,
"title": channel_title,
"created_at": datetime.now(timezone.utc).isoformat()
}
save_sidechat_state(sc_state)
target = new_uuid
print(f"Spawned new sidechat channel '{channel_title}' ({new_uuid}) for {agent}")
else:
target = sc_name
except Exception as e:
sys.stderr.write(f"warning: fast gateway session-start exception ({e}), falling back to name {sc_name}\n")
target = sc_name
elif job.get("dm_target"):
target = job.get("dm_target").strip()
elif job.get("target"):
target = job.get("target").strip()
elif job.get("sidechat", {}).get("create"):
sc_cfg = job.get("sidechat", {})
sc_name = render_prompt(sc_cfg.get("name_template", "job-{job_name}-{date}"), variables)
target = sc_name
# Sidechat-first policy (2026-10-04): refuse to dispatch to main chat
# unless the job explicitly opts in. Never fall back to main silently.