Skip to content

Commit 9358672

Browse files
committed
ownership-lab H-26B / H-27: census-only resolvability seam (OWEN_H26B_CENSUS: receiver construction provenance, concrete override row, sink and transfer of every disposable-returning library call; 89 lines, no lowering change); H-27 runtime probe program and raw results; census runner
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Am9eQwzNfbugH72eVKetC2
1 parent c0356df commit 9358672

7 files changed

Lines changed: 325 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""H-26B base-typed virtual resolvability census (derived from the H-25 runner; corrected environment; H-25 row files) (derived from the H-24 runner; harness invariant 0: the corrected environment is the default) over the kept H-23A scan clones (e3h23/<tag>): the SAME project/TFM units, reference
2+
directories and trusted row files the OFF/ON scans used; runs the extractor once per unit with OWEN_RE_ORACLE=<unit
3+
rows> and OWEN_H24_CENSUS=<unit>/h24.jsonl (census only, no engines), then aggregates one record per disposable local
4+
with nested writes. usage: h24census.py <repo> [<repo> ...]"""
5+
import json, os, sys, subprocess, glob, re, hashlib, time, collections
6+
S='/tmp/claude-0/-home-user/8a9da608-aa27-5449-8306-1fae9426f9b9/scratchpad'; R='/home/user/Own.NET'; E=f'{S}/lab/sc/e3h23'; E2=f'{S}/lab/sc/e2h23'
7+
FIX=True # corrected compilation environment: SDK implicit global usings + the ASP.NET Core ref pack (erratum 2)
8+
XD={'net8':f'{S}/ext8q/ownsharp-extract.dll','net10':f'{S}/ext10q/ownsharp-extract.dll'}
9+
OUT=f'{S}/lab/h26b/census'; os.makedirs(OUT,exist_ok=True)
10+
sys.path.insert(0,f'{S}/lab/h24'); from implicit_usings import implicit_usings
11+
def aspnet_ref(major):
12+
c=sorted(glob.glob(f'/root/.dotnet/packs/Microsoft.AspNetCore.App.Ref/{major}.*/ref/net{major}.0'))
13+
return c[-1] if c else None
14+
env={**os.environ,'PATH':'/root/.dotnet:'+os.environ['PATH'],'DOTNET_NOLOGO':'1','DOTNET_CLI_TELEMETRY_OPTOUT':'1','DOTNET_SKIP_FIRST_TIME_EXPERIENCE':'1'}
15+
for k in ('OWEN_RE_ORACLE','OWEN_H23A','OWEN_RE_BODY','OWEN_RE_MINTED_RETURN','OWEN_RE_MIXED_RETURN','OWEN_LAB_THROWEXIT','OWEN_LAB_NULLINIT','OWEN_LAB_NULLGUARD','OWEN_P037X_GUARDED','OWEN_P037X_RELATIONAL','OWEN_RE_ORACLE_HITLOG','OWEN_H24_CENSUS','OWEN_H25_CENSUS','OWEN_H26B_CENSUS'): env.pop(k,None)
16+
EXCL=re.compile(r'(^|/)(tests?|testing|samples?|benchmarks?|examples?|docs?|demo)(/|\.|$)',re.I)
17+
TESTP=re.compile(r'(test|tests|testing|benchmark|bench|sample|samples|example|examples|demo|playground)',re.I)
18+
def assets_of(p,W):
19+
c=os.path.join(os.path.dirname(p),'obj','project.assets.json')
20+
if os.path.exists(c): return c
21+
pn=os.path.splitext(os.path.basename(p))[0]
22+
for c in glob.glob(f'{W}/**/artifacts/obj/{pn}/project.assets.json',recursive=True): return c
23+
return None
24+
for repo in sys.argv[1:]:
25+
tag=repo.replace('/','__'); W=f'{E}/{tag}'; t0=time.time()
26+
e2=json.load(open(f'{E2}/{tag}.e2.json'))
27+
projs=sorted(p for p in glob.glob(f'{W}/**/*.csproj',recursive=True)); prod=[p for p in projs if not EXCL.search(os.path.relpath(p,W))]
28+
units=0; recs=[]; fails=0
29+
for p in prod:
30+
rel=os.path.relpath(p,W); assets=assets_of(p,W)
31+
if not assets or rel not in e2['per_project'] or 'targets' not in e2['per_project'][rel]: continue
32+
a=json.load(open(assets))
33+
for tfm in a['targets']:
34+
tfm0=tfm.split('/')[0]
35+
if tfm0 not in e2['per_project'][rel]['targets']: continue
36+
refdir=f'{W}/.refs/{hashlib.sha256((rel+tfm).encode()).hexdigest()[:10]}'; keyf=f'{refdir}/rows.json'
37+
if not os.path.exists(keyf): continue
38+
srcs=sorted(x for x in glob.glob(os.path.join(os.path.dirname(p),'**','*.cs'),recursive=True) if '/obj/' not in x and '/bin/' not in x)
39+
if not srcs: continue
40+
m=re.match(r'net(\d+)\.',tfm0); major=int(m.group(1)) if m else 0; xd=XD['net10'] if major>=9 else XD['net8']
41+
sfx='h26b'; out=f'{refdir}/{sfx}.jsonl'; open(out,'w').close(); hits=f'{refdir}/{sfx}hits.jsonl'; open(hits,'w').close()
42+
e={**env,'OWEN_RE_ORACLE':keyf,'OWEN_H26B_CENSUS':out,'OWEN_RE_ORACLE_HITLOG':hits}; extra=[]
43+
if FIX:
44+
ns=implicit_usings(p) or []
45+
if ns:
46+
gu=f'{refdir}/GlobalUsings.g.cs'; open(gu,'w').write(''.join(f'global using {n};\n' for n in ns)); extra.append(gu)
47+
ar=aspnet_ref(major if major else 8)
48+
if ar: e['OWN_EXTRA_REF_DIRS']=ar
49+
try: pr=subprocess.run(['dotnet',xd,'--flow-locals',*srcs,*extra,'--ref-dir',refdir,'-o',f'{refdir}/{sfx}.facts.json'],cwd=R,capture_output=True,text=True,env=e,timeout=1500); rc=pr.returncode
50+
except subprocess.TimeoutExpired: rc='timeout'
51+
if rc!=0: fails+=1
52+
units+=1
53+
for l in open(out):
54+
if not l.strip(): continue
55+
j=json.loads(l); j['project']=rel; j['tfm']=tfm0; j['kind']='test' if TESTP.search(os.path.basename(rel)) or TESTP.search(os.path.relpath(j['file'],W) if j['file'].startswith(W) else j['file']) else 'production'
56+
j['file']=os.path.relpath(j['file'],W) if j['file'].startswith(W) else j['file']; recs.append(j)
57+
json.dump({'repo':repo,'sha':e2['sha'],'units':units,'extractor_failures':fails,'seconds':round(time.time()-t0),'environment':'corrected (implicit usings + aspnet ref pack)' if FIX else 'as-is','records':recs},open(f'{OUT}/{tag}.h26b.json','w'),indent=1)
58+
c=collections.Counter((r['kind'],r['provenance']) for r in recs if r['is_virtual_member'])
59+
print('H26B_DONE',repo,'units',units,'fails',fails,'disposable-returning library calls',len(recs),'virtual-member sites by kind/provenance',dict(c),flush=True)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""SDK implicit global usings for a project (what the build would generate into obj/<Project>.GlobalUsings.g.cs):
2+
Microsoft.NET.Sdk: System, System.Collections.Generic, System.IO, System.Linq, System.Net.Http, System.Threading,
3+
System.Threading.Tasks; Microsoft.NET.Sdk.Web adds the ASP.NET Core / Microsoft.Extensions namespaces;
4+
Microsoft.NET.Sdk.Worker adds Microsoft.Extensions.*; plus <Using Include="..."/> and minus <Using Remove="..."/> items
5+
from the project file and every Directory.Build.props above it; nothing when ImplicitUsings is not enabled."""
6+
import os, re, xml.etree.ElementTree as ET
7+
BASE=['System','System.Collections.Generic','System.IO','System.Linq','System.Net.Http','System.Threading','System.Threading.Tasks']
8+
WEB=['Microsoft.AspNetCore.Builder','Microsoft.AspNetCore.Hosting','Microsoft.AspNetCore.Http','Microsoft.AspNetCore.Routing','Microsoft.Extensions.Configuration','Microsoft.Extensions.DependencyInjection','Microsoft.Extensions.Hosting','Microsoft.Extensions.Logging']
9+
WORKER=['Microsoft.Extensions.Configuration','Microsoft.Extensions.DependencyInjection','Microsoft.Extensions.Hosting','Microsoft.Extensions.Logging']
10+
def props_chain(csproj):
11+
out=[]; d=os.path.dirname(os.path.abspath(csproj))
12+
while True:
13+
p=os.path.join(d,'Directory.Build.props')
14+
if os.path.exists(p): out.append(p)
15+
if d==os.path.dirname(d): break
16+
d=os.path.dirname(d)
17+
return out[::-1] # outermost first
18+
def implicit_usings(csproj):
19+
try: root=ET.parse(csproj).getroot()
20+
except Exception: return None
21+
sdk=(root.attrib.get('Sdk') or '')
22+
enabled=None; add=[]; rem=[]
23+
for f in props_chain(csproj)+[csproj]:
24+
try: r=ET.parse(f).getroot()
25+
except Exception: continue
26+
for e in r.iter():
27+
tag=e.tag.split('}')[-1]
28+
if tag=='ImplicitUsings' and (e.text or '').strip().lower() in ('enable','true'): enabled=True
29+
if tag=='ImplicitUsings' and (e.text or '').strip().lower() in ('disable','false'): enabled=False
30+
if tag=='Using' and e.attrib.get('Include'): add.append(e.attrib['Include'].strip())
31+
if tag=='Using' and e.attrib.get('Remove'): rem.append(e.attrib['Remove'].strip())
32+
if not enabled: return []
33+
ns=list(BASE)
34+
if sdk.startswith('Microsoft.NET.Sdk.Web'): ns+=WEB
35+
elif sdk.startswith('Microsoft.NET.Sdk.Worker'): ns+=WORKER
36+
ns+= [a for a in add if not a.startswith('static ') and '=' not in a]
37+
return [n for n in dict.fromkeys(ns) if n not in rem]
38+
if __name__=='__main__':
39+
import sys
40+
for p in sys.argv[1:]: print(p, implicit_usings(p))

‎corpus/ownership-lab/h27/pgkeep.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pgserver, time, sys
2+
s = pgserver.get_server('/tmp/pgsc', cleanup_mode=None)
3+
print('PG_UP', s.get_uri(), flush=True)
4+
while True: time.sleep(3600)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{"api":"BeginTransactionAsync","probe":"P1_simultaneous","result":"throws","error":"InvalidOperationException: A transaction is already in progress; nested/concurrent transactions aren\u0027t supported."}
2+
{"api":"BeginTransactionAsync","probe":"P2_sequential_after_release","same_identity":true,"second_handle":"usable"}
3+
{"api":"BeginTransactionAsync","probe":"P3_use_after_release","commit_on_released":"commit on released handle WORKS","command_with_released":"throws: InvalidOperationException: Transaction is already completed","note":"t1 released by DisposeAsync; t2 live at this point"}
4+
{"api":"BeginTransactionAsync","probe":"P4_release_surface","results":[{"how":"DisposeAsync","ends_obligation":"next acquisition OK"},{"how":"Dispose","ends_obligation":"next acquisition OK"},{"how":"CommitAsync","ends_obligation":"next acquisition OK"},{"how":"RollbackAsync","ends_obligation":"next acquisition OK"}]}
5+
{"api":"BeginTransactionAsync","probe":"P5_receiver_reclaims","after":"handle unusable after receiver closed: InvalidOperationException: Transaction is already completed","disp":"DisposeAsync after receiver close OK"}
6+
{"api":"BeginTransactionAsync","probe":"P6_disposal_mandatory","another_operation":"another command on the receiver WORKS (runs inside the open transaction)","second_acquisition":"second acquisition throws: InvalidOperationException: A transaction is already in progress; nested/concurrent transactions aren\u0027t supported.","receiver_close":"receiver close with a live transaction OK (rolled back on return to pool)"}
7+
{"api":"ExecuteReaderAsync","probe":"P1_simultaneous","result":"throws","error":"NpgsqlOperationInProgressException: A command is already in progress: SELECT id FROM h27"}
8+
{"api":"ExecuteReaderAsync","probe":"P2_sequential_after_release","same_identity":true,"second_handle":"usable"}
9+
{"api":"ExecuteReaderAsync","probe":"P3_use_after_release","read_on_released":"ReadAsync on released handle WORKS (returned True; the identity is live again as r2)","note":"r1 and r2 identity equality decides what this measures"}
10+
{"api":"ExecuteReaderAsync","probe":"P4_release_surface","results":[{"how":"DisposeAsync","ends_obligation":"next operation on the connection OK"},{"how":"Dispose","ends_obligation":"next operation on the connection OK"},{"how":"CloseAsync","ends_obligation":"next operation on the connection OK"},{"how":"exhaust","ends_obligation":"next operation throws: NpgsqlOperationInProgressException: A command is already in progress: SELECT id FROM h27"}]}
11+
{"api":"ExecuteReaderAsync","probe":"P5_receiver_reclaims","after_command_disposed":"reader usable after command disposed (True)","after_connection_closed":"reader unusable after connection closed: InvalidOperationException: The reader is closed"}
12+
{"api":"ExecuteReaderAsync","probe":"P6_disposal_mandatory","another_operation":"another operation throws with a live reader: NpgsqlOperationInProgressException: A command is already in progress: SELECT id FROM h27","second_acquisition":"second ExecuteReaderAsync throws: NpgsqlOperationInProgressException: A command is already in progress: SELECT id FROM h27"}
13+
{"probe":"DONE","npgsql":"10.0.3.0"}

0 commit comments

Comments
 (0)