interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / calibration / scripts / tc_void_lib.sh

110 lines · 4303 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0
2# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Turing calibration (EXP-001): the one VOID counter, shared by sealed generation, the frozen-tree tests and
17# the evaluator (FAILURE_REPORTING.md section 2; CAL-0 review 2 Q1). Sourced by generate_sealed_data.sh and
18# record_void.sh; turing-cal-eval implements the same rule in C (refuse_c).
19#
20# The counter is the number of void_receipt_<n>.json files in
21# $TC_EVAL_ROOT/<C_f>/run/bundle (TC_EVAL_ROOT default ~/aien-data/turing-cal/eval)
22# the directory the sealed evaluation writes its bundle to (BLINDING_PROTOCOL.md step 8). A void receipt takes the
23# first free n (exclusive create, never overwritten). The receipt with n >= 3 also writes final_receipt.json
24# (kind inconclusive_infra, verdict INCONCLUSIVE, reason INFRA): EXP-001 ends there. Nothing may start once
25# final_receipt.json exists or three void receipts exist.
26
27TC_EVAL_ROOT="${TC_EVAL_ROOT:-$HOME/aien-data/turing-cal/eval}"
28TC_MAX_ATTEMPTS=3
29
30tc_void_dir() { printf '%s/%s/run/bundle\n' "$TC_EVAL_ROOT" "$1"; }
31
32# tc_void_count DIR: number of void receipts (1, 2, ... without gaps).
33tc_void_count() {
34 local n=0
35 while [ -e "$1/void_receipt_$((n + 1)).json" ]; do n=$((n + 1)); done
36 echo "$n"
37}
38
39# tc_void_ended DIR: true when EXP-001 has ended (a final receipt exists or the attempts are used up).
40# (the experiment named in receipts is $EXP_ID, default EXP-001)
41tc_void_ended() { [ -e "$1/final_receipt.json" ] || [ "$(tc_void_count "$1")" -ge "$TC_MAX_ATTEMPTS" ]; }
42
43# JSON-safe text: quote, backslash and control characters become an apostrophe (as in turing-cal-eval).
44tc_jclean() { printf '%s' "$1" | tr '"\\\000-\037' "'"; }
45
46# tc_void_write C_F STAGE STEP CODE REASON COMMAND INPUTS PROFILE_DIGEST CANDIDATE_MANIFEST_SHA256
47# Writes the next void receipt; prints its number. Writes the INCONCLUSIVE (INFRA) final receipt on the third.
48tc_void_write() {
49 local cf="$1" stage="$2" step="$3" code="$4" reason command inputs pd="$8" cm="$9" dir n t f
50 reason="$(tc_jclean "$5")" command="$(tc_jclean "$6")" inputs="$(tc_jclean "$7")"
51 dir="$(tc_void_dir "$cf")"
52 mkdir -p "$dir"
53 t="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
54 n=1
55 while :; do
56 f="$dir/void_receipt_$n.json"
57 if (set -C; : >"$f") 2>/dev/null; then break; fi
58 n=$((n + 1))
59 [ "$n" -lt 1000 ] || return 1
60 done
61 cat >>"$f" <<EOF
62{
63 "schema": "turing.cal.void_receipt.v1",
64 "experiment": "${EXP_ID:-EXP-001}",
65 "kind": "void",
66 "stage": "$stage",
67 "dry_run": false,
68 "created_utc": "$t",
69 "attempt": $n,
70 "step": "$step",
71 "code": "$code",
72 "reason": "$reason",
73 "command": "$command",
74 "inputs": "$inputs",
75 "profile_digest": "$pd",
76 "freeze_commit": "$cf",
77 "candidate_manifest_sha256": "$cm"
78}
79EOF
80 if [ "$n" -ge "$TC_MAX_ATTEMPTS" ] && (set -C; : >"$dir/final_receipt.json") 2>/dev/null; then
81 cat >>"$dir/final_receipt.json" <<EOF
82{
83 "schema": "turing.cal.terminal_receipt.v1",
84 "experiment": "${EXP_ID:-EXP-001}",
85 "kind": "inconclusive_infra",
86 "dry_run": false,
87 "created_utc": "$t",
88 "verdict": "INCONCLUSIVE",
89 "reason": "INFRA",
90 "void_attempts": $n,
91 "last_step": "$step",
92 "last_code": "$code",
93 "profile_digest": "$pd",
94 "freeze_commit": "$cf",
95 "candidate_manifest_sha256": "$cm",
96 "EXP_001_COMPRESSION_BRIDGE": "INCONCLUSIVE"
97}
98EOF
99 fi
100 echo "$n"
101}
102
103# tc_void_first_command DIR STAGE: the command of the first void receipt of STAGE (empty if none).
104tc_void_first_command() {
105 local k=1 f
106 while f="$1/void_receipt_$k.json" && [ -e "$f" ]; do
107 if grep -q "^ \"stage\": \"$2\",\$" "$f"; then sed -n 's/^ "command": "\(.*\)",$/\1/p' "$f"; return 0; fi
108 k=$((k + 1))
109 done
110}