Skip to content

Commit a668fbb

Browse files
committed
fix: stabilize runtime run ordering
1 parent 5d8fa5d commit a668fbb

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

apps/orchestrator/src/cortexpilot_orch/services/control_plane_read_service.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,31 @@ def _last_event_ts(run_id: str) -> str:
178178
return value
179179
return ""
180180

181+
def _run_sort_ts(run_dir: Path, manifest_record: dict[str, Any]) -> float:
182+
manifest_path = run_dir / "manifest.json"
183+
if manifest_path.exists():
184+
return manifest_path.stat().st_mtime
185+
created_at = _as_text(manifest_record.get("created_at"))
186+
if created_at:
187+
try:
188+
return _parse_iso_ts(created_at).timestamp()
189+
except Exception:
190+
pass
191+
return run_dir.stat().st_mtime
192+
181193
def _list_runs_runtime() -> list[dict[str, Any]]:
182194
results: list[dict[str, Any]] = []
183-
for run_dir in sorted(runs_root.glob("*"), key=lambda item: item.stat().st_mtime, reverse=True):
195+
run_dirs = []
196+
for run_dir in runs_root.glob("*"):
197+
if not run_dir.is_dir():
198+
continue
184199
manifest = _read_json(run_dir / "manifest.json", {})
185200
manifest_record = _as_record(manifest)
186201
if not manifest_record:
187202
continue
203+
run_dirs.append((run_dir, manifest_record, _run_sort_ts(run_dir, manifest_record)))
204+
205+
for run_dir, manifest_record, _sort_ts in sorted(run_dirs, key=lambda item: item[2], reverse=True):
188206
run_id = _as_text(manifest_record.get("run_id")) or run_dir.name
189207
payload = dict(manifest_record)
190208
payload["run_id"] = run_id

0 commit comments

Comments
 (0)