Files
microdao-daarion/services/city-service/repo_city.py_fragment.py

39 lines
1.9 KiB
Python

# TASK 038: Dynamic discovery of Node Guardian / Steward if cache is empty
if not data.get("guardian_agent") or not data.get("steward_agent"):
dynamic_agents = await pool.fetch("""
SELECT id, display_name, kind, public_slug
FROM agents
WHERE node_id = $1
AND (kind IN ('node_guardian', 'node_steward') OR kind IN ('infra_monitor', 'infra_ops'))
AND COALESCE(is_archived, false) = false
""", node_id)
if not data.get("guardian_agent"):
# Prefer 'node_guardian', fallback to 'infra_monitor'
guardian_candidates = [a for a in dynamic_agents if a['kind'] == 'node_guardian']
monitor_candidates = [a for a in dynamic_agents if a['kind'] == 'infra_monitor']
guardian = guardian_candidates[0] if guardian_candidates else (monitor_candidates[0] if monitor_candidates else None)
if guardian:
data["guardian_agent"] = {
"id": guardian["id"],
"name": guardian["display_name"],
"kind": guardian["kind"],
"slug": guardian["public_slug"],
}
if not data.get("steward_agent"):
# Prefer 'node_steward', fallback to 'infra_ops'
steward_candidates = [a for a in dynamic_agents if a['kind'] == 'node_steward']
ops_candidates = [a for a in dynamic_agents if a['kind'] == 'infra_ops']
steward = steward_candidates[0] if steward_candidates else (ops_candidates[0] if ops_candidates else None)
if steward:
data["steward_agent"] = {
"id": steward["id"],
"name": steward["display_name"],
"kind": steward["kind"],
"slug": steward["public_slug"],
}