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 / src / omega_evidence.h

146 lines · 6550 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
17/*
18 * omega_evidence.h -- immutable run-evidence plumbing shared by every gate suite.
19 *
20 * Problem this closes: gate suites used to fopen() straight into the
21 * committed evidence/ tree, silently rewriting evidence that had already
22 * been reviewed and merged, and receipts asserted literal pass counts
23 * instead of reporting what actually ran. This header gives every gate
24 * suite:
25 *
26 * (a) omega_evidence_path() -- a namespaced, run-scoped output path
27 * that never collides with (or overwrites) a legacy evidence/ file.
28 * (b) accessor functions for every suite's gate counters, plus callable
29 * entry points for the M4..M15 suites (previously inlined in
30 * tools/omegatool.c) so a regression gate can actually execute them
31 * and sum real counts instead of asserting a literal.
32 * (c) git commit identity (run_commit / tree_dirty) so a receipt cannot
33 * misrepresent the commit it ran on as "the qualified candidate".
34 * (d) observed hardware identity (compute_class / sm_version / uuid)
35 * read from a live Nvrm handle instead of a hard-coded "sm_121".
36 */
37#ifndef OMEGA_EVIDENCE_H
38#define OMEGA_EVIDENCE_H
39
40#include <stddef.h>
41#include <stdbool.h>
42#include <stdio.h>
43#include "nvrm.h"
44
45/* ---- (a) run-scoped, non-clobbering evidence paths -------------------- */
46
47/*
48 * Resolve `relpath` to a run-scoped output path and create any parent
49 * directories needed to write it.
50 *
51 * - Default: "build/qual-runs/<run_id>/<relpath>".
52 * - Even when OMEGA_QUAL_RECORD=1, intermediate gate output remains under
53 * build/qual-runs. Only tools/m19r_qualify.sh writes permanent evidence,
54 * after all gates finish, using an exclusive content-addressed file.
55 * - This function never returns a legacy "evidence/<relpath>" path
56 * (i.e. never a path that collides with a previously committed,
57 * reviewed evidence file).
58 *
59 * `run_id` is computed once per process as UTC yyyymmddThhmmssZ + "-" +
60 * the short HEAD sha, and is stable for the lifetime of the process.
61 *
62 * Returns 0 on success (out/n filled with a NUL-terminated path), -1 on
63 * failure or refusal.
64 */
65int omega_evidence_path(const char *relpath, char *out, size_t n);
66
67/*
68 * Write a finished receipt under its content address:
69 * "build/qual-runs/<run_id>/<relstem>.<sha256 of buf>.<ext>". The file is
70 * created with O_EXCL and mode 0444, so it is never rewritten; the same
71 * bytes always get the same name, other bytes always get another name.
72 * Returns 0 when written, 1 when that exact content is already recorded
73 * (left untouched), -1 on failure. `out` gets the path in both first cases.
74 */
75int omega_evidence_write_digest(const char *relstem, const char *ext, const void *buf,
76 size_t len, char *out, size_t n);
77
78/*
79 * Open `path` (from omega_evidence_path) for writing, created or truncated
80 * with mode 0644 (not fopen's 0666 & ~umask): a receipt is never
81 * world-writable. NULL on failure.
82 */
83FILE *omega_evidence_create(const char *path);
84
85/* The run_id used by omega_evidence_path(), computed lazily on first use. */
86const char *omega_evidence_run_id(void);
87
88/* ---- (c) commit identity ------------------------------------------------ */
89
90/* HEAD sha of the working tree the current process is running from. */
91bool omega_evidence_run_commit(char out[41]);
92
93/* True if the full relevant git tree (including untracked files) is dirty. */
94bool omega_evidence_tree_dirty(void);
95
96/* Path of the omegatool that is running the gates, for receipt digests and manifests:
97 * "$OUT_DIR/omegatool" (tests/gates/run.sh builds each step into build/step-<step>/,
98 * omega#511; a clean clone builds with OUT_DIR=build), "build/omegatool" when OUT_DIR
99 * is unset, else the kernel's record of the running executable (/proc/self/exe).
100 * The file name is taken from /proc/self/exe, never spelled in the code: this file is
101 * linked into production binaries and R16-G3 refuses legacy program names in them.
102 * Returns false when no readable file is found. */
103bool omega_evidence_self_binary(char *out, size_t n);
104
105/* Reads physics.lock at the repo root; trims whitespace/newline. Returns
106 * false if the file cannot be read. */
107bool omega_evidence_physics_commit(char *out, size_t n);
108
109/* ---- (d) observed hardware identity ------------------------------------- */
110
111typedef struct {
112 unsigned compute_class; /* raw Nvrm.compute_class */
113 unsigned rm_sm_version; /* raw Nvrm.sm_version */
114 char gpu_uuid_hex[33]; /* Nvrm.gpu_uuid[16], hex-encoded */
115 const char *alias; /* human alias only, e.g. "sm_121" -- never the bound identity */
116} OmegaEvidenceHardware;
117
118void omega_evidence_hardware_from_nvrm(const Nvrm *rm, OmegaEvidenceHardware *out);
119
120/* ---- (b) per-suite gate counters & callable suite entry points --------- */
121
122/* M4..M15 used to be inlined directly in tools/omegatool.c's main(). They
123 * are now callable functions so a regression gate can invoke them and read
124 * back how many gates each suite actually ran/passed. All twelve share one
125 * counter pair internally (matching the previous inlined behavior); read
126 * the snapshot immediately after each call, before invoking the next. */
127int omega_run_m4_gates(void);
128int omega_run_m5_gates(void);
129int omega_run_m6_gates(void);
130int omega_run_m7_gates(void);
131int omega_run_m8_gates(void);
132int omega_run_m9_gates(void);
133int omega_run_m10_gates(void);
134int omega_run_m11_gates(void);
135int omega_run_m12_gates(void);
136int omega_run_m13_gates(void);
137int omega_run_m14_gates(void);
138int omega_run_m15_gates(void);
139void omega_get_gate_snapshot(int *count, int *passed);
140
141/* M17/M18/M19 already track their own static counters; these expose them. */
142void omega_get_m17_gate_snapshot(int *count, int *passed);
143void omega_get_m18_gate_snapshot(int *count, int *passed);
144void omega_get_m19_gate_snapshot(int *count, int *passed);
145
146#endif /* OMEGA_EVIDENCE_H */