"""Read-only compact progress snapshot; never loads service credentials.""" import json from pathlib import Path import sqlite3 import sys sys.stdout.reconfigure(encoding="utf-8") root=Path(__file__).resolve().parents[2]/"data/tts-pilot/corpus50000-20261114" phase=json.loads((root/"orchestrator.json").read_text(encoding="utf-8-sig")) snapshot={"phase":phase["phase"]} if phase["phase"]=="PREPARING_TEXT": database=sqlite3.connect(root/"preparation.sqlite3",timeout=10) try: database.execute("PRAGMA query_only=ON") snapshot["reviewed_groups"]=dict(database.execute("SELECT stage,COUNT(*) FROM jobs GROUP BY stage")) snapshot["unique_reviewed_texts"]=database.execute("SELECT COUNT(*) FROM accepted_texts").fetchone()[0] snapshot["last_event_at"]=database.execute("SELECT created_at FROM events ORDER BY id DESC LIMIT 1").fetchone()[0] finally:database.close() progress=root/"progress.json" if progress.exists(): saved=json.loads(progress.read_text(encoding="utf-8")) snapshot.update({k:saved[k] for k in ("completed","attempted","elapsed_ms") if k in saved}) if saved.get("error"):snapshot["error"]=saved["error"] else:snapshot["completed"]=0 if phase["phase"]=="STOPPED_ON_ERROR": snapshot["error"]=phase.get("detail") print(json.dumps(snapshot,ensure_ascii=False)) if phase["phase"]=="STOPPED_ON_ERROR": print((root/"production.stdout.log").read_text(encoding="utf-8",errors="replace")[-3000:]) print((root/"production.stderr.log").read_text(encoding="utf-8",errors="replace")[-3500:])