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>
287 lines
14 KiB
Python
287 lines
14 KiB
Python
"""Private independent integer model and raw-observer comparison."""
|
|
from pathlib import Path
|
|
import json
|
|
import random
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
LOW = -(1 << 63)
|
|
HIGH = (1 << 63) - 1
|
|
OK, RANGE, EXISTS, DEAD, STALE, TOKEN, ENGAGED, WAIT, OWNER, QUEUED, TURN, NOT_OWNER, NOT_WAITING, BUSY, OVERFLOW = range(15)
|
|
|
|
class Model:
|
|
def __init__(self):
|
|
self.slots = [dict(active=0, epoch=0, token=0, owner=-1, value=0, queue=[]) for _ in range(8)]
|
|
self.actors = [[0, -1, 0] for _ in range(16)]
|
|
|
|
def bind(self, p, kind, slot):
|
|
self.actors[p] = [kind, slot, self.slots[slot]['epoch']]
|
|
|
|
def valid(self, args, participants=()):
|
|
s, e, t = args[:3]
|
|
if not 0 <= s < 8 or any(not 0 <= p < 16 for p in participants):
|
|
return RANGE
|
|
node = self.slots[s]
|
|
if not node['active']:
|
|
return DEAD
|
|
if node['epoch'] != e:
|
|
return STALE
|
|
if node['token'] != t:
|
|
return TOKEN
|
|
return OK
|
|
|
|
def step(self, command):
|
|
op, *v = command
|
|
reply = op in ('I', 'R', 'Z', 'Q')
|
|
def result(code, value=0):
|
|
return [op, code, value] if reply else [op, code]
|
|
if op == 'I':
|
|
s, t = v
|
|
if not 0 <= s < 8:
|
|
return result(RANGE)
|
|
node = self.slots[s]
|
|
if node['active']:
|
|
return result(EXISTS)
|
|
node.update(active=1, epoch=node['epoch'] + 1, token=t, owner=-1, value=0, queue=[])
|
|
return result(OK, node['epoch'])
|
|
if op == 'V':
|
|
s = v[0]
|
|
if not 0 <= s < 8:
|
|
return [op, RANGE, 0, 0, 0, -1, 0, 0]
|
|
n = self.slots[s]
|
|
return [op, OK, n['active'], n['epoch'], n['token'], n['owner'], n['value'], len(n['queue']), *n['queue']]
|
|
if op == 'P':
|
|
p = v[0]
|
|
return [op, OK, *self.actors[p]] if 0 <= p < 16 else [op, RANGE, 0, -1, 0]
|
|
if op == 'S':
|
|
return [op, sum(n['active'] for n in self.slots), sum(n['owner'] != -1 for n in self.slots), sum(len(n['queue']) for n in self.slots)]
|
|
participants = v[3:5] if op == 'H' else v[3:4] if op in ('L', 'N', 'U', 'C', 'X', 'A', 'Q') else ()
|
|
code = self.valid(v, participants)
|
|
if code != OK:
|
|
return result(code)
|
|
s, e, t = v[:3]
|
|
n = self.slots[s]
|
|
p = v[3] if len(v) > 3 else None
|
|
if op == 'D':
|
|
if n['owner'] != -1 or n['queue']:
|
|
return result(BUSY)
|
|
n.update(active=0, token=0, owner=-1, value=0, queue=[])
|
|
elif op == 'T':
|
|
if n['owner'] != -1 or n['queue']:
|
|
return result(BUSY)
|
|
n['token'] = p
|
|
elif op == 'R':
|
|
return result(OK, n['value'])
|
|
elif op in ('L', 'N'):
|
|
if n['owner'] == p:
|
|
return result(OWNER)
|
|
if p in n['queue']:
|
|
return result(QUEUED)
|
|
if self.actors[p][0]:
|
|
return result(ENGAGED)
|
|
if n['owner'] == -1 and not n['queue']:
|
|
n['owner'] = p
|
|
self.bind(p, 1, s)
|
|
elif op == 'N':
|
|
return result(BUSY)
|
|
else:
|
|
n['queue'].append(p)
|
|
self.bind(p, 2, s)
|
|
return result(WAIT)
|
|
elif op == 'U':
|
|
if n['owner'] != p:
|
|
return result(NOT_OWNER)
|
|
n['owner'] = -1
|
|
self.actors[p] = [0, -1, 0]
|
|
elif op == 'C':
|
|
if n['owner'] == p:
|
|
return result(OWNER)
|
|
if p not in n['queue']:
|
|
return result(NOT_WAITING)
|
|
if n['owner'] != -1:
|
|
return result(BUSY)
|
|
if n['queue'][0] != p:
|
|
return result(TURN)
|
|
n['queue'].pop(0)
|
|
n['owner'] = p
|
|
self.bind(p, 1, s)
|
|
elif op == 'X':
|
|
if n['owner'] == p:
|
|
return result(OWNER)
|
|
if p not in n['queue']:
|
|
return result(NOT_WAITING)
|
|
n['queue'].remove(p)
|
|
self.actors[p] = [0, -1, 0]
|
|
elif op == 'H':
|
|
q = v[4]
|
|
if n['owner'] != p:
|
|
return result(NOT_OWNER)
|
|
if q not in n['queue']:
|
|
return result(NOT_WAITING)
|
|
if n['queue'][0] != q:
|
|
return result(TURN)
|
|
self.actors[p] = [0, -1, 0]
|
|
n['queue'].pop(0)
|
|
n['owner'] = q
|
|
self.bind(q, 1, s)
|
|
elif op == 'Z':
|
|
if n['owner'] != -1:
|
|
return result(BUSY)
|
|
count = len(n['queue'])
|
|
for q in n['queue']:
|
|
self.actors[q] = [0, -1, 0]
|
|
n['queue'].clear()
|
|
return result(OK, count)
|
|
elif op == 'A':
|
|
if n['owner'] != p:
|
|
return result(NOT_OWNER)
|
|
total = n['value'] + v[4]
|
|
if not LOW <= total <= HIGH:
|
|
return result(OVERFLOW)
|
|
n['value'] = total
|
|
elif op == 'Q':
|
|
if n['owner'] == p:
|
|
return result(OK, -1)
|
|
if p in n['queue']:
|
|
return result(OK, n['queue'].index(p))
|
|
return result(NOT_WAITING)
|
|
else:
|
|
raise RuntimeError(op)
|
|
return result(OK)
|
|
|
|
|
|
def encode(rows):
|
|
return b''.join((' '.join(map(str, row)) + '\n').encode('ascii') for row in rows)
|
|
|
|
|
|
def scenes():
|
|
all_scenes = []
|
|
def add_scene(name, rows):
|
|
model = Model()
|
|
expected = encode([model.step(row) for row in rows])
|
|
all_scenes.append((name, rows, encode(rows), expected))
|
|
add_scene('empty', [])
|
|
add_scene('smoke', [('I',2,17),('L',2,1,17,4),('A',2,1,17,4,9),('U',2,1,17,4),('D',2,1,17),('I',2,17),('R',2,1,17),('V',2)])
|
|
# Repeated identity cycles, independent slots, full-width tokens and stale handles.
|
|
rows = [('S',)] + [('V',s) for s in range(8)] + [('P',p) for p in range(16)]
|
|
for s in range(8):
|
|
for epoch in range(1,5):
|
|
token = [LOW, HIGH, 0, -1][epoch-1]
|
|
rows += [('I',s,token),('I',s,token),('V',s),('R',s,epoch,token),('R',s,epoch-1,token),('L',s,epoch,token,15),('P',15),('A',s,epoch,token,15,s+epoch),('U',s,epoch,token,15),('T',s,epoch,token,token),('T',s,epoch,token,7),('R',s,epoch,token),('R',s,epoch,7),('D',s,epoch,7),('D',s,epoch,7),('R',s,epoch,7),('V',s),('P',15),('S',)]
|
|
add_scene('identity_cycles',rows)
|
|
rows = [('I',0,LOW),('I',7,HIGH),('L',0,1,LOW,0),('A',0,1,LOW,0,37),('L',7,1,HIGH,15),('L',7,1,HIGH,0),('N',7,1,HIGH,0),('L',0,1,LOW,0),('N',0,1,LOW,0),('Q',0,1,LOW,0),('L',0,1,LOW,1),('L',0,1,LOW,2),('L',0,1,LOW,3),('L',0,1,LOW,2),('N',0,1,LOW,2),('C',0,1,LOW,1),('C',0,1,LOW,0),('X',0,1,LOW,0),('Z',0,1,LOW),('D',0,1,LOW),('T',0,1,LOW,0),('H',0,1,LOW,2,1),('H',0,1,LOW,0,9),('H',0,1,LOW,0,2),('H',0,1,LOW,0,1),('R',0,1,LOW),('P',0),('P',1),('Q',0,1,LOW,2),('X',0,1,LOW,2),('V',0),('L',0,1,LOW,4),('Q',0,1,LOW,4),('Q',0,1,LOW,3),('Q',0,1,LOW,9),('U',0,1,LOW,1),('V',0),('D',0,1,LOW),('V',0),('P',3),('P',4),('S',),('N',0,1,LOW,0),('T',0,1,LOW,4),('C',0,1,LOW,4),('X',0,1,LOW,3),('V',0),('C',0,1,LOW,4),('R',0,1,LOW),('U',0,1,LOW,4),('L',0,1,LOW,3),('L',0,1,LOW,4),('U',0,1,LOW,3),('Z',0,1,LOW),('Z',0,1,LOW),('P',4),('D',0,1,LOW),('V',0),('S',)]
|
|
# Full queue length and both free/owned states; no automatic handoff or bypass.
|
|
rows += [('U',7,1,HIGH,15),('D',7,1,HIGH),('I',7,0),('N',7,2,0,0)]
|
|
rows += [('L',7,2,0,p) for p in range(1,16)]
|
|
rows += [('Q',7,2,0,p) for p in range(16)] + [('V',7),('S',),('U',7,2,0,0),('D',7,2,0),('Z',7,2,0)]
|
|
rows += [('P',p) for p in range(16)] + [('D',7,2,0),('S',)]
|
|
rows += [('I',0,99),('L',0,2,99,0),('L',0,2,99,1),('U',0,2,99,0),('L',0,2,99,2),('V',0),('Q',0,2,99,2),('C',0,2,99,2),('C',0,2,99,1),('R',0,2,99),('U',0,2,99,1),('Z',0,2,99),('D',0,2,99)]
|
|
add_scene('queue_lifecycle',rows)
|
|
# Every supported Handle API observes each validation branch directly.
|
|
rows=[]
|
|
handle_ops=['D','R','Z','T','L','N','U','C','X','Q','A','H']
|
|
def operation(op,h,p=0,q=1):
|
|
extra=[]
|
|
if op in ['T','L','N','U','C','X','Q']:extra=[p]
|
|
if op in ['A','H']:extra=[p,q]
|
|
return (op,*h,*extra)
|
|
invalid=[LOW,-1,8,HIGH]
|
|
for x in invalid:
|
|
rows += [('I',x,LOW),('V',x)]
|
|
rows += [operation(op,(x,LOW,HIGH),LOW,HIGH) for op in handle_ops]
|
|
for p in [LOW,-1,16,HIGH]:rows += [('P',p)]
|
|
for op in handle_ops:rows += [operation(op,(0,LOW,HIGH))]
|
|
rows += [('I',0,LOW)]
|
|
for epoch in [LOW,-1,0,2,HIGH]:
|
|
rows += [operation(op,(0,epoch,HIGH)) for op in handle_ops]
|
|
for token in [HIGH,-1,0,1]:
|
|
rows += [operation(op,(0,1,token)) for op in handle_ops]
|
|
for op in ['L','N','U','C','X','Q','A','H']:
|
|
for p in [LOW,-1,16,HIGH]:
|
|
rows += [operation(op,(0,LOW,HIGH),p,HIGH),operation(op,(7,0,0),p,HIGH),operation(op,(0,1,LOW),p,HIGH)]
|
|
for q in [LOW,-1,16,HIGH]:rows += [('H',0,1,LOW,0,q)]
|
|
rows += [('V',0),('P',0),('S',),('N',0,1,LOW,0),('A',0,1,LOW,1,LOW),('A',0,1,LOW,0,0),('A',0,1,LOW,0,HIGH),('A',0,1,LOW,0,1),('R',0,1,LOW),('A',0,1,LOW,0,LOW),('R',0,1,LOW),('A',0,1,LOW,0,-HIGH),('A',0,1,LOW,0,-1),('R',0,1,LOW),('A',0,1,LOW,0,HIGH),('A',0,1,LOW,0,1),('R',0,1,LOW),('U',0,1,LOW,0),('A',0,1,LOW,0,0),('T',0,1,LOW,HIGH),('V',0),('D',0,1,HIGH),('V',0)]
|
|
add_scene('domains_and_errors',rows)
|
|
rows=[('I',0,17),('I',1,-17),('L',0,1,17,0),('A',0,1,17,0,37),('L',0,1,17,1),('L',0,1,17,2),('L',1,1,-17,15),('L',1,1,-17,14)]
|
|
probes=[('V',slot) for slot in range(8)]+[('P',p) for p in range(16)]+[('S',)]
|
|
rows+=probes
|
|
failures=[('I',0,99)]
|
|
for op in handle_ops:
|
|
for h in [(-1,1,17),(7,1,17),(0,0,17),(0,1,18)]:
|
|
failures.append(operation(op,h,4,5))
|
|
for op in ['L','N','U','C','X','Q','A','H']:
|
|
failures.append(operation(op,(0,1,17),-1,16))
|
|
failures += [('D',0,1,17),('T',0,1,17,0),('L',0,1,17,0),('L',0,1,17,1),('L',0,1,17,15),('N',0,1,17,0),('N',0,1,17,1),('N',0,1,17,15),('N',0,1,17,4),('U',0,1,17,1),('C',0,1,17,0),('C',0,1,17,4),('C',0,1,17,1),('X',0,1,17,0),('X',0,1,17,4),('H',0,1,17,1,2),('H',0,1,17,0,4),('H',0,1,17,0,2),('H',0,1,17,0,0),('Z',0,1,17),('A',0,1,17,1,0),('Q',0,1,17,4)]
|
|
for row in failures:
|
|
rows.append(row);rows+=probes
|
|
rows += [('U',0,1,17,0)] + probes
|
|
for row in [('D',0,1,17),('T',0,1,17,0),('N',0,1,17,4),('C',0,1,17,2)]:
|
|
rows.append(row);rows+=probes
|
|
add_scene('failure_atomicity',rows)
|
|
rng=random.Random(16020261027)
|
|
rows=[]
|
|
model=Model()
|
|
for step in range(2500):
|
|
s=rng.randrange(8); n=model.slots[s]; p=rng.randrange(16)
|
|
op=rng.choice(['I','D','L','L','N','U','C','X','H','Z','A','R','T','Q','V','P','S'])
|
|
if op=='I': row=(op,s,rng.choice([LOW,HIGH,-9,0,17]))
|
|
elif op=='V':row=(op,s)
|
|
elif op=='P':row=(op,p)
|
|
elif op=='S':row=(op,)
|
|
else:
|
|
h=(s,n['epoch'],n['token'])
|
|
if rng.randrange(8)==0:h=(s,rng.choice([LOW,HIGH,0,n['epoch']+1]),n['token'])
|
|
row=operation(op,h,p,rng.choice([LOW,HIGH,0,-1,1,2,15]))
|
|
model.step(row);rows.append(row)
|
|
if step%25==0:rows.extend([('V',s),('P',p),('S',)])
|
|
rows += [('S',)] * (4096-len(rows))
|
|
add_scene('seeded_transitions',rows)
|
|
return all_scenes
|
|
|
|
|
|
def main():
|
|
candidate=Path(sys.argv[1])
|
|
names=['ledger.hpp','storage.hpp','identities.cpp','transitions.cpp','queries.cpp']
|
|
# Finish every trusted filesystem operation before the first compiler subprocess.
|
|
sources={name:(candidate/name).read_bytes() for name in names}
|
|
observer=(Path(__file__).resolve().parent/'observer.txt').read_bytes()
|
|
cases=scenes()
|
|
scratch=Path(tempfile.mkdtemp(prefix='instance-',dir=Path.cwd()))
|
|
for name,data in sources.items():
|
|
path=scratch/name;path.write_bytes(data)
|
|
path=scratch/'observer.cpp';path.write_bytes(observer)
|
|
argv=['g++','-std=c++17','-O2','-Wall','-Wextra','observer.cpp','identities.cpp','transitions.cpp','queries.cpp','-o','observe']
|
|
record={'build':None,'scenes':[],'first_reject':None}
|
|
try:
|
|
build=subprocess.run(argv,cwd=str(scratch),capture_output=True,timeout=35)
|
|
except subprocess.TimeoutExpired:
|
|
record['build']={'exit':'timeout'};record['first_reject']='build-timeout'
|
|
print(json.dumps(record,separators=(',',':')),file=sys.stderr);print('FAIL build timeout');return 1
|
|
record['build']={'exit':build.returncode,'out':len(build.stdout),'err':len(build.stderr)}
|
|
if build.returncode:
|
|
record['first_reject']='build';record['build']['stderr']=build.stderr[-700:].decode('utf8','replace')
|
|
print(json.dumps(record,separators=(',',':')),file=sys.stderr);print('FAIL build');return 1
|
|
for name,rows,data,expected in cases:
|
|
try:
|
|
run=subprocess.run([str(scratch/'observe')],input=data,cwd=str(scratch),capture_output=True,timeout=8)
|
|
item={'name':name,'exit':run.returncode,'out':len(run.stdout),'err':len(run.stderr),'reject':None}
|
|
if run.returncode:item['reject']='exit'
|
|
elif run.stderr:item['reject']='stderr'
|
|
elif run.stdout!=expected:item['reject']='stdout-bytes'
|
|
if item['reject'] and record['first_reject'] is None:
|
|
lines=run.stdout.split(b'\n');want=expected.split(b'\n')
|
|
index=next((i for i in range(min(len(lines),len(want))) if lines[i]!=want[i]),min(len(lines),len(want)))
|
|
record['first_reject']={'scene':name,'kind':item['reject'],'line':index+1,'command':list(rows[index]) if index<len(rows) else None,'want':want[index].decode('ascii')[:140] if index<len(want) else None,'got':lines[index].decode('ascii','replace')[:140] if index<len(lines) else None}
|
|
except subprocess.TimeoutExpired:
|
|
item={'name':name,'exit':'timeout','out':None,'err':None,'reject':'timeout'}
|
|
if record['first_reject'] is None:record['first_reject']={'scene':name,'kind':'timeout'}
|
|
record['scenes'].append(item)
|
|
print(json.dumps(record,separators=(',',':')),file=sys.stderr)
|
|
if record['first_reject'] is not None:
|
|
print('FAIL '+json.dumps(record['first_reject'],separators=(',',':')));return 1
|
|
print('PASS');return 0
|
|
|
|
if __name__=='__main__':
|
|
raise SystemExit(main())
|