amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

301 lines
16 KiB
Python

import hashlib
import json
import os
import signal
import time
from pathlib import Path
import random
import re
import subprocess
import sys
import tempfile
HARNESS=r'''#include "pool.hpp"
#include "protocol.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace fold;
static void total(const Total& t) {
std::cout<<t.sum<<' '<<t.count<<' '<<t.done<<' '<<t.closed<<' '<<t.queued<<' '<<t.owner;
}
static void worker(const WorkerView& w) {
std::cout<<w.sum<<' '<<w.count<<' '<<w.done<<' '<<w.carry.size();
for(auto b:w.carry)std::cout<<' '<<b;
}
static void snapshot(const Snapshot& s) {
std::cout<<s.workers<<' '<<s.capacity<<' '<<s.accepted<<" | ";total(s.total);
std::cout<<" | "<<s.queue.size();for(auto b:s.queue)std::cout<<' '<<b;
for(const auto& w:s.local){std::cout<<" | ";worker(w);}
}
int main(int argc,char** argv) {
if(argc!=2)return 0;
if(std::string(argv[1])=="reuse") {
std::size_t size=0;
while(std::cin>>size){std::cin.get();std::string text(size,'\0');std::cin.read(&text[0],size);
std::istringstream input(text);std::ostringstream output,error;
int code=run_session(input,output,error);
std::cout<<"BEGIN "<<code<<' '<<output.str().size()<<'\n'<<output.str();
std::cerr<<error.str();std::cout<<"END\n";
}
return 0;
}
Pool objects[2];
int id=0;std::string verb;
while(std::cin>>id>>verb){
Pool& pool=objects[id];std::int64_t a=0,b=0;
if(verb=="RESET"||verb=="WRITE"||verb=="TAKE")std::cin>>a>>b;
else if(verb=="BYTE"||verb=="FINISH"||verb=="WORKER")std::cin>>a;
if(verb=="RESET")std::cout<<"R "<<pool.configure(a,b);
else if(verb=="WRITE")std::cout<<"R "<<pool.write(a,b);
else if(verb=="BYTE")std::cout<<"R "<<pool.byte(a);
else if(verb=="CLOSE")std::cout<<"R "<<pool.close();
else if(verb=="FINISH")std::cout<<"R "<<pool.finish(a);
else if(verb=="TAKE"){auto s=pool.take(a,b);std::cout<<"T "<<s.code<<' '<<s.bytes<<' '<<s.records;}
else if(verb=="TOTAL"){std::cout<<"G ";total(pool.totals());}
else if(verb=="WORKER"){
WorkerView w;w.sum=99;w.count=-7;w.done=1;w.carry={201,202};
int code=pool.worker(a,w);std::cout<<"W "<<code<<' ';worker(w);
}
else if(verb=="SNAP"){std::cout<<"S ";snapshot(pool.snapshot());}
std::cout<<'\n'<<"S ";snapshot(pool.snapshot());std::cout<<'\n';
}
return 0;
}
'''
class Model:
def __init__(self):
self.reset(1,256)
def reset(self,n,c):
self.n=n;self.c=c;self.accepted=0;self.q=[];self.closed=0
self.local=[dict(values=[],carry=[],done=0) for _ in range(n)]
def owner(self):
return next((i for i,w in enumerate(self.local) if w['carry']),-1)
def worker(self,i):
w=self.local[i]
return [sum(w['values']),len(w['values']),w['done'],len(w['carry']),*w['carry']]
def totals(self):
committed=[w for w in self.local if w['done']]
return [sum(sum(w['values']) for w in committed),sum(len(w['values']) for w in committed),len(committed),self.closed,len(self.q),self.owner()]
def snapshot(self):
parts=[f'{self.n} {self.c} {self.accepted}',nums(self.totals()),nums([len(self.q),*self.q])]
return ' | '.join(parts+[nums(self.worker(i)) for i in range(self.n)])
def action(self,verb,args,api=False):
if verb=='TOTAL':return 'G '+nums(self.totals())
if verb=='SNAP':return 'S '+self.snapshot()
if verb=='WORKER':
i=args[0]
if i<0 or i>=self.n:return 'W 1'+(' 99 -7 1 2 201 202' if api else '')
return 'W 0 '+nums(self.worker(i))
if verb=='RESET':
n,c=args
if not 1<=n<=8 or not 4<=c<=256:return 'R 1'
self.reset(n,c);return 'R 0'
if verb in ('WRITE','BYTE'):
if verb=='WRITE':
value,count=args
if not -2**31<=value<2**31 or not 0<=count<=64:return 'R 1'
data=list((value%2**32).to_bytes(4,'little'))*count
else:
value=args[0]
if not 0<=value<=255:return 'R 1'
data=[value]
if self.closed:return 'R 2'
if len(data)+len(self.q)>self.c:return 'R 3'
if len(data)+self.accepted>262144:return 'R 6'
self.q.extend(data);self.accepted+=len(data);return 'R 0'
if verb=='CLOSE':self.closed=1;return 'R 0'
if verb=='FINISH':
i=args[0]
if not 0<=i<self.n:return 'R 1'
w=self.local[i]
if w['done']:return 'R 0'
if not self.closed or self.q:return 'R 2'
if w['carry']:return 'R 5'
w['done']=1;return 'R 0'
i,budget=args
if not 0<=i<self.n or not 0<=budget<=256:return 'T 1 0 0'
w=self.local[i]
if w['done']:return 'T 2 0 0'
if self.owner() not in (-1,i):return 'T 4 0 0'
count=min(budget,len(self.q));records=0
for x in self.q[:count]:
w['carry'].append(x)
if len(w['carry'])==4:
w['values'].append(int.from_bytes(bytes(w['carry']),'little',signed=True))
w['carry']=[];records+=1
del self.q[:count]
return f'T 0 {count} {records}'
def nums(values):return ' '.join(map(str,values))
def api_case():
commands=[]
def add(v,*a,id=0):commands.append((id,v,list(a)))
def observe(id=0):
add('TOTAL',id=id)
for w in range(8):add('WORKER',w,id=id)
add('SNAP',id=id)
# Both live objects use worker 0 with different state, then reset only one.
add('WRITE',23,2);add('TAKE',0,4);add('WRITE',-31,1,id=1);add('TAKE',0,4,id=1)
observe();observe(1);add('RESET',2,16);observe(1)
# Smoke exposes only carry handling; it never finishes the last worker.
add('WRITE',16909060,1);add('TAKE',0,1);add('WORKER',0);add('TAKE',1,0);add('TAKE',0,0)
add('TAKE',0,3);add('WORKER',0);add('CLOSE');add('FINISH',0);add('TOTAL');add('WORKER',0)
# Complete local contribution on final EOF, duplicate finish, zero records.
add('RESET',2,256);add('WRITE',-11,2);add('TAKE',0,4);add('WRITE',0,3);add('TAKE',1,256)
add('WORKER',0);add('WORKER',1);add('CLOSE');add('FINISH',0);add('TOTAL');add('FINISH',1)
add('TOTAL');add('WORKER',1);add('FINISH',1);add('FINISH',0);observe()
# Closed pipes retain their unread bytes and drain before workers finish.
add('RESET',2,16);add('WRITE',9,2);add('CLOSE');add('FINISH',0)
add('TAKE',0,4);add('WORKER',0);add('TAKE',1,256);add('WORKER',1)
add('TAKE',0,256);add('FINISH',1);add('FINISH',0);observe()
# All successful parameter endpoints with effects, not blocked by another error.
add('RESET',1,4);add('WRITE',-2147483648,1);add('TAKE',0,0);add('TAKE',0,256)
add('WORKER',0);add('WRITE',2147483647,1);add('TAKE',0,4);add('CLOSE');add('FINISH',0);observe()
add('RESET',8,256);add('WRITE',2147483647,64);add('TAKE',7,256);add('WORKER',7)
add('WRITE',0,64);add('TAKE',0,256);add('WORKER',0)
add('WRITE',-2147483648,0);add('WRITE',2147483647,0);add('BYTE',0);add('BYTE',255)
add('BYTE',0);add('BYTE',0);add('TAKE',7,4);add('WORKER',7);add('CLOSE')
for i in [0,1,2,3,4,5,6,7]:add('FINISH',i);add('WORKER',i);add('TOTAL')
# Endpoints and domain/native extremes for every numeric API parameter.
low=-2**63;high=2**63-1
for n in [low,-1,0,9,high]:add('RESET',n,16)
for c in [low,-1,3,257,high]:add('RESET',2,c)
for v in [low,-2147483649,2147483648,high]:add('WRITE',v,1)
for c in [low,-1,65,high]:add('WRITE',0,c)
for v in [low,-1,256,high]:add('BYTE',v)
for i in [low,-1,8,high]:
add('TAKE',i,4);add('FINISH',i);add('WORKER',i)
for b in [low,-1,257,high]:add('TAKE',0,b)
# Range checks and all zero count writes on nonzero closed state.
add('WRITE',0,0);add('BYTE',7);add('TAKE',0,0);add('CLOSE');observe()
# FULL/STATE/BUSY/TAIL paths and recovery, retaining nonzero complete state.
add('RESET',3,4);add('WRITE',7,1);add('BYTE',1);add('WRITE',8,1);add('FINISH',0)
add('TAKE',0,1);add('WORKER',0);add('TAKE',1,4);add('TAKE',1,0)
add('TAKE',0,3);add('WRITE',0,1);add('TAKE',1,4);add('WORKER',1)
add('BYTE',42);add('TAKE',2,1);add('WORKER',2);add('CLOSE');add('FINISH',2)
add('FINISH',1);add('FINISH',0);add('FINISH',1);add('TAKE',1,4);add('TAKE',2,0);observe()
# A carry may belong to any worker and blocks only take by another worker.
for owner in [0,3,7]:
add('RESET',8,256)
for b in [255,255,255,255,0,0,0,128]:add('BYTE',b)
for budget in [1,2,1,3,1]:add('TAKE',owner,budget);add('WORKER',owner)
add('CLOSE')
for i in reversed(range(8)):add('FINISH',i)
observe()
# Lifetime byte limit is reached by real input/consumption; FULL comes first.
add('RESET',1,256)
for turn in range(1024):
add('WRITE',-1,64)
if turn==1023:add('BYTE',0);add('WRITE',0,1);add('WRITE',0,0)
add('TAKE',0,256)
add('BYTE',0);add('WRITE',0,1);add('WRITE',0,0);add('CLOSE');add('BYTE',0);add('WRITE',0,1);add('WRITE',0,0);add('FINISH',0);observe()
rng=random.Random(94018)
for _ in range(260):
obj=rng.randrange(2);v=rng.choice(['RESET','WRITE','BYTE','TAKE','CLOSE','FINISH','TOTAL','WORKER','SNAP'])
values={'RESET':[rng.randint(1,8),rng.randint(4,256)],'WRITE':[rng.randint(-2**31,2**31-1),rng.randrange(6)],'BYTE':[rng.randrange(256)],'TAKE':[rng.randrange(8),rng.randrange(257)],'CLOSE':[],'FINISH':[rng.randrange(8)],'TOTAL':[],'WORKER':[rng.randrange(8)],'SNAP':[]}
add(v,*values[v],id=obj)
models=[Model(),Model()];source=[];expected=[]
for i,v,a in commands:
source.append(f'{i} {v}'+(' '+nums(a) if a else '')+'\n')
expected.extend([models[i].action(v,a,True),'S '+models[i].snapshot()])
return ''.join(source).encode(),('\n'.join(expected)+'\n').encode()
ARITY={'RESET':2,'WRITE':2,'BYTE':1,'TAKE':2,'CLOSE':0,'FINISH':1,'TOTAL':0,'WORKER':1,'SNAP':0}
def cli_expected(data):
m=Model();out=[]
lines=data.split(b'\n')
if lines[-1:]==[b'']:lines.pop()
for number,line in enumerate(lines,1):
if number>4096:out.append('R 6');continue
if len(line)>512 or any(x not in (9,32) and not 33<=x<=126 for x in line):out.append('R 7');continue
tokens=line.decode('ascii').split()
if not tokens or tokens[0] not in ARITY or len(tokens)!=ARITY.get(tokens[0],0)+1:out.append('R 7');continue
args=[];valid=True
for t in tokens[1:]:
if not re.fullmatch('-?[0-9]+',t):valid=False;break
value=int(t)
if not -2**63<=value<2**63:valid=False;break
args.append(value)
out.append(m.action(tokens[0],args) if valid else 'R 7')
return ('\n'.join(out)+ ('\n' if out else '')).encode()
def cli_cases():
lines=['RESET 2 256','WRITE 21 1','TAKE 0 4','BYTE 0','BYTE 0','BYTE 0','BYTE 0','TAKE 1 4','WORKER 1','CLOSE','FINISH 0','FINISH 1','TOTAL','SNAP']
for verb,n in ARITY.items():
if n:lines.extend([verb+' '+' '.join(['0']*(n-1)),'SNAP'])
else:lines.extend([verb+' 0','SNAP'])
lines.extend([verb+' '+' '.join(['0']*(n+1)),'SNAP'])
for at in range(n):
for bad in ['+1','-','1.0','1x','9223372036854775808','-9223372036854775809','-9223372036854775808','9223372036854775807']:
args=['0']*n;args[at]=bad;lines.extend([verb+' '+' '.join(args),'SNAP'])
lines+=['RESET 0002 0256','WRITE -0000 0002','TAKE -0 0008','WORKER 00','TOTAL','WRITE 0007 01','TAKE 01 04','WORKER 01','CLOSE','FINISH 00','FINISH 01','TOTAL','BYTE \x0b0','BYTE \x0c0','','\t ','unknown','TOTAL\r','BYTE \x00','BYTE \x7f','BYTE \xff','X'*513,' '*512,' '*507+'TOTAL',' '*508+'TOTAL','\tRESET\t8 256\t','WRITE -2147483648 1','TAKE 7 4','WORKER 7','WRITE 0 2','TAKE 0 8','WORKER 0','CLOSE','FINISH 7','FINISH 0','TOTAL']
ordinary='\n'.join(lines).encode('latin1')
maximum=('WRITE 13 1\nTAKE 0 4\nCLOSE\nFINISH 0\n'+'TOTAL\n'*4092+'RESET 8 4\nSNAP\n').encode()
return ordinary,maximum
def digest(data):return hashlib.sha256(data).hexdigest()[:16]
def execute(argv,cwd,data,timeout):
started=time.monotonic()
p=subprocess.Popen(argv,cwd=cwd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,start_new_session=True)
timed_out=False
try:
output,error=p.communicate(data,timeout=timeout)
except subprocess.TimeoutExpired:
timed_out=True
os.killpg(p.pid,signal.SIGKILL)
output,error=p.communicate()
return p,output,error,timed_out,round((time.monotonic()-started)*1000)
def difference(output,expected,input_data,api):
actual=output.splitlines();wanted=expected.splitlines()
index=next((i for i in range(max(len(actual),len(wanted))) if actual[i:i+1]!=wanted[i:i+1]),0)
def preview(lines):return repr(lines[index])[:96] if index<len(lines) else '<missing>'
detail=[index,preview(actual),preview(wanted)]
if api:
source=input_data.splitlines();at=index//2
detail.append(source[at].decode('ascii') if at<len(source) else '<extra>')
return detail
def main():
candidate=Path(sys.argv[1]);names=['pool.hpp','pool.cpp','protocol.hpp','protocol.cpp','main.cpp']
material={name:(candidate/name).read_bytes() for name in names}
api_input,api_output=api_case();ordinary,maximum=cli_cases()
sessions=[maximum,maximum,b'',b'TOTAL',b'WRITE 0 1\nTAKE 0 4\nCLOSE\nFINISH 0\nTOTAL\n',b'TOTAL\n']
reuse_input=b''.join(str(len(s)).encode()+b'\n'+s for s in sessions)
reuse_output=b''
for s in sessions:
result=cli_expected(s);reuse_output+=f'BEGIN 0 {len(result)}\n'.encode()+result+b'END\n'
smoke=b'RESET 2 16\nWRITE 16909060 1\nTAKE 0 1\nTAKE 0 3\nCLOSE\nFINISH 0\nTOTAL\n'
plans=[('api','observer',['api'],api_input,api_output),('cli','fold',[],ordinary,cli_expected(ordinary)),('max','fold',[],maximum,cli_expected(maximum)),('empty','fold',[],b'',b''),('smoke','fold',[],smoke,cli_expected(smoke)),('reuse','observer',['reuse'],reuse_input,reuse_output)]
scratch=Path(tempfile.mkdtemp(prefix='fold-',dir=Path.cwd()))
for name,data in material.items():(scratch/name).write_bytes(data)
(scratch/'observer.cpp').write_text(HARNESS)
# All trusted filesystem work, model generation and input preparation ends here.
meta={'cwd':str(scratch),'build':[],'scene':[],'checks':0,'failed':[],'raw_stdout_retained':False}
common=['g++','-std=c++17','-O2','-Wall','-Wextra','pool.cpp','protocol.cpp']
for executable,source in [('observer','observer.cpp'),('fold','main.cpp')]:
argv=common+[source,'-o',executable]
p,output,error,timed_out,elapsed=execute(argv,scratch,None,35)
meta['build'].append([argv,p.pid,p.returncode,len(output),len(error),digest(output),digest(error),timed_out,elapsed])
if p.returncode or timed_out:
meta['failed'].append(executable+':build');print(json.dumps(meta,separators=(',',':')),file=sys.stderr);print('FAIL build');return 1
for name,executable,args,input_data,expected in plans:
argv=['./'+executable,*args]
p,output,error,timed_out,elapsed=execute(argv,scratch,input_data,12)
failures=[]
if p.returncode!=0:failures.append('exit')
if output!=expected:failures.append('stdout')
if error:failures.append('stderr')
if timed_out:failures.append('timeout')
meta['checks']+=3
detail=difference(output,expected,input_data,name=='api') if output!=expected else []
meta['scene'].append([name,argv,p.pid,p.returncode,len(input_data),digest(input_data),len(output),digest(output),len(expected),digest(expected),len(error),digest(error),timed_out,elapsed,failures,detail])
meta['failed'].extend(name+':'+f for f in failures)
serialized=json.dumps(meta,separators=(',',':'))
if len(serialized)>=3900:raise RuntimeError('metadata too large')
print(serialized,file=sys.stderr)
if meta['failed']:print('FAIL '+','.join(meta['failed']));return 1
print('PASS');return 0
if __name__=='__main__':sys.exit(main())