← back to Ticket System
data/codex-yoloforever/cycle-20260908T1651Z.AQuuOW/persist.py
108 lines
import datetime, fcntl, hashlib, json, os, pathlib
P = pathlib.Path(__file__).resolve().parent
ROOT = P.parents[2]
def read(name): return json.loads((P / name).read_text())
def write(name, value): (P / name).write_text(json.dumps(value, indent=2) + '\n')
def digest(data): return hashlib.sha256(data).hexdigest()
C = pathlib.Path((P / 'closing-path.txt').read_text().strip())
closing = json.loads((C / 'monitor-final.json').read_text())
assert closing['counts']['FAIL'] == 0
dtd = read('dtd-final.json')
assert dtd['final_verdict'] in ['SHIP', 'HOLD-FOR-STEVE']
acceptance = read('parent-cody-acceptance.json')
assert acceptance['counts']['FAIL'] == 0
dispositions = read('ordered-dispositions.json')
dispositions[0]['reason'] = dispositions[0]['reason'].replace('3079 MB', str(closing['root_mb']) + ' MB')
for row in dispositions: row['closing_observed_at'] = closing['timestamp']
write('ordered-dispositions-final.json', dispositions)
# Preserve raw outputs locally. The reusable proof commits concise canonical
# metadata instead of duplicating the full historic ticket prose in every cycle.
proof = json.loads(json.dumps(closing))
for command in proof['commands']:
if command['argv'][:2] == ['node', '-e'] and "l.tickets()" in command['argv'][-1]:
command['stdout_sha256'] = digest(command['stdout'].encode())
command['stdout'] = 'Canonical response retained in the raw closing evidence directory.'
proof['scope'] = 'Verified monitoring only; all three source operational outcomes UNRESOLVED.'
proof['cody_acceptance'] = 'parent-cody-acceptance.json'
proof['final_dtd'] = dtd
proof['artifact_environment'] = str(P)
proof['risk_tier'] = 'R0 evidence; underlying R4 source outcomes unverified'
write('e2e-proof.json', proof)
record = dict(
schema_version=1, timestamp=datetime.datetime.now(datetime.timezone.utc).isoformat(),
cycle_id=P.name, source_tickets=[r['id'] for r in dispositions],
ordered_dispositions=dispositions, source_outcomes='All three UNRESOLVED',
execution_iterations=0, execution_cap=6,
actual_implementation_progress=dict(increments=0, new_preparation=0, operational_closures=0),
monitoring=dict(ordered_queue_entries=3, in_flight_metadata_entries=20,
open_non_task_workers=0, cap_deferrals=0,
root_closing_mb=closing['root_mb'], root_canary='FAIL',
enrichment=json.loads((C/'enrichment-observed.json').read_text()),
pricing=closing['pricing_rows'], scoped_inputs=29,
changed_scoped_input_metadata=len(json.loads((C/'pricing-inputs.json').read_text())['changed_metadata'])),
action='Persist read-only monitoring in supplied order and return normally',
dtd_verdict='No new increment; unchanged known blockers not re-debated',
cody=acceptance['cody'], final_dtd=dtd,
final_dtd_verdict=dtd['final_verdict'] + ' monitoring records only',
tests_evidence=dict(closing_counts=closing['counts'], source_canary='FAIL',
e2e=str(P/'e2e-proof.json'), raw=str(P),
critical_skips=[x['check'] for x in closing['checks'] if x['verdict']=='SKIP'],
ui='No UI produced; installed canary/API/auth-negative/READ ONLY SQL substitute'),
next_seed='Fresh ordered queue; changed exact current backup-maintenance approval, new provider-neutral per-request null reason or scoped diagnostic input, or authoritative wholesale/vendor-SKU inputs. Do not repeat completed historical rehearsal or unchanged generic correlation.',
gated_memos=['/Users/macstudio3/.claude/yolo-queue/pending-approval/2026-09-08-TK-10928-projects-root-snapshot-recovery.md', '/Users/macstudio3/.claude/yolo-queue/pending-approval/2026-09-04-TK-10066-architectural-fabrics-1005-active-no-price.md'],
new_gated_memos=0, clarify='Skipped: no new decision-changing ambiguity; existing conservative gates retained',
cost=dict(direct_paid_api_usd=0, external_spend_usd=0, provider_key_reads=0,
claude_invocations=0, dtd_subscription_tokens=dtd.get('subscription_tokens'),
parent_child_subscription_tokens='unmeasured'),
schedule='Existing 600-second launchd unchanged; STOPPED absent; runner observes actual worker exit after return')
write('cycle-record.json', record)
ledger=P.parent/'ledger.jsonl'
encoded=(json.dumps(record,separators=(',',':'))+'\n').encode()
with ledger.open('a+b') as f:
fcntl.flock(f,fcntl.LOCK_EX)
f.seek(0); before=f.read()
existing=[json.loads(x) for x in before.splitlines() if x.strip()]
found=[x for x in existing if x.get('cycle_id')==P.name]
if found:
assert found==[record], 'Conflicting existing cycle record'
appended=False
else:
f.seek(0,2); f.write(encoded); f.flush(); os.fsync(f.fileno()); appended=True
f.seek(0); after=f.read()
parsed=[json.loads(x) for x in after.splitlines() if x.strip()]
assert after.startswith(before)
assert [x for x in parsed if x.get('cycle_id')==P.name]==[record]
fcntl.flock(f,fcntl.LOCK_UN)
write('ledger-append-proof.json',dict(timestamp=datetime.datetime.now(datetime.timezone.utc).isoformat(),
path=str(ledger), appended=appended, exclusive_lock=True, fsync=True,
prefix_preserved=True, exactly_once=True, before_bytes=len(before), after_bytes=len(after),
prefix_sha256=digest(before), row_sha256=digest(encoded)))
report=('All three source outcomes remain UNRESOLVED. Zero execution increments (0/6), '
'zero new preparation, zero operational closures.\n\n' +
'\n'.join(f"{r['position']}. {r['id']}: {r['disposition']}. {r['reason']}" for r in dispositions)+
f"\n\nCody: {acceptance['cody']['verdict']}; {acceptance['cody']['votes']}. "
f"Top action: {acceptance['cody']['top_fix']}\n\n"
f"Final DTD: {dtd['final_verdict']} for monitoring persistence and normal return only; "
f"{dtd['tally']}, {dtd['availability']} available, mandatory Codex {dtd['post_decision']}. "
f"Dissent: {dtd['dissent']}\n\n"
f"Closing monitoring checks: {closing['counts']}. Actual backup canary remains FAIL. "
'Critical live-backup, enrichment-cause/recovery, authoritative pricing/sellability and later worker-exit checks remain SKIP. '
'No UI was produced; real classifier/API/auth-negative/READ ONLY SQL checks substitute for CTA and screenrecord.\n\n'
'All 20 in-flight entries were monitored through canonical ownership/activity only. No source claims/status changes, '
'provider calls, keys, external writes/messages, schedule changes or spend. Existing memos retained; no new gate memo. '
'Direct API/external spend $0; subscription token usage is separately recorded and parent/child usage unmeasured.\n\n'
'Ledger append was locked, fsynced and read back exactly once. Existing launchd remains at 600 seconds. '
'Next seed: changed exact maintenance approval or authoritative cause/pricing inputs, then fresh queue order. '
'The runner observes actual worker exit after this turn returns.\n')
(P/'FINAL-REPORT.md').write_text(report)
verification=ROOT/'verification'
slug=P.name.replace('.','-')
(verification/(slug+'.md')).write_text(report)
(verification/(slug+'-e2e-proof.json')).write_text(json.dumps(proof,indent=2)+'\n')
print(json.dumps({'ledger_exactly_once':True,'counts':closing['counts'],'root_mb':closing['root_mb'],'execution':0,'report':str(verification/(slug+'.md'))}))