omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / deployment / fast / qualify.py
| 1 | import os |
| 2 | """External exact-output regression and service isolation checks.""" |
| 3 | from experiment import R,SOCK,start,stop,request,expected,cases |
| 4 | from pathlib import Path |
| 5 | import concurrent.futures,hashlib,json,socket,struct,subprocess,time,sys |
| 6 | P=(Path(os.path.expanduser('~')) / '/handoffs/tool-omega-20261104/round40'.lstrip('/')) |
| 7 | D=(Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/round40'.lstrip('/')) |
| 8 | allrows=[];pins={} |
| 9 | def addfile(name,mode): |
| 10 | path=P/name;pins[str(path)]=hashlib.sha256(path.read_bytes()).hexdigest() |
| 11 | for index,row in enumerate(json.loads(path.read_text())): |
| 12 | assert row['pass'],(name,index) |
| 13 | if mode=='jobs': |
| 14 | for stage,t in enumerate(row['turns']):allrows.append(dict(source=name,index=index,stage=stage,prompt=t['prompt'],expected=t['raw'])) |
| 15 | else:allrows.append(dict(source=name,index=index,prompt=row['prompt'],expected=row['raw_output'])) |
| 16 | for name in ['final-selected.json','step600-retention-jobs.json','step600-target-jobs.json']: |
| 17 | addfile(name,'jobs') |
| 18 | for name in ['step600-regression.json','step600-copy.json','step600-correction-probes.json']: |
| 19 | addfile(name,'rows') |
| 20 | unique={} |
| 21 | for row in allrows: |
| 22 | key=row['prompt'];old=unique.get(key) |
| 23 | if old:assert old['expected']==row['expected'],row |
| 24 | else:unique[key]=row |
| 25 | rows=list(unique.values()) |
| 26 | (R/'regression-inputs.json').write_text(json.dumps(dict(raw_count=len(allrows),unique_count=len(rows),pins=pins,rows=rows),indent=2)+'\n') |
| 27 | def check_protocol(p): |
| 28 | receipts=[] |
| 29 | def healthy(label): |
| 30 | q=request(cases[0]['prompt']);assert q['stdout']==expected['read_request'];assert p.poll() is None |
| 31 | receipts.append(dict(label=label,healthy_after=True)) |
| 32 | for label,data,code in [('zero-length',b'\0\0',2),('oversize',struct.pack('<H',4001),2),('embedded-zero',struct.pack('<H',3)+b'a\0b',2),('token-overflow',struct.pack('<H',1200)+b'! '*600,3)]: |
| 33 | s=socket.socket(socket.AF_UNIX);s.settimeout(5);s.connect(SOCK);s.sendall(data) |
| 34 | reply=b'' |
| 35 | while len(reply)<3:reply+=s.recv(3-len(reply)) |
| 36 | assert reply==b'\xff\xff'+bytes([code]),(label,reply) |
| 37 | s.close();healthy(label) |
| 38 | for label,data in [('partial-header',b'\x20'),('partial-body',struct.pack('<H',20)+b'x')]: |
| 39 | s=socket.socket(socket.AF_UNIX);s.connect(SOCK);s.sendall(data);s.close();healthy(label) |
| 40 | s=socket.socket(socket.AF_UNIX);s.connect(SOCK);s.sendall(struct.pack('<H',len(cases[3]['prompt']))+cases[3]['prompt'].encode());s.recv(3);s.close();healthy('disconnect-during-generation') |
| 41 | s=socket.socket(socket.AF_UNIX);s.settimeout(5);s.connect(SOCK);s.sendall(b'\x10');begin=time.monotonic();reply=s.recv(3);elapsed=time.monotonic()-begin;s.close() |
| 42 | assert reply.startswith(b'\xff\xff') and 1.5<elapsed<4,(reply,elapsed) |
| 43 | healthy('slow-header-timeout');receipts[-1]['seconds']=elapsed |
| 44 | q=subprocess.run([str(R/'server-rows')],capture_output=True,timeout=5) |
| 45 | assert q.returncode==75;healthy('duplicate-server-refused') |
| 46 | with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool: |
| 47 | results=list(pool.map(lambda c:request(c['prompt']),cases)) |
| 48 | assert all(v['stdout']==expected[c['name']] for v,c in zip(results,cases));healthy('four-queued-requests') |
| 49 | for label,data,rc in [('empty',b'',2),('nul',b'hello\0',2),('overbytes',b'x'*4001,2),('overtokens',b'! '*600,3)]: |
| 50 | q=subprocess.run([str(R/'client')],input=data,capture_output=True,timeout=10) |
| 51 | assert q.returncode==rc,(label,q.returncode);healthy('client-'+label) |
| 52 | (R/'protocol-checks.json').write_text(json.dumps(receipts,indent=2)+'\n') |
| 53 | |
| 54 | # Byte-rebuilding audit across every state of the independent final cases. |
| 55 | p,err,warm=start('server-rows-check') |
| 56 | checked=0 |
| 57 | try: |
| 58 | for row in rows: |
| 59 | if row['source']!='final-selected.json':continue |
| 60 | v=request(row['prompt']);assert v['stdout']==row['expected'],('checked',row['index'],row.get('stage')) |
| 61 | checked+=1 |
| 62 | finally:stop(p,err) |
| 63 | (R/'cache-byte-audit.json').write_text(json.dumps(dict(passed=True,request_states=checked,method='Every cache hit rebuilt and every launch byte compared before unchanged submission'),indent=2)+'\n') |
| 64 | print('Checked launch bytes and final output states:',checked,flush=True) |
| 65 | |
| 66 | p,err,warm=start('server-rows') |
| 67 | passed=[] |
| 68 | try: |
| 69 | check_protocol(p) |
| 70 | for i,row in enumerate(rows): |
| 71 | v=request(row['prompt']) |
| 72 | assert v['stdout']==row['expected'],(i,row['source'],row['index'],row.get('stage'),v['stdout'],row['expected']) |
| 73 | passed.append(dict(source=row['source'],index=row['index'],stage=row.get('stage'),output_sha256=hashlib.sha256(v['stdout'].encode()).hexdigest(),total_ns=v['total_ns'])) |
| 74 | if i%50==0: |
| 75 | (R/'regression-progress.json').write_text(json.dumps(dict(passed=len(passed),total=len(rows),last_source=row['source']))+'\n') |
| 76 | print('Exact response parity',len(passed),'/',len(rows),flush=True) |
| 77 | # Existing native command is the independent oracle for context/tile/rolling boundaries. |
| 78 | boundary=[] |
| 79 | for n in [31,32,33,63,64,65,127,128,129,223,224,225,254,255]: |
| 80 | prompt='!'*n |
| 81 | q=subprocess.run([str(D/'omega-tool-model')],input=prompt.encode(),capture_output=True,timeout=30) |
| 82 | assert q.returncode==0,(n,q.returncode) |
| 83 | a=request(prompt);assert a['stdout']==q.stdout.decode(),('boundary',n) |
| 84 | boundary.append(dict(prompt_bytes=n,output_sha256=hashlib.sha256(q.stdout).hexdigest(),output_token_frames=a['token_frames'])) |
| 85 | # Interleave a known repair to detect cross-request context state. |
| 86 | assert request(cases[1]['prompt'])['stdout']==expected['repair_request'] |
| 87 | (R/'boundary-checks.json').write_text(json.dumps(boundary,indent=2)+'\n') |
| 88 | finally:stop(p,err) |
| 89 | for path,want in pins.items():assert hashlib.sha256(Path(path).read_bytes()).hexdigest()==want |
| 90 | (R/'regression-results.json').write_text(json.dumps(dict(passed=True,raw_states=len(allrows),unique_states=len(rows),byte_checked_final_states=checked,results=passed),indent=2)+'\n') |
| 91 | (R/'regression-progress.json').write_text(json.dumps(dict(passed=len(passed),total=len(rows),status='complete'))+'\n') |
| 92 | print('Full parity and service boundary checks passed.',len(rows),'unique states.',flush=True) |