#!/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 from faults import report_process 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) fault_path=root/'bridge-faults.json' faults=json.loads(fault_path.read_text(encoding='utf-8')).get('roles',{}) if fault_path.exists() else {} processes={} started_at={} logs={} next_start={} roles=['worker','mirror'] if cfg.get('notification_targets'):roles.append('notifier') if cfg.get('task_report_config'):roles.append('report_relay') if cfg.get('decision_fleet',{}).get('enabled'):roles.append('decision_fleet') 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 roles: process=processes.get(role) if process and cfg.get('notification_targets'): report_process(cfg,root,role,process,faults,started_at.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()