"""Read-only /proc observer for this exact job's descendants; no requests/signals."""
import ast,json,time
from pathlib import Path
script=Path('public/evidence/seleniumbase-public-30-20260929/run.py').resolve();out=Path('runner/data/seleniumbase-public-30-20260930').resolve();binary=Path('/tmp/scrapingevals-patchright-amazon-20260929/browsers/chromium-1243/chrome-linux64/chrome').resolve()
ns={'Path':Path};tree=ast.parse(script.read_text());node=next(n for n in tree.body if getattr(n,'name',None)=='tree_members');exec(compile(ast.Module(body=[node],type_ignores=[]),'proc-only','exec'),ns)
observations={};started=time.monotonic()
while time.monotonic()-started<600:
 for p in Path('/proc').glob('[0-9]*/cmdline'):
  try:
   a=p.read_bytes().decode(errors='replace').split('\0')
   if len(a)<3 or a[1]!=str(script) or '--single' not in a or '--output' not in a or a[a.index('--output')+1]!=str(out):continue
   target=a[a.index('--single')+1]
   if target in observations:continue
   for pid in ns['tree_members'](int(p.parent.name)):
    q=Path(f'/proc/{pid}');args=(q/'cmdline').read_bytes().decode(errors='replace').strip('\0').split('\0')
    if (q/'exe').resolve()==binary and len(args)>1 and not any(x.startswith('--type=') for x in args[1:]):
     observations[target]={'chrome_pid':pid,'worker_pid':int(p.parent.name),'arguments':args[1:]};print(target,json.dumps(args[1:]),flush=True)
     (out/'observed-launch-arguments.json').write_text(json.dumps(observations,indent=2)+'\n');break
  except (OSError,ValueError):pass
 if (out/'results.json').exists() and json.loads((out/'results.json').read_text()).get('finished_at'):break
 time.sleep(.1)
print('Observed owned Chrome arguments for',len(observations),'targets',flush=True)
