Repository navigation
Add real C ABI registration and compare dispatch with the Idris model #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6dea5f0
6cf6d12
d8b0424
88d7040
6fecbe0
788ab14
d5c047a
730d0c7
dc3d57d
a77bf4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // SPDX-License-Identifier: CC-BY-SA-4.0 | ||
| // Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> | ||
| = Runtime registration boundary | ||
|
|
||
| The first executable registry exposes an opaque C handle, registration, | ||
| unregistration and synchronous invocation. Only REST (9) and MCP (1) have | ||
| slots. Other named protocols return Unsupported (11); unknown tags return | ||
| InvalidParam (2). Duplicate registration refuses without replacing the original | ||
| endpoint. A callback's return value is propagated only if it is a named status. | ||
| An unknown callback status becomes ProcessFailed (6). | ||
|
|
||
| This is a registry of caller-supplied handlers. No built-in REST or MCP network | ||
| transport is available yet. Callback success is its report, not evidence of | ||
| delivery. The older template functions are separate and do not implement this | ||
| contract. Build the production library and header with `zig build` in | ||
| `src/interface/ffi` using Zig 0.15.2. | ||
|
|
||
| == Ownership and lifetime | ||
|
|
||
| The owner serializes every operation on a handle, holds callback code and its | ||
| context alive until unregister/destroy, supplies a readable input region for | ||
| the entire call, and destroys the handle exactly once. Input is never retained. | ||
| Null input is accepted only at length zero. Reentrant calls, mutation and | ||
| destruction during a callback refuse; no registry pointer is exposed to the | ||
| callback unless its owner deliberately supplies one in the context. | ||
|
|
||
| The runtime does not prove arbitrary foreign-pointer validity, concurrent | ||
| access safety, callback termination or recovery from a callback that unwinds | ||
| across the C ABI. These are explicit preconditions and future qualification | ||
| work, not properties inferred from the finite decoder proof. | ||
|
|
||
| == Evidence and source-to-proof obligations | ||
|
|
||
| The hosted registry workflow compiles the actual Idris model with RefC and | ||
| compares its 1,024 observations with a separately compiled C caller linked to | ||
| the actual Zig shared library. Observations include both status and endpoint | ||
| identity, so selecting the wrong registered slot cannot pass by returning zero. | ||
| The caller also exercises duplicate registration, unregister/re-register, | ||
| raw bytes, null spans, callback failure, invalid callback status and reentrancy. | ||
| An unknown-tag mutation must compile and then fail the executable check. | ||
|
|
||
| The evidence directory records source identities and both matrices. A passing | ||
| matrix is finite differential execution, not an Atoma source-refinement proof. | ||
| The Idris registration theorem applies to its model. Still required: source | ||
| binding for Zig dispatch, preservation under registry updates, region/lifetime | ||
| semantics, and a transport-specific implementation/proof contract. Extend the | ||
| Agda-compatible boundary first; independently replay supported witness claims | ||
| in Lean and Rocq before qualifying the stronger Cubical profile. | ||
|
|
||
| Next: a real REST handler with bounded response storage and explicit timeout, | ||
| connection and HTTP failure outcomes, exercised against a local test server in | ||
| remote CI. MCP follows with its own framing/session obligations. Neither route | ||
| may report availability merely because its protocol has a name. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> | ||
| set -euo pipefail | ||
| unset CDPATH | ||
| root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | ||
| evidence="$root/build/runtime-registry-evidence" | ||
|
hyperpolymath marked this conversation as resolved.
Resolved
|
||
| mkdir -p "$evidence" | ||
| echo INCOMPLETE > "$evidence/result.txt" | ||
| work=$(mktemp -d -t uaa-runtime-registry.XXXXXXXX) | ||
| trap 'status=$?; rm -rf -- "$work"; if ((status)); then echo FAIL > "$evidence/result.txt"; fi' EXIT | ||
| zig=$(command -v "${ZIG:-zig}") | ||
| zig=$(cd "$(dirname "$zig")" && pwd)/$(basename "$zig") | ||
| test "$("$zig" version)" = 0.15.2 | ||
|
Check failure on line 14 in scripts/check-runtime-registry.sh
|
||
| # Rebuild and consume the oracle in the same private directory. An inherited | ||
| # EVIDENCE_DIR or a stale default oracle must not change the inputs to this run. | ||
| EVIDENCE_DIR="$work/idris-evidence" bash "$root/scripts/check-registry.sh" > "$evidence/idris.log" 2>&1 | ||
| test "$(cat "$work/idris-evidence/result.txt")" = PASS | ||
|
Check failure on line 18 in scripts/check-runtime-registry.sh
|
||
| cp "$work/idris-evidence/idris-oracle.csv" "$work/oracle.csv" | ||
| cp -R "$work/idris-evidence" "$evidence/" | ||
| mkdir -p "$work/src" "$work/include" "$work/test" | ||
| cp "$root/src/interface/ffi/build.zig" "$work/" | ||
| cp "$root/src/interface/ffi/src/registry.zig" "$work/src/" | ||
| cp "$root/src/interface/ffi/src/protocol_tag.zig" "$work/src/" | ||
| cp "$root/src/interface/ffi/src/main.zig" "$work/src/" | ||
| cp "$root/src/interface/ffi/include/uaa_registry.h" "$work/include/" | ||
| cp "$root/src/interface/ffi/test/registry_caller.c" "$work/test/" | ||
| cp "$root/src/interface/ffi/test/integration_test.zig" "$work/test/" | ||
| (cd "$work"; sha256sum build.zig src/*.zig include/*.h test/* oracle.csv) > "$evidence/inputs.sha256" | ||
| "$zig" version > "$evidence/zig-version.txt" | ||
| build() { | ||
| (cd "$work"; "$zig" build -Doptimize=ReleaseSafe) | ||
| "$zig" cc -Wall -Wextra -Werror -I "$work/zig-out/include" "$work/test/registry_caller.c" \ | ||
| -L "$work/zig-out/lib" -luaa_registry -Wl,-rpath,"$work/zig-out/lib" -o "$work/caller" | ||
| } | ||
| build > "$evidence/build.log" 2>&1 | ||
| "$work/caller" > "$evidence/actual.csv" | ||
| cmp "$work/oracle.csv" "$evidence/actual.csv" | ||
| cp "$work/oracle.csv" "$evidence/expected.csv" | ||
| # An actual Zig decoder mutation must compile and be rejected at execution. | ||
| sed -i 's/if (!known(tag)) return 2;/if (!known(tag)) return 11;/' "$work/src/registry.zig" | ||
| build > "$evidence/mutant-build.log" 2>&1 | ||
| if "$work/caller" > "$evidence/mutant.csv" 2> "$evidence/mutant.log"; then | ||
| if cmp -s "$work/oracle.csv" "$evidence/mutant.csv"; then | ||
|
Check warning on line 44 in scripts/check-runtime-registry.sh
|
||
| echo 'FAIL: unknown-tag mutation escaped the oracle' >&2; exit 1 | ||
| fi | ||
| fi | ||
| echo PASS > "$evidence/result.txt" | ||
| echo 'PASS: real C ABI, Idris differential matrix, lifetime/refusal regressions and rejecting Zig mutant' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- SPDX-License-Identifier: MPL-2.0 | ||
| -- Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> | ||
| module Main | ||
| import Abi.Protocol | ||
| import Abi.ProtocolFinite | ||
| import Data.Fin | ||
| %default total | ||
|
|
||
| present : Bits8 -> Nat | ||
| present tag = case protocolFromWire tag of | ||
| Nothing => 0 | ||
| Just _ => 1 | ||
|
|
||
| rows : Nat -> Nat -> IO () | ||
| rows Z index = pure () | ||
| rows (S fuel) index = do | ||
| putStrLn (show index ++ " " ++ show (present (cast index))) | ||
| rows fuel (S index) | ||
|
|
||
| main : IO () | ||
| main = rows 256 0 |
Uh oh!
There was an error while loading. Please reload this page.