feat(harvester): add 2-turn emergency escalation follow-up to opm on persistent silence stalls

This commit is contained in:
operator
2026-10-05 05:30:36 +00:00
parent 3f1051cf7b
commit eba084b046
+42 -23
View File
@@ -1057,31 +1057,50 @@ def maybe_nudge_untagged_sidechat(agent, thread_id, thread_name, mid, text, dry_
tracker = load_json_file(NUDGE_TRACKER_FILE) tracker = load_json_file(NUDGE_TRACKER_FILE)
rec = tracker.get(thread_id, {}) rec = tracker.get(thread_id, {})
if rec.get("nudged_for_mid") == mid or rec.get("nudge_count", 0) >= 1: if rec.get("nudged_for_mid") == mid:
return return
# Inject strict tool directive footer n_count = rec.get("nudge_count", 0)
thread_url = f"https://box.muse-dev.online/thread/{thread_id}"
nudge_msg = ( # 1st turn: Strict rejection and tool invocation prompt
f"[STRICT ENFORCEMENT: Conversational commentary is rejected. Work requires active execution.]\n" if n_count == 0:
f"Thread Console: {thread_url}\n" thread_url = f"https://box.muse-dev.online/thread/{thread_id}"
f"You must emit an executable tool call: [TOOL <op> <args>] or curl command against https://box.muse-dev.online/exec\n" nudge_msg = (
f"Example: [TOOL service.status {{\"unit\": \"board.service\"}}] or [TOOL followup.create {{\"in_m\": 10, \"prompt\": \"continue\"}}]\n" f"[STRICT ENFORCEMENT: Conversational commentary is rejected. Work requires active execution.]\n"
f"When all operations are finished, close strictly with [RESULT {matching_job_id}] <outcome>." f"Thread Console: {thread_url}\n"
) f"You must emit an executable tool call: [TOOL <op> <args>] or curl command against https://box.muse-dev.online/exec\n"
try: f"Example: [TOOL service.status {{\"unit\": \"board.service\"}}] or [TOOL followup.create {{\"in_m\": 10, \"prompt\": \"continue\"}}]\n"
import muse_hybrid f"When all operations are finished, close strictly with [RESULT {matching_job_id}] <outcome>."
print(f"[{agent}] Injecting 1-turn nudge into {thread_name or thread_id[:8]} for job {matching_job_id}") )
muse_hybrid.send_message(agent, nudge_msg, thread_id=thread_id, wait=0) try:
tracker[thread_id] = { import muse_hybrid
"ts": utcnow(), print(f"[{agent}] Injecting 1-turn strict nudge into {thread_name or thread_id[:8]} for job {matching_job_id}")
"job_id": matching_job_id, muse_hybrid.send_message(agent, nudge_msg, thread_id=thread_id, wait=0)
"nudged_for_mid": mid, tracker[thread_id] = {
"nudge_count": rec.get("nudge_count", 0) + 1, "ts": utcnow(),
} "job_id": matching_job_id,
save_json_file(NUDGE_TRACKER_FILE, tracker) "nudged_for_mid": mid,
except Exception as ne: "nudge_count": 1,
sys.stderr.write(f"warning: failed to deliver conversational nudge: {ne}\n") }
save_json_file(NUDGE_TRACKER_FILE, tracker)
except Exception as ne:
sys.stderr.write(f"warning: failed to deliver conversational nudge: {ne}\n")
# 2nd turn: Trigger emergency 5m escalation follow-up to opm/coordinator
elif n_count == 1 and not rec.get("escalated"):
print(f"[{agent}] Conversational stall persisted in {thread_name or thread_id[:8]} - scheduling emergency escalation to opm")
esc_prompt = f"[ESCALATION] Agent {agent} stalled in thread {thread_name or thread_id[:8]} on job {matching_job_id}. Review thread or reassign."
try:
cmd = [
"systemd-run", "--user", "--on-active=300s",
sys.executable, str(BIN_DIR / "box-ctl.py"), "notify", "opm", esc_prompt, "--sender", agent
]
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
tracker[thread_id]["escalated"] = True
tracker[thread_id]["escalated_ts"] = utcnow()
save_json_file(NUDGE_TRACKER_FILE, tracker)
except Exception as ee:
sys.stderr.write(f"warning: failed to schedule emergency escalation: {ee}\n")