#!/usr/bin/env python3 """Keep the local queue worker and visible-history mirror available without exporting auth.""" import argparse import json import os from pathlib import Path import subprocess import sys import time from worker import atomic_json,session_lock def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--config',required=True) args=parser.parse_args() config_path=Path(args.config).resolve() cfg=json.loads(config_path.read_text(encoding='utf-8-sig')) root=Path(cfg['state_file']).expanduser().resolve().parent root.mkdir(parents=True,exist_ok=True,mode=0o700) if os.name=='posix':os.umask(0o077) identity='supervisor:'+json.dumps({'control':cfg['control'],'session_id':cfg['session_id']},sort_keys=True) processes={} logs={} next_start={} with session_lock(identity): try: while True: state_path=Path(cfg['state_file']).expanduser() state=json.loads(state_path.read_text(encoding='utf-8')) if state_path.exists() else {} for role in ('worker','mirror'): process=processes.get(role) if process and process.poll() is None:continue if role=='worker' and (state.get('needs_reconciliation') or (state.get('inflight') and not state.get('pending_completion'))): continue if time.monotonic()