diff --git a/mesh_missions/service.py b/mesh_missions/service.py index 0bfb1ab..7895069 100644 --- a/mesh_missions/service.py +++ b/mesh_missions/service.py @@ -277,13 +277,21 @@ def refresh_mission_runtime(self, mission: dict) -> dict: cooperative_tasks.append(self.mesh.get_cooperative_task(task_id)) except Exception as exc: cooperative_tasks.append({"id": task_id, "state": "failed", "error": str(exc), "children": []}) + resolved_cooperative_jobs: dict[str, dict] = {} for task in cooperative_tasks: for child in list(task.get("children") or []): - job_id = str(child.get("job_id") or ((child.get("job") or {}).get("id")) or "").strip() + job = dict(child.get("job") or {}) + job_id = str(child.get("job_id") or job.get("id") or "").strip() if job_id and job_id not in child_job_ids: child_job_ids.append(job_id) + if job_id and job: + job.setdefault("id", job_id) + resolved_cooperative_jobs[job_id] = job child_jobs: list[dict] = [] for job_id in child_job_ids: + if job_id in resolved_cooperative_jobs: + child_jobs.append(resolved_cooperative_jobs[job_id]) + continue try: child_jobs.append(self.mesh.get_job(job_id)) except Exception as exc: diff --git a/tests/test_sovereign_mesh.py b/tests/test_sovereign_mesh.py index 45b262e..aa0c11b 100644 --- a/tests/test_sovereign_mesh.py +++ b/tests/test_sovereign_mesh.py @@ -7537,6 +7537,16 @@ def test_mission_wraps_cooperative_task_launch(self): ) self.assertEqual(len(mission["lineage"]["cooperative_tasks"]), 1) + self.assertEqual(alpha.mesh.run_worker_once("alpha-worker")["status"], "completed") + self.assertEqual(beta.mesh.run_worker_once("beta-worker")["status"], "completed") + refreshed = alpha.mesh.get_mission(mission["id"]) + self.assertEqual(refreshed["status"], "completed") + self.assertEqual(refreshed["summary"]["child_status_counts"], {"completed": 2}) + self.assertEqual( + {job["target"] for job in refreshed["child_jobs"]}, + {"alpha-node", "beta-node"}, + ) + def test_cooperative_task_endpoints_are_exposed_over_http(self): alpha = self.make_stack("alpha") beta = self.make_stack("beta")