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

254 lines
19 KiB
Python

OBSERVER = '#include "durable.hpp"\n#include <iostream>\n#include <sstream>\n#include <string>\nusing namespace durable;\nnamespace {\nstd::vector<Sample> initial(Number nonce)\n{\n return {{nonce, nonce, nonce, nonce, nonce, nonce}};\n}\nvoid samples(char label, int result, const std::vector<Sample> &values)\n{\n std::cout << label << \' \' << result << \' \' << values.size();\n for (const auto &s : values) {\n std::cout << \' \' << s.sequence << \' \' << s.writer << \' \' << s.generation\n << \' \' << s.topic << \' \' << s.payload << \' \' << s.replayed;\n }\n std::cout << \'\\n\';\n}\nbool execute(Domain &d, char command, std::istringstream &in)\n{\n int id=0, topic=0, durability=0, size=0;\n Number nonce=0, payload=0;\n if (command == \'W\' || command == \'O\') {\n if (!(in >> id >> topic >> durability >> size)) return false;\n const int result = command == \'W\' ? d.open_writer(id, topic, durability, size)\n : d.open_reader(id, topic, durability, size);\n std::cout << "R " << result << \'\\n\';\n } else if (command == \'X\' || command == \'C\' || command == \'Z\') {\n if (!(in >> id)) return false;\n const int result = command == \'X\' ? d.close_writer(id) :\n command == \'C\' ? d.close_reader(id) : d.clear(id);\n std::cout << "R " << result << \'\\n\';\n } else if (command == \'D\' || command == \'L\') {\n if (!(in >> id >> size)) return false;\n const int result = command == \'D\' ? d.set_depth(id, size) : d.set_capacity(id, size);\n std::cout << "R " << result << \'\\n\';\n } else if (command == \'P\') {\n if (!(in >> id >> payload >> nonce)) return false;\n const int result = d.publish(id, payload, nonce);\n std::cout << "P " << result << \' \' << nonce << \'\\n\';\n } else if (command == \'B\') {\n if (!(in >> id >> nonce >> size) || size < 0) return false;\n std::vector<Number> values;\n for (int i=0; i<size; ++i) {\n if (!(in >> payload)) return false;\n values.push_back(payload);\n }\n std::vector<Number> output{nonce, nonce};\n const int result = d.publish_many(id, values, output);\n std::cout << "B " << result << \' \' << output.size();\n for (Number value : output) std::cout << \' \' << value;\n std::cout << \' \' << values.size();\n for (Number value : values) std::cout << \' \' << value;\n std::cout << \'\\n\';\n } else if (command == \'H\' || command == \'K\' || command == \'T\') {\n if (!(in >> id)) return false;\n if (command == \'T\' && !(in >> size)) return false;\n if (!(in >> nonce)) return false;\n auto output = initial(nonce);\n const int result = command == \'H\' ? d.history(id, output) :\n command == \'K\' ? d.peek(id, output) : d.take(id, size, output);\n samples(command, result, output);\n } else if (command == \'I\') {\n if (!(in >> id >> nonce)) return false;\n WriterInfo info{nonce,nonce,nonce,nonce,nonce,nonce,nonce};\n const int result = d.writer_info(id, info);\n std::cout << "I " << result << \' \' << info.id << \' \' << info.generation << \' \'\n << info.topic << \' \' << info.durability << \' \' << info.depth << \' \'\n << info.published << \' \' << info.retained << \'\\n\';\n } else if (command == \'J\') {\n if (!(in >> id >> nonce)) return false;\n ReaderInfo info{nonce,nonce,nonce,nonce,nonce,nonce,nonce,nonce};\n const int result = d.reader_info(id, info);\n std::cout << "J " << result << \' \' << info.id << \' \' << info.topic << \' \'\n << info.durability << \' \' << info.capacity << \' \' << info.received << \' \'\n << info.taken << \' \' << info.lost << \' \' << info.queued << \'\\n\';\n } else if (command == \'A\' || command == \'E\') {\n std::vector<int> output{91,92};\n if (command == \'A\') d.writer_ids(output); else d.reader_ids(output);\n std::cout << command << \' \' << output.size();\n for (int value : output) std::cout << \' \' << value;\n std::cout << \'\\n\';\n } else if (command == \'Q\') {\n const auto info = d.totals();\n std::cout << "Q " << info.writers << \' \' << info.readers << \' \' << info.retained\n << \' \' << info.queued << \' \' << info.next_sequence << \'\\n\';\n } else if (command == \'N\') {\n d.reset();\n std::cout << "R 0\\n";\n } else {\n return false;\n }\n std::string remaining;\n return !(in >> remaining);\n}\n}\nint main()\n{\n Domain domains[2];\n int selected=0;\n std::string line;\n while (std::getline(std::cin,line)) {\n std::istringstream in(line);\n char command=0;\n if (!(in >> command)) continue;\n if (command == \'U\') {\n std::string remaining;\n if (!(in >> selected) || selected < 0 || selected > 1 || (in >> remaining)) return 2;\n std::cout << "U " << selected << \'\\n\';\n } else if (!execute(domains[selected], command, in)) {\n return 2;\n }\n }\n return std::cin.bad() ? 2 : 0;\n}\n'
CANDIDATES = ['durable.hpp', 'history.cpp', 'domain.cpp', 'reader.cpp', 'batch.cpp', 'inspect.cpp']
import json
from pathlib import Path
import random
import subprocess
import sys
import tempfile
class Model:
def __init__(self): self.reset()
def reset(self): self.w={}; self.r={}; self.g={}; self.next=1
@staticmethod
def within(x,a,b): return a <= x <= b
def trim(self,r):
n=max(0,len(r['q'])-r['cap']);r['lost']+=n;r['q']=r['q'][n:]
def deliver(self,r,s):
r['q'].append(list(s));r['received']+=1;self.trim(r)
def commit(self,i,p):
w=self.w[i];s=[self.next,i,w['g'],w['t'],p,0];self.next+=1;w['published']+=1
if w['d']: w['h']=(w['h']+[s])[-w['depth']:]
for r in self.r.values():
if r['t']==w['t']:self.deliver(r,s)
return s[0]
def call(self,c,a):
if c=='N':self.reset();return ['R',0]
if c=='Q':return ['Q',len(self.w),len(self.r),sum(len(w['h']) for w in self.w.values()),sum(len(r['q']) for r in self.r.values()),self.next]
if c in ('A','E'):
ids=sorted(self.w if c=='A' else self.r);return [c,len(ids)]+ids
i=a[0]
if c in ('W','O'):
_,t,d,limit=a;target=self.w if c=='W' else self.r
if not self.within(i,1,32) or not self.within(t,1,8) or d not in (0,1) or not self.within(limit,1,16 if c=='W' else 64):return ['R',-22]
if i in target:return ['R',-17]
if c=='W':
self.g[i]=self.g.get(i,0)+1;self.w[i]=dict(g=self.g[i],t=t,d=d,depth=limit,published=0,h=[])
else:
r=dict(t=t,d=d,cap=limit,received=0,taken=0,lost=0,q=[]);self.r[i]=r
if d:
retained=sorted((s for w in self.w.values() if w['t']==t and w['d'] for s in w['h']),key=lambda s:s[0])
for s in retained:self.deliver(r,s[:5]+[1])
return ['R',0]
iswriter=c in ('X','D','P','B','H','I');target=self.w if iswriter else self.r
exists=i in target;obj=target.get(i)
if c in ('X','C'):
if not exists:return ['R',-2]
del target[i];return ['R',0]
if c in ('D','L'):
if not exists:return ['R',-2]
limit=a[1]
if not self.within(limit,1,16 if c=='D' else 64):return ['R',-22]
if c=='D':obj['depth']=limit;obj['h']=obj['h'][-limit:]
else:obj['cap']=limit;self.trim(obj)
return ['R',0]
if c=='P':
p,n=a[1:]
if not exists:return ['P',-2,n]
if not self.within(p,-1000000,1000000):return ['P',-22,n]
return ['P',0,self.commit(i,p)]
if c=='B':
n,sz=a[1:3];values=a[3:];result=[n,n]
status=-2 if not exists else -22 if len(values)>16 or any(not self.within(p,-1000000,1000000) for p in values) else 0
if status==0:result=[self.commit(i,p) for p in values]
return ['B',status,len(result)]+result+[len(values)]+values
if c in ('H','K','T'):
n=a[-1];result=[[n]*6];status=-2 if not exists else -22 if c=='T' and not self.within(a[1],0,64) else 0
if status==0:
if c=='H':result=obj['h']
elif c=='K':result=obj['q']
else:
amount=min(a[1],len(obj['q']));result=obj['q'][:amount];obj['q']=obj['q'][amount:];obj['taken']+=amount
return [c,status,len(result)]+[v for s in result for v in s]
if c=='Z':
if not exists:return ['R',-2]
obj['lost']+=len(obj['q']);obj['q']=[];return ['R',0]
if c=='I':
n=a[1];fields=[i,obj['g'],obj['t'],obj['d'],obj['depth'],obj['published'],len(obj['h'])] if exists else [n]*7
return ['I',0 if exists else -2]+fields
if c=='J':
n=a[1];fields=[i,obj['t'],obj['d'],obj['cap'],obj['received'],obj['taken'],obj['lost'],len(obj['q'])] if exists else [n]*8
return ['J',0 if exists else -2]+fields
raise RuntimeError(c)
models=[Model(),Model()];selected=0;commands=[];expected=[];labels=[]
def add(label,c,*args):
global selected
commands.append(' '.join(map(str,[c]+list(args))))
labels.append(label)
if c=='U':selected=args[0];row=['U',selected]
else:row=models[selected].call(c,list(args))
expected.append(' '.join(map(str,row)))
def observe(label):
add(label,'Q');add(label,'A');add(label,'E')
for i in (1,2,3,32):
add(label,'I',i,773);add(label,'H',i,773);add(label,'J',i,773);add(label,'K',i,773)
def batch(label,i,values,n=984): add(label,'B',i,n,len(values),*values)
# Direct empty-state observations and missing-identifier output preservation.
observe('R01,R02,R03,R11,R12 empty-state')
for i in (-1,0,1,32,33):
for c,args in [('X',[]),('C',[]),('Z',[]),('D',[0]),('L',[0]),('P',[1000001,701]),('H',[701]),('K',[701]),('T',[-1,701]),('I',[701]),('J',[701])]:add('R02,R03 missing-first',c,i,*args)
batch('R03,R10 missing-before-invalid',i,[0,1000001])
# All creation domain endpoints and invalid neighbors.
for c,maximum in [('W',16),('O',64)]:
for i in (-1,0,33):add('R02,R03 invalid-id',c,i,1,1,1)
for t in (0,9):add('R02,R03 invalid-topic',c,1,t,1,1)
for d in (-1,2):add('R02,R03 invalid-durability',c,1,1,d,1)
for limit in (0,maximum+1):add('R02,R03 invalid-limit',c,1,1,1,limit)
for args in [(1,1,0,1),(32,8,1,maximum)]:add('R02,R04,R07 valid-endpoints',c,*args)
add('R03 invalid-before-occupied',c,1,9,2,0)
add('R03 duplicate',c,1,1,0,1)
observe('R02,R03,R11 endpoint-state');add('R12','N')
# Writer history keeps most recent values, depth resize and all direct queries.
for depth in (1,2,3,16):
add('R06','N');add('R06','W',1,8,1,depth)
for p in range(depth+4):add('R05,R06','P',1,p*73-200,887)
add('R06','H',1,991);add('R11','I',1,991)
add('R07','O',1,8,1,64);add('R07','K',1,991)
for d in (0,17,1,16,3):
add('R03,R06','D',1,d);add('R06','H',1,991);add('R11','I',1,991)
add('R06','P',1,1000000,991);add('R06','P',1,-1000000,991)
add('R06,R07 snapshot-isolation','K',1,991)
observe('R06,R11 inspect-after-depth')
# All durability combinations, global ordering, off-topic exclusion.
for wd in (0,1):
for rd in (0,1):
add('R05,R07','N');add('R07','W',1,1,wd,3);add('R07','W',2,1,1-wd,3);add('R07','W',32,8,1,16)
for i,p in [(2,91),(1,-19),(32,671),(1,471),(2,-399)]:add('R05,R07','P',i,p,734)
add('R07','O',1,1,rd,64);add('R07','O',2,8,rd,1);add('R07','O',32,1,1-rd,1)
add('R07','K',1,734);add('R07','K',2,734);add('R07','K',32,734)
for i in (1,2,32):add('R07 live','P',i,612+i,734)
observe('R07,R08 live-and-replay')
# Assigned non-smoke writer lifecycle boundary and owned copies across reuse.
add('R04','N');add('R04','W',1,1,1,16);batch('R04',1,[18,27,-49])
add('R04','O',1,1,1,64);add('R04','K',1,432);add('R04 duplicate-generation','W',1,1,1,16);add('R04','X',1);add('R04','X',1)
add('R04 retained-copy','K',1,432);add('R04','H',1,432);add('R04','I',1,432);add('R04','Q')
add('R04 no-closed-replay','O',2,1,1,64);add('R04 no-closed-replay','K',2,432)
add('R04 new-generation','W',1,8,1,16);add('R04 new-generation','P',1,38,432);add('R04','I',1,432)
add('R04 same-id-different-topic','K',1,432);add('R04','K',2,432);add('R04','O',32,8,1,64)
add('R04','K',32,432);add('R04','X',1);add('R04 copies','K',32,432);add('R04','Q')
add('R04','W',1,1,0,1);add('R04','I',1,432);add('R04','P',1,-57,432);add('R04','K',1,432)
observe('R04 lifecycle');add('R12','N');add('R12','N');add('R04,R12 reset-generation','W',1,1,1,1);add('R04,R12','I',1,23)
# Batch atomicity, empty and maximum size, input/output preservation.
add('R10','N');add('R10','W',1,1,1,16);add('R10','O',1,1,1,64)
for values in [[],[-1000000],[1000000]*16,list(range(17)),[1000001,2],[2,-1000001],[7,1000001,8],list(range(16))]:
batch('R03,R10 batch',1,values);observe('R03,R10 batch-state')
for p in (-1000001,1000001,-1000000,1000000):add('R02,R03,R05 payload','P',1,p,901)
observe('R03 after-invalid-publish')
# Queue limits, both endpoints for take/capacity, repeated query, clear and reopen.
for cap in (1,64):
add('R08,R09','N');add('R08','W',1,1,1,16);add('R08','O',1,1,0,cap)
for k in range(5):batch('R08 queue-overflow',1,list(range(k*16,k*16+16)))
add('R08','J',1,763);add('R09','K',1,763);add('R09','K',1,763)
for n in (-1,65,0,1,64):
add('R03,R09 take','T',1,n,763);add('R09','J',1,763);add('R09','K',1,763)
batch('R08 refill',1,list(range(16)))
for n in (0,65,1,64):
add('R03,R08 capacity','L',1,n);add('R08','J',1,763);add('R08','K',1,763)
add('R09','Z',1);add('R09','Z',1);add('R09','J',1,763);add('R09','K',1,763)
add('R09','C',1);add('R09','C',1);add('R09','O',1,1,1,cap);add('R09','J',1,763);add('R09','K',1,763)
# Full ID tables and deterministic sorting; independent domains/reset.
add('R11','N')
for i in list(range(32,0,-1)):
add('R02,R11 full-id-range','W',i,1+(i%8),i%2,1+(i%16));add('R02,R11 full-id-range','O',i,1+(i%8),i%2,1+(i%64))
add('R11 sorted','A');add('R11 sorted','E');add('R11','Q')
add('R01','U',1);observe('R01 independent-new-domain');add('R01','W',32,8,1,16);add('R01','P',32,592,100);add('R01','O',32,8,1,64)
add('R01','U',0);observe('R01 original-domain');add('R12','N');add('R01','U',1);observe('R01 other-domain-survives-reset');add('R01','U',0)
# Fixed-seed stateful combinations, always using public grammar.
rng=random.Random(17220261027)
for step in range(650):
c=rng.choice(['W','O','X','C','D','L','P','B','H','K','T','Z','I','J','A','E','Q','U','N'])
i=rng.choice([0,1,2,3,8,16,32,33]);n=rng.randrange(100,100000)
if c in ('W','O'):args=[i,rng.choice([0,1,2,8,9]),rng.choice([-1,0,1,2]),rng.choice([0,1,2,3,16,17,64,65])]
elif c in ('X','C','Z'):args=[i]
elif c in ('D','L'):args=[i,rng.choice([0,1,2,16,17,64,65])]
elif c=='P':args=[i,rng.choice([-1000001,-1000000,rng.randint(-1000,1000),1000000,1000001]),n]
elif c=='B':
values=[rng.randint(-1000,1000) for _ in range(rng.choice([0,1,3,16,17]))];args=[i,n,len(values)]+values
elif c in ('H','K','I','J'):args=[i,n]
elif c=='T':args=[i,rng.choice([-1,0,1,64,65]),n]
elif c=='U':args=[rng.randrange(2)]
else:args=[]
add('R01-R15 seeded-combinations',c,*args)
if step%29==0:observe('R03,R11,R12 seeded-state')
# Observer's Number domain includes both signed 64-bit endpoints.
add('R02,R03,R13 Number-endpoints','N')
add('R13','W',1,1,1,1)
add('R13','O',1,1,1,1)
for nonce in (-9223372036854775808,9223372036854775807):
for i in (1,33):
add('R03,R13 output-endpoints','P',i,1000001,nonce)
batch('R03,R10,R13 output-endpoints',i,[1000001],nonce)
batch('R10,R13 empty-batch-endpoints',i,[],nonce)
for c in ('H','K','I','J'):add('R03,R13 output-endpoints',c,i,nonce)
add('R03,R13 output-endpoints','T',i,0,nonce)
add('R02,R03,R13 payload-wide-domain','P',1,nonce,nonce)
observe('R03,R13 wide-domain-state')
# Complete native int endpoints for all integer parameter domains.
add('R02,R03,R13 int-endpoints','N')
add('R02','W',1,1,1,1);add('R02','O',1,1,1,1)
for extreme in (-2147483648,2147483647):
for c in ('W','O'):
add('R02 int-id',c,extreme,1,1,1)
add('R02 int-topic',c,1,extreme,1,1)
add('R02 int-durability',c,1,1,extreme,1)
add('R02 int-limit',c,1,1,1,extreme)
for c in ('X','C','Z'):add('R02,R03 int-existing-id',c,extreme)
for c in ('D','L'):
add('R02,R03 int-existing-id',c,extreme,extreme)
add('R02,R03 int-limit',c,1,extreme)
for c in ('H','K','I','J'):add('R02,R03 int-existing-id',c,extreme,883)
add('R02,R03 int-existing-id','P',extreme,1000001,883)
add('R02,R03 int-existing-id','T',extreme,extreme,883)
add('R02,R03 int-count','T',1,extreme,883)
batch('R02,R03 int-existing-id',extreme,[1000001])
observe('R02,R03 int-endpoint-atomicity')
inputs=['','\n \t\n'+'\n'.join(commands)+'\n\n'];answers=['','\n'.join(expected)+'\n']
# All trusted scratch I/O is complete before starting the first compiler process.
scratch=Path(tempfile.mkdtemp(prefix='durable-',dir=Path.cwd()))
source=Path(sys.argv[1])
contents={name:(source/name).read_bytes() for name in CANDIDATES}
contents['observer.cpp']=OBSERVER.encode()
for name,data in contents.items():(scratch/name).write_bytes(data)
for index,data in enumerate(inputs):(scratch/('input-'+str(index)+'.txt')).write_text(data)
def event(kind, **fields):
print(json.dumps(dict(event=kind,**fields),sort_keys=True),file=sys.stderr,flush=True)
def reject(reason, **fields):
event('reject',reason=reason,**fields)
print(reason)
sys.exit(1)
argv=['c++','-std=c++17','-O2','-Wall','-Wextra',*CANDIDATES[1:],'observer.cpp','-o','observer']
built=subprocess.run(argv,cwd=scratch,capture_output=True,timeout=35)
event('build',exitcode=built.returncode,stdout_bytes=len(built.stdout),stderr_bytes=len(built.stderr))
if built.returncode:
reject('build rejected',detail=built.stderr[-1000:].decode('utf-8','backslashreplace'))
results=[]
for index,data in enumerate(inputs):
result=subprocess.run([str(scratch/'observer')],cwd=scratch,input=data.encode(),capture_output=True,timeout=15)
event('run',scene=index,exitcode=result.returncode,stdin_bytes=len(data.encode()),stdout_bytes=len(result.stdout),stderr_bytes=len(result.stderr))
results.append(result)
# Do not access scratch after a candidate/compiler process has started.
for index,(result,answer) in enumerate(zip(results,answers)):
if result.returncode:
reject('execution rejected',scene=index,exitcode=result.returncode)
if result.stderr:
reject('stderr forbidden',scene=index,stderr_bytes=len(result.stderr))
if result.stdout!=answer.encode():
got=result.stdout.split(b'\n');want=answer.encode().split(b'\n')
at=next((n for n,(x,y) in enumerate(zip(got,want)) if x!=y),min(len(got),len(want)))
label='empty-stdin R01,R13' if index==0 else labels[at] if at<len(labels) else 'R13-R15 extra-output'
reject('behavior mismatch '+label,scene=index,row=at,got=repr(got[at:at+1])[:200],want=repr(want[at:at+1])[:200])
event('accepted',commands=len(commands),scenes=len(inputs))
print('PASS')