fix(gateway): constrain verified Qwen replies to emotion schema

This commit is contained in:
zenord
2026-10-12 12:18:18 +08:00
parent b521d368a5
commit 18ec4c2104
18 changed files with 351 additions and 60 deletions
+8 -8
View File
@@ -13,7 +13,7 @@ def health():
with opener.open('https://192.168.31.61:5011/health',timeout=3) as r:return json.load(r)
def atomic(path,content,mode):
path.parent.mkdir(parents=True,exist_ok=True)
tmp=path.with_name(path.name+'.v051.tmp');tmp.write_bytes(content);tmp.chmod(mode);tmp.replace(path)
tmp=path.with_name(path.name+'.gateway.tmp');tmp.write_bytes(content);tmp.chmod(mode);tmp.replace(path)
def live_hashes():return {name:digest(root/name) for name in deploy_files}
original=live_hashes()
if original!=expected:
@@ -30,7 +30,7 @@ private_hashes={str(p):digest(p) for p in private_files}
def relation_unchanged():
return subprocess.check_output(['systemctl','--user','cat',unit])==unit_text and all(digest(Path(p))==h for p,h in private_hashes.items())
if apply and health().get('busy'): raise RuntimeError('gateway_busy_no_restart')
with tempfile.TemporaryDirectory(prefix='voice-v051-stage-') as folder:
with tempfile.TemporaryDirectory(prefix='voice-gateway-stage-') as folder:
stage=Path(folder)
for name,content in bundle.items():
path=stage/name;path.parent.mkdir(parents=True,exist_ok=True);path.write_bytes(base64.b64decode(content))
@@ -42,9 +42,9 @@ with tempfile.TemporaryDirectory(prefix='voice-v051-stage-') as folder:
if live_hashes()!=original:raise RuntimeError('source_changed_during_tests')
if not relation_unchanged():raise RuntimeError('environment_or_unit_changed_during_tests')
if health().get('busy'):raise RuntimeError('gateway_busy_after_tests_no_restart')
backup=root/'.runtime/backups'/time.strftime('voice-v051-%Y%m%d-%H%M%S');backup.mkdir(parents=True,mode=0o700)
backup=root/'.runtime/backups'/time.strftime('voice-gateway-%Y%m%d-%H%M%S');backup.mkdir(parents=True,mode=0o700)
# Save all actual runtime Python sources/tests, modes, plus unit/env privately. No logs/history/audio copied.
for path in list(root.glob('*.py'))+list((root/'tests').glob('*.py')):
for path in list(root.glob('*.py'))+list((root/'tests').glob('*.py'))+list((root/'personas').glob('*.json')):
dst=backup/path.relative_to(root);dst.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,dst)
for i,path in enumerate(private_files):
dst=backup/'private'/str(i);dst.parent.mkdir(parents=True,exist_ok=True,mode=0o700);shutil.copy2(path,dst)
@@ -86,12 +86,12 @@ def main():
source=root/'gateway';manifest=json.loads((source/'SOURCE_MANIFEST.json').read_text())
baseline=manifest.get('deployment_baseline',manifest['provider_baseline'])['files']
files=sorted(set(baseline)|{p.relative_to(source).as_posix() for p in source.glob('*.py')}|{p.relative_to(source).as_posix() for p in (source/'tests').glob('*.py')})
assert all(n.endswith('.py') and not Path(n).is_absolute() and '..' not in Path(n).parts for n in files)
public_personas={'personas/lvbu.lorebook.json','personas/yangmi.lorebook.json'}
assert all((n.endswith('.py') or n in public_personas) and not Path(n).is_absolute() and '..' not in Path(n).parts for n in files)
expected={name:baseline.get(name) for name in files}
record=root/'logs/voice-investigation/gateway-emotion-deploy.json'
if record.exists():
previous=json.loads(record.read_text())
if previous.get('applied'):expected=previous['hashes'];assert set(expected)==set(files)
# SOURCE_MANIFEST is the reviewed expected live baseline. Old ignored records
# must not silently replace it when the deployment whitelist changes.
bundle={}
for path in source.rglob('*'):
name=path.relative_to(source).as_posix()