supervisor: unique cc-ci-supervisor web-UI name (same invariant as the upgrader)
_archive_stale_titles() generalized to (title, label); launch-supervisor's
spawn_supervisor() archives every older 'cc-ci-supervisor' session before
launching, so exactly one session carries the name. 11 historical supervisor
sessions archive-renamed live ('supervisor archive — <date> <time>').
This commit is contained in:
@@ -98,6 +98,12 @@ def spawn_supervisor(sid, reason):
|
||||
Path(LOG_DIR).mkdir(parents=True, exist_ok=True)
|
||||
if _sup_alive():
|
||||
_sup_kill(); time.sleep(1)
|
||||
# Unique-name invariant (same as the upgrader): archive-rename every older session titled
|
||||
# SUP_SESSION so the one this launch creates is the ONLY 'cc-ci-supervisor' in the web UI.
|
||||
try:
|
||||
lu._archive_stale_titles(SUP_SESSION, "supervisor archive —")
|
||||
except Exception:
|
||||
pass
|
||||
kf = Path(LOG_DIR) / f".kickoff-{SUP_SESSION}.txt"
|
||||
kf.write_text(build_kickoff(sid, reason))
|
||||
share = "--share" if OPENCODE_SHARE else ""
|
||||
|
||||
@@ -286,19 +286,22 @@ def _db_created_ms(sid):
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
def _archive_stale_titles():
|
||||
"""Rename every existing top-level session titled SESSION to a dated archive title, so
|
||||
EXACTLY ONE session ever carries the canonical name (the one this launch creates). This
|
||||
keeps the run trivially findable in the opencode web UI and makes the title lookup in
|
||||
_session_id() unambiguous. Old runs stay browsable under 'upgrader archive — weekly <date>'."""
|
||||
def _archive_stale_titles(title=None, label=None):
|
||||
"""Rename every existing top-level session with the given canonical title to a dated
|
||||
archive title, so EXACTLY ONE session ever carries the canonical name (the one the next
|
||||
launch creates). Keeps the run trivially findable in the opencode web UI and makes the
|
||||
title lookup in _session_id() unambiguous. Old runs stay browsable under
|
||||
'<label> — <date>'. Also used by launch-supervisor.py for its own session name."""
|
||||
title = title or SESSION
|
||||
label = label or ("upgrader archive — weekly" if title == "cc-ci-upgrader" else f"{title} archive —")
|
||||
rows = _server_get("/session") or []
|
||||
rows = rows if isinstance(rows, list) else rows.get("data", [])
|
||||
for s in rows:
|
||||
if s.get("title") == SESSION and not (s.get("parentID") or s.get("parentId")):
|
||||
if s.get("title") == title and not (s.get("parentID") or s.get("parentId")):
|
||||
created = _db_created_ms(s["id"])
|
||||
d = datetime.fromtimestamp(created / 1000).strftime("%Y-%m-%d") if created else "unknown-date"
|
||||
_server_patch(f"/session/{s['id']}", {"title": f"upgrader archive — weekly {d}"})
|
||||
log(f" archived old session {s['id'][:20]} → 'upgrader archive — weekly {d}'")
|
||||
_server_patch(f"/session/{s['id']}", {"title": f"{label} {d}"})
|
||||
log(f" archived old session {s['id'][:20]} → '{label} {d}'")
|
||||
|
||||
def _session_id():
|
||||
"""The opencode session this launcher manages. Prefers the pinned id recorded at launch
|
||||
|
||||
Reference in New Issue
Block a user