Files
Mikei386 c0bc5d3a1b Integrate Basalt telemetry and shared GPU speech runtimes
Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
2026-11-03 21:16:41 +01:00

69 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""Athena host only: exact telemetry overlay, regular GUI drain, no profile edits."""
import argparse,hashlib,importlib.util,json,shutil,subprocess,time
from pathlib import Path
ROOT=Path('/opt/athena-deck-dev/dashboard-telemetry-activation')
BASE=Path('/opt/athena-deck-dev/runtime');STATE=BASE/'state';SOURCE=Path('/opt/athena-deck-dev/source')
IMAGE='athena-deck-standalone:basalt-telemetry'
FILES=('basalt_worker.py','basalt_serve.py','basalt_telemetry.py','dashboard_data.py','dashboard-ui.js','deploy/install.py')
SETTINGS=('profiles.json','endpoint.json','audio-policy.json','cpu-partition.json','reasoning-budget.json')
def info():return json.loads(subprocess.check_output(['docker','inspect','athena-deck-dev'],text=True))[0]
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() if p.is_file() else None
def save(data):
p=ROOT/'activation.json';p.write_text(json.dumps(data,indent=2));p.chmod(0o600);assert json.loads(p.read_text())==data
return data
def installer():
s=importlib.util.spec_from_file_location('deck_install',SOURCE/'deploy/install.py');assert s and s.loader
m=importlib.util.module_from_spec(s);s.loader.exec_module(m);return m
def healthy():
end=time.monotonic()+90
while info()['State'].get('Health',{}).get('Status')=='starting' and time.monotonic()<end:time.sleep(1)
assert info()['State']['Health']['Status']=='healthy'
def prepare():
assert not (ROOT/'activation.json').exists(),'Preparation already exists; inspect rather than overwrite'
d=info();tag=d['Config']['Image'];assert subprocess.check_output(['docker','image','inspect','--format','{{.Id}}',tag],text=True).strip()==d['Image']
app=ROOT/'image/app';(app/'deploy').mkdir(parents=True,exist_ok=True)
original=(SOURCE/'deploy/install.py').read_text();anchor="FILES += ['cpu_partition.py']";assert anchor in original
(app/'deploy/install.py').write_text(original.replace(anchor,anchor+"\nFILES += ['basalt_serve.py','basalt_telemetry.py']",1))
before={n:sha(SOURCE/n) for n in FILES};after={n:sha(app/n) for n in FILES};assert all(after.values())
for n in FILES:
(app/n).chmod(0o644)
if before[n] is not None:
p=ROOT/'before'/n;p.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(SOURCE/n,p)
(ROOT/'image/Dockerfile').write_text('FROM '+tag+'\nUSER root\nCOPY app/ /app/\nUSER 65534:65534\n')
(ROOT/'image/.dockerignore').write_text('*\n!Dockerfile\n!app/\n!app/**\n')
with (ROOT/'image-build.log').open('w') as out:subprocess.run(['docker','build','--network','none','--pull=false','-t',IMAGE,ROOT/'image'],stdout=out,stderr=subprocess.STDOUT,check=True,timeout=180)
probe="""from pathlib import Path
import tempfile
from server import Server
from basalt_telemetry import Counters
with tempfile.TemporaryDirectory() as tmp:
s=Server(0,state_dir=Path(tmp));s.endpoint.close();s.video.close();s.dashboard.close();s.server_close()
print('Full isolated Server constructor passed; no production state or models')
"""
subprocess.run(['docker','run','--rm','--network','none','--read-only','--user','65534:65534','--memory','512m','--pids-limit','256','--cap-drop','ALL','-e','NVIDIA_VISIBLE_DEVICES=void','-e','DECK_REQUIRE_SETUP=0','-e','DECK_NETWORK_MODE=disabled','-e','TMPDIR=/test-tmp','--mount','type=bind,src='+str(STATE/'basalt-runtime/tmp')+',dst=/test-tmp','--entrypoint','python3',IMAGE,'-B','-c',probe],check=True,timeout=45)
assert info()['State']['StartedAt']==d['State']['StartedAt']
save(dict(phase='prepared',image_before=tag,image_id_before=d['Image'],started_before=d['State']['StartedAt'],source_before=before,source_after=after,config=json.loads((BASE/'installation.json').read_text()),settings={n:(STATE/n).read_text() for n in SETTINGS},prepared_at=time.time()))
print('Image and full constructor verified; production unchanged')
def apply():
a=json.loads((ROOT/'activation.json').read_text());assert a['phase']=='prepared'
d=json.loads((ROOT/'drained.json').read_text());assert time.time()-d['checked_at']<60 and d['state']=='stopped'
assert type(d['active_requests']) is int and d['active_requests']==0
assert all(type(d['scheduler'][k]) is int and d['scheduler'][k]==0 for k in ('active_requests','waiting_requests','tts_waiting_requests')) and d['scheduler']['switching'] is False
assert info()['Image']==a['image_id_before'] and all(sha(SOURCE/n)==a['source_before'][n] for n in FILES)
assert all((STATE/n).read_text()==a['settings'][n] for n in SETTINGS if n!='endpoint.json')
subprocess.run(['docker','stop','--timeout','45','athena-deck-dev'],check=True)
assert not subprocess.check_output(['nvidia-smi','--query-compute-apps=pid','--format=csv,noheader,nounits'],text=True).strip(),'Unexpected GPU work; no process will be killed'
try:
for n in FILES:shutil.copy2(ROOT/'image/app'/n,SOURCE/n)
(STATE/'endpoint.json').write_text(a['settings']['endpoint.json'])
subprocess.run(['docker','rm','athena-deck-dev'],check=True)
c=dict(a['config'],image=IMAGE,previous_image=a['image_before']);i=installer();i.launch(c);i.ready(c);healthy();i.write_manifest(BASE,c)
assert all(sha(SOURCE/n)==a['source_after'][n] for n in FILES) and all((STATE/n).read_text()==a['settings'][n] for n in SETTINGS)
save(dict(a,phase='activated; live acceptance pending',activated_at=time.time()));print('Activated and healthy; profiles and all protected settings unchanged')
except Exception:
save(dict(a,phase='activation failed; inspect before rollback'));raise
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('operation',choices=('prepare','apply'));p.add_argument('--go',action='store_true');a=p.parse_args();assert a.go,'Explicit Michael Go required'
prepare() if a.operation=='prepare' else apply()