from ops import *
import datetime,re
job='20260926-contextra-process-ab-r01'
assert cmd(['git','-C',str(REPO),'rev-parse','HEAD']).strip()=='37b4613fee1e713e98b09345b2a68be1e3c06978'
assert not cmd(['git','-C',str(REPO),'diff','--cached','--name-only']).strip()
paths=sorted(set(cmd(['git','-C',str(REPO),'diff','--name-only']).splitlines()+cmd(['git','-C',str(REPO),'ls-files','--others','--exclude-standard']).splitlines()))
assert len(paths)==10
cmd(['git','-C',str(REPO),'diff','--check'])
for p in paths:
    if not p.endswith('.md'):continue
    for target in re.findall(r'\]\(([^)]+)\)',(REPO/p).read_text()):
        if '://' not in target and not target.startswith('#'):assert ((REPO/p).parent/target.split('#')[0]).exists()
for p,h in json.loads((HERE/'build-final-intent.json').read_text())['hashes'].items():assert hashlib.sha256((REPO/p).read_bytes()).hexdigest()==h
final=json.loads((HERE/'final-state.json').read_text())
assert final['wss'] and final['stopped']==36 and not final['active']
save('verification.json',dict(final_targeted_tests=23,earlier_tests=28,helper_test=1,counts_overlap=True,python='3.12',
 request_thread_regression=dict(before='FAIL',after='PASS'),gpu_A='warmup application error; all11 reaped',gpu_B='NOT RUN',final=final,files=paths,portfolio='MEDIUM candidate only'))
receipt=dict(schema_version='ltb1021.codex_hub.report_receipt.v1',receipt_id=job,
 timestamp=datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=9))).isoformat(),
 session_alias='work-session',task='Child spawn thread 수명 결함 수정과 provider process A/B 도구 준비',
 results=['짧은request thread 종료로child가종료되는결함을fixture재현하고supervisor thread가spawn/reap소유하도록수정',
 'bounded exit signal/terminal/stop근거와최초provider fatal진단추가;격리된재사용CLI준비',
 'A warmup combined가multi_provider_results오류보고;exit0/terminal_failed;Medium10유지;11child회수;B미실행'],
 verify=['최종Python3.12 표적23PASS;앞서28PASS/helper1PASS(중복합산금지)',
 'source/image hash일치;36stopped/WSS연결/4모델READY/Artifact HTTP On/원래설정및비대상보존'],
 commits=[],remaining=['A최초failure stall/exception상세확인','정상A성립후B측정및process분리방향결정','Artifact기존미해결유지'])
save('report-receipt.json',receipt)
print(cmd(['codex-report-receipt','--profile','ltb1021','--session-alias','work-session','--receipt',str(HERE/'report-receipt.json')]))
out=Path('/tmp/codex/ltb1021/git-closeout')/job;out.mkdir(mode=0o700)
mf=out/'manifest.json'
args=['codex-git-closeout','prepare','--repository',str(REPO),'--output',str(mf),'--job-id',job,
 '--profile','ltb1021','--session-alias','work-session',
 '--title','fix(runtime): child spawn 수명 보장과 process 비교 진단 준비',
 '--message','Why=요청thread 종료가 Linux parent-death 보호로channel child를종료시킬수있으며,혼합부하실패와process분리효과를구분할근거가부족했다.',
 '--message','What=기존supervisor thread가spawn/reap을소유하도록수정하고bounded종료진단과provider fatal진단을추가했다.외부출력없는명시적A/B CLI와가이드를보존한다.',
 '--message','Impact=parent-death보호유지,Start/Settings/Event/Artifact schema및모델/instance/batch/FPS/deadline불변.상태API에bounded diagnostic추가.운영process분리default전환없음.',
 '--message','Verify=요청thread fixture기존FAIL/수정후PASS.최종Python3.12 표적23PASS. GPU A warmup application오류로11child회수, B NOT RUN으로비교불충분.최종36stopped/WSS연결/4모델READY/Artifact HTTP On.추가fatal진단후GPU재시험없음.',
 '--message','Rollback=이전pr13-mixed image/config보존.명시승인후채널회수와image pin전환으로복귀가능.이번에는도구/image/계측보존하고자동rollback/자동카메라Start없음.',
 '--verify','Python3.12 targeted23 PASS; request thread lifetime regression reproduced before and passes after; diff check PASS',
 '--verify','A warmup application error/exit0 terminal_failed; all11 children reaped; B NOT RUN; final36 stopped, WSS/model ready',
 '--expires-in-seconds','86400']
for p in paths:args+=['--path',p]
print(cmd(args))
batch=out/'batch.json'
print(cmd(['codex-git-closeout','batch-prepare','--output',str(batch),'--batch-id',job,'--profile','ltb1021','--session-alias','work-session','--expected-group-count','1','--repository-label','contextra-analytics','--manifest',str(mf),'--expect-plan-hash',json.loads(mf.read_text())['plan_hash'],'--expires-in-seconds','86400']))
h=json.loads(batch.read_text())['plan_hash']
print(cmd(['codex-git-closeout','batch-plan','--batch-manifest',str(batch),'--expect-batch-plan-hash',h]))
print(cmd(['codex-git-closeout','batch-present','--batch-manifest',str(batch),'--expect-batch-plan-hash',h]))
