informed-decision/docs/evidence/2026-10-11-zlib-image-release/post-ready-native-outcomes-command.py
tegwick 312ab97e87 Prepare owner-reviewed zlib-only native release decision
Assistant: codex
Assistant-Model: gpt-6.1-sol
Assistant-Session: 01a126e1-76f8-7643-8cf3-e93336539ade
2026-10-11 12:37:05 +02:00

56 lines
2.8 KiB
Python

"""Fixed admitted StateHub-Pod source1 readback after verified candidate Ready.
Request identity is derived solely from the fixed authenticated route. Actual
native outcomes returns review/dispositions, without top-level source identity.
Only HTTP200, timestamp, shape and counts leave this command. No review,
disposition, actor, submission state, private body or approval inference leaves.
"""
import datetime
import json
import urllib.request
import urllib.error
MEMO_ID='infd-20261011-zlib-remediation-r1'
VERSION=1
def require(value):
if not value:
raise ValueError('invalid bounded native outcomes shape')
def safe_outcome_metadata(value):
require(isinstance(value,dict))
# Optional body identity is checked only if actually present, never invented.
if 'memo_id' in value:
require(value['memo_id']==MEMO_ID)
for key in ('version','memo_version'):
if key in value:
require(type(value[key]) is int and value[key]==VERSION)
require('review' in value and (value['review'] is None or isinstance(value['review'],dict)))
rows=value.get('dispositions')
require(isinstance(rows,list) and len(rows)<=1024 and all(isinstance(row,dict) for row in rows))
return {'request_memo_id':MEMO_ID,'request_memo_version':VERSION,'request_identity_source':'fixed-authenticated-route','has_review':value['review'] is not None,'disposition_count':len(rows),'dispositions_interpreted':False,'approval_inferred':False,'current_approval_claimed':False}
def main():
try:
from api.services.memo_dispatch import ORIGIN,NoRedirect,token_file
request=urllib.request.Request(ORIGIN+'/v1/decisions/'+MEMO_ID+'/outcomes?version=1',headers={'Authorization':'Bearer '+token_file('/var/run/secrets/state-hub/informed-decision/lifecycle-token')})
opener=urllib.request.build_opener(urllib.request.ProxyHandler({}),NoRedirect())
with opener.open(request,timeout=15) as response:
require(response.status==200)
raw=response.read(1048577);require(len(raw)<=1048576)
result=safe_outcome_metadata(json.loads(raw))
result.update(http_status=200,observed_at=datetime.datetime.now(datetime.timezone.utc).isoformat(),native_authenticated_canonical_lifecycle_outcomes=True,native_provider_path_returned=True,credential_material_output=False)
print(json.dumps(result))
except Exception as error:
result={'request_memo_id':MEMO_ID,'request_memo_version':VERSION,'request_identity_source':'fixed-authenticated-route','status':'unverified','failure':'native_readback_unavailable_or_invalid'}
if isinstance(error,urllib.error.HTTPError) and type(error.code) is int and 100<=error.code<=599:
result['http_status']=error.code
print(json.dumps(result))
raise SystemExit(1) from None
if __name__=='__main__':
main()