"""Paired shade diagnostic: only installed Settings/UI wrapper selection differs.""" from pathlib import Path import datetime, hashlib, importlib.util, json, os, pwd, socket, subprocess, sys, time, threading CANDIDATE = '--candidate' in sys.argv CONFIG = json.loads(Path('/run/pane23-shade-status/identity.json').read_text()) SELECTED = CONFIG['candidate_ui_wrapper'] if CANDIDATE else CONFIG['baseline_ui_wrapper'] SETTINGS = CONFIG['candidate_settings'] if CANDIDATE else CONFIG['baseline_settings'] D = Path('/run/shell/pane23-shade-status-' + ('candidate-a' if CANDIDATE else 'baseline-a')) priority_changes={} DROP = Path('/run/systemd/system/shell-ui.service.d/90-pane23-shade-status-trace.conf') BOOT = '69e90426-5ead-4ebb-82d5-2a592168e34d' SYSTEM = '/nix/store/hpmzja32mncizz7s49ylr8pj9cy5npvg-nixos-system-nixos-26.11.20260919.20b1ddd' FALLBACK = SYSTEM TRACE = D / 'trace.json' PYTHON = sys.executable def run(*cmd): return subprocess.check_output(cmd, text=True, timeout=20).strip() def save(name, value): (D/name).write_text(json.dumps(value, indent=2)+'\n') def sha(path): return hashlib.sha256(Path(path).read_bytes()).hexdigest() def now(): return datetime.datetime.now(datetime.timezone.utc).isoformat() spec = importlib.util.spec_from_file_location('capture', '/run/pane23-shade-status/hdmi-shell-capture-board.py') cap = importlib.util.module_from_spec(spec); spec.loader.exec_module(cap) def identity(): ipc=cap.IPC() try: outputs=cap.output_state(ipc.outputs()); sway=ipc.pid finally: ipc.close() rust=int(run('systemctl','show','shell-ui','--property=MainPID','--value')) env=dict(x.partition(b'=')[::2] for x in Path(f'/proc/{rust}/environ').read_bytes().split(b'\0') if b'=' in x) settings=os.fsdecode(env[b'K230_SETTINGS']) return dict(utc=now(), boot_id=Path('/proc/sys/kernel/random/boot_id').read_text().strip(), system=os.path.realpath('/run/current-system'), persistent_system=os.path.realpath('/nix/var/nix/profiles/system'), outputs=outputs, sway_pid=sway, sway_executable=os.path.realpath(f'/proc/{sway}/exe'), sway_sha256=sha(f'/proc/{sway}/exe'), rust_pid=rust, rust_executable=os.path.realpath(f'/proc/{rust}/exe'), rust_sha256=sha(f'/proc/{rust}/exe'), settings_wrapper=settings,settings_wrapper_sha256=sha(settings), services=run('systemctl','is-active','shell','shell-ui').splitlines(), cpu_online=Path('/sys/devices/system/cpu/online').read_text().strip()) def guard(v): assert v['boot_id']==BOOT and v['system']==SYSTEM and v['persistent_system']==FALLBACK assert len(v['outputs'])==1 and v['outputs'][0]['name']=='DSI-1' assert v['outputs'][0]['rect']['width']==1232 and v['outputs'][0]['rect']['height']==568 assert v['outputs'][0]['transform']=='270' assert v['services']==['active','active'] assert v['sway_sha256']==CONFIG['sway_sha256'] and v['rust_sha256']==CONFIG['rust_sha256'] assert sha('/sys/kernel/notes')==CONFIG['kernel_notes_sha256'] assert Path('/sys/kernel/tracing/current_tracer').exists()==CONFIG['tracefs_mounted'] for name,h in CONFIG['boot_files'].items():assert sha('/boot/'+name)==h for name,h in CONFIG['tracing'].items():assert sha('/sys/kernel/tracing/'+name)==h def sender(): account=pwd.getpwnam('shell'); os.setgroups([]); os.setgid(account.pw_gid); os.setuid(account.pw_uid) rows=[] for gesture in range(3): # Real protocol, synthetic reveal. No physical touch or compositor input claim. with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as peer: peer.settimeout(2); peer.connect('/run/shell/k230-shell-rust.sock') seq=230000+gesture for index, (phase, progress) in enumerate([('begin',0)]+[('update',round(i*1000/60)) for i in range(1,61)]+[('finish',0)]): deadline=time.monotonic()+1/60 message=dict(v=1,kind='reveal',surface='shade',phase=phase,seq=seq,progress=progress) peer.sendall((json.dumps(message,separators=(',',':'))+'\n').encode()) rows.append(dict(gesture=gesture,phase=phase,progress=progress,sent_monotonic_ns=time.monotonic_ns())) time.sleep(max(0,deadline-time.monotonic())) time.sleep(.5) time.sleep(.5) print(json.dumps(rows)) if len(sys.argv)>1 and sys.argv[1]=='--send': sender(); raise SystemExit(0) assert not D.exists() and not DROP.exists() D.mkdir(mode=0o700); account=pwd.getpwnam('shell'); os.chown(D,account.pw_uid,account.pw_gid) manifest=dict(treatment='native fresh Settings status' if CANDIDATE else 'original Python Settings status',started_at=now(),source_sha256=sha(__file__),status='PREPARING', workload='Three synthetic shade reveal streams: begin, 60 updates at 60Hz (0..1000), finish closed, 0.5s settle and 0.5s inter-gesture pause. Panel landscape1232x568.', limits='Installed Rust client spans and presentation feedback; bypasses physical input and compositor gesture routing. Restarted client, cold startup included separately. No optical/finger-latency claim.') save('manifest.json',manifest) before=identity(); guard(before); save('before.json',before) assert before['settings_wrapper']==CONFIG['baseline_settings'] assert sha(SELECTED)==CONFIG['ui_wrapper_hashes'][SELECTED] assert sha(SETTINGS)==CONFIG['settings_wrapper_hashes'][SETTINGS] space={p:dict(block_size=(v:=os.statvfs(p)).f_frsize,free_blocks=v.f_bfree,unprivileged_available_blocks=v.f_bavail) for p in ('/var/tmp','/run/shell')} save('space.json',space) assert space['/run/shell']['unprivileged_available_blocks']*space['/run/shell']['block_size']>32*1024*1024 drop_written=False assert not Path('/run/systemd/transient/pane23-shade-status-restore.timer').exists() run('systemd-run','--unit=pane23-shade-status-restore','--on-active=90s','--collect','/bin/sh','-c','rm -f '+str(DROP)+'; systemctl daemon-reload; systemctl restart shell-ui') try: DROP.parent.mkdir(exist_ok=True) DROP.write_text('[Service]\nExecStart=\nExecStart='+SELECTED+' --serve\nEnvironment=K230_TRACE_PATH='+str(TRACE)+'\nEnvironment=K230_TRACE_SECONDS=20\nEnvironment=K230_TRACE_ID=23000000000000000000000000000001\n') drop_written=True run('systemctl','daemon-reload'); run('systemctl','restart','shell-ui') time.sleep(3) during=identity(); guard(during) assert during['sway_pid']==before['sway_pid'] and during['rust_executable']==before['rust_executable'] assert during['settings_wrapper']==SETTINGS save('during.json',during) manifest.update(status='CAPTURING',capture_start=now()); save('manifest.json',manifest) samples=[]; stop=threading.Event() def sample(): while not stop.is_set(): row=dict(monotonic_ns=time.monotonic_ns(), processes={}) for tag,pid in [('sway',during['sway_pid']),('rust',during['rust_pid']),('observer',os.getpid())]: fields=Path(f'/proc/{pid}/stat').read_text().rpartition(')')[2].split() sched=[int(v) for v in Path(f'/proc/{pid}/schedstat').read_text().split()] row['processes'][tag]=dict(pid=pid,state=fields[0],cpu_ticks=int(fields[11])+int(fields[12]),schedstat=sched) row['cpu0_ticks']=[int(v) for v in Path('/proc/stat').read_text().splitlines()[1].split()[1:]] row['settings_status_children']={} children=set() for file in Path(f"/proc/{during['rust_pid']}/task").glob('*/children'): try: children.update(file.read_text().split()) except (FileNotFoundError,ProcessLookupError): pass for pid in children: try: args=Path(f'/proc/{pid}/cmdline').read_bytes().split(b'\0') if len(args)!=4 or args[2]!=b'status' or args[3]!=b'': continue path=Path(os.fsdecode(args[1])) if str(path)!='/nix/store/qc4fg0nvm8i3lpclnyji2ms68axr0vf3-device_settings.py': continue f=Path(f'/proc/{pid}/stat').read_text().rpartition(')')[2].split() row['settings_status_children'][pid]=dict(command='k230-settings status',script_path=str(path),cpu_ticks=int(f[11])+int(f[12]),start_ticks=int(f[19]),nice=int(f[16])) except (FileNotFoundError,ProcessLookupError): pass samples.append(row); stop.wait(.1) thread=threading.Thread(target=sample); thread.start() try: sent=json.loads(run(PYTHON,__file__,'--send')); save('sent.json',sent) finally: stop.set(); thread.join(timeout=2) assert not thread.is_alive() save('resources.json',dict(clock_ticks_per_second=os.sysconf('SC_CLK_TCK'),samples=samples,observer='Two /proc process stat/schedstat and CPU0 tick samples at10Hz; observation overhead remains present.')) deadline=time.monotonic()+25 while time.monotonic()