railiance-platform/scripts/root_custody_finish_entry.py
codex 33ff82210e
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Diagnose attended custody finish failures with safe staged receipts
Assistant: codex
Assistant-Model: gpt-6.1-sol
Assistant-Session: 01a1029d-2c93-7500-a0e0-e3e089668b29
2026-10-03 21:08:56 +02:00

40 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Stdlib-only silent bootstrap; reserves a new safe receipt before imports."""
import importlib.util
import json
import os
from pathlib import Path
import sys
from datetime import datetime,timezone
def main():
receipt=None
fd=None
try:
for index,arg in enumerate(sys.argv[1:],start=1):
if arg=='--receipt' and index+1<len(sys.argv):
receipt=Path(sys.argv[index+1])
elif arg.startswith('--receipt='):
receipt=Path(arg.split('=',1)[1])
if receipt is None or receipt.is_symlink():
return 1
fd=os.open(receipt,os.O_CREAT|os.O_EXCL|os.O_WRONLY,0o600)
result={'ok':False,'status':'started','stage':'helper_import','recorded_at':datetime.now(timezone.utc).isoformat()}
os.write(fd,json.dumps(result).encode());os.fsync(fd);os.close(fd);fd=None
spec=importlib.util.spec_from_file_location('custody_finish',Path(__file__).with_name('root_custody_finish.py'))
helper=importlib.util.module_from_spec(spec);spec.loader.exec_module(helper)
return helper.main(receipt_reserved=True)
except FileExistsError:
return 1
except BaseException:
if receipt is not None:
try:
if fd is not None:os.close(fd)
result={'ok':False,'status':'failed','stage':'helper_import','error_code':'helper_startup_failed','recorded_at':datetime.now(timezone.utc).isoformat()}
with receipt.open('w') as out:json.dump(result,out);out.flush();os.fsync(out.fileno())
except Exception:pass
return 1
if __name__=='__main__':raise SystemExit(main())