Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions .github/workflows/registry-boundary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,43 @@
make install
- name: Add Idris to PATH
run: echo "$HOME/.idris2/bin" >> "$GITHUB_PATH"
- name: Total proofs, all tag/registry combinations and rejecting mutant
run: bash scripts/check-registry.sh
- name: Provision pinned Zig for the actual C ABI caller
run: |
set -euo pipefail
cd "$RUNNER_TEMP"
curl --proto '=https' --proto-redir '=https' --connect-timeout 20 --max-time 120 -fL https://zigmirror.hryx.net/zig/zig-x86_64-linux-0.15.2.tar.xz -o zig.tar.xz || \
curl --proto '=https' --proto-redir '=https' --connect-timeout 20 --max-time 120 -fL https://zig.linus.dev/zig/zig-x86_64-linux-0.15.2.tar.xz -o zig.tar.xz || \
curl --proto '=https' --proto-redir '=https' --connect-timeout 20 --max-time 120 -fL https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz -o zig.tar.xz

Check warning on line 52 in .github/workflows/registry-boundary.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of using the literal '=https' 6 times.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaIPDQObgLu7cM3HrJfA&open=AaIPDQObgLu7cM3HrJfA&pullRequest=20
echo '02aa270f183da276e5b5920b1dac44a63f1a49e55050ebde3aecc9eb82f93239 zig.tar.xz' | sha256sum -c -
tar -xf zig.tar.xz
echo "$RUNNER_TEMP/zig-x86_64-linux-0.15.2" >> "$GITHUB_PATH"
- name: Total proofs and actual C ABI differential execution
run: |
set -euo pipefail
# An inherited producer override must not select an old oracle.
EVIDENCE_DIR="$RUNNER_TEMP/unused-oracle" bash scripts/check-runtime-registry.sh
test ! -e "$RUNNER_TEMP/unused-oracle"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
if: always()
with:
name: registry-boundary-evidence
path: build/registry-evidence/
path: |
build/registry-evidence/
build/runtime-registry-evidence/
if-no-files-found: error

gate:
name: CI/gate
needs: [registry]
if: always()
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Require completed registry boundary evidence
env:
REGISTRY_RESULT: ${{ needs.registry.result }}
run: |
if [ "$REGISTRY_RESULT" != success ]; then
echo "::error::Registry boundary did not pass: $REGISTRY_RESULT"
exit 1
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,4 @@ verification/proofs/agda/*.agdai

# Local registry gate evidence; CI uploads it as an artifact.
/build/registry-evidence/
/build/runtime-registry-evidence/
51 changes: 29 additions & 22 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,29 @@ image:https://img.shields.io/badge/Zig-Zero--overhead-F7A41D?logo=zig&logoColor=
image:https://api.thegreenwebfoundation.org/greencheckimage/github.com[Green Web,link="https://www.thegreenwebfoundation.org/green-web-check/?url=github.com"]


One C ABI for every estate service protocol. A caller links this library and
picks a transport by protocol tag, instead of each service re-rolling its own
HTTP or MCP client.
An Idris2-defined ABI with pure Zig FFI and API implementations for estate
service protocols. The current shared library dispatches synchronous calls to
caller-supplied REST and MCP callbacks through C-compatible declarations.

[IMPORTANT]
====
*Status: minted, no adapter code yet.* This repository was initialised from
`rsr-template-repo` on 2026-11-05. The adapter itself lands in the pull requests
that follow, in the order given under <<plan>>. Nothing below is a claim that the
code exists until those land.
*Status: experimental callback registry implemented.* The Zig shared library
supports registration, calls, unregistration and destruction, with explicit
refusals for unsupported tags and invalid state. Hosted checks compare 1,024
runtime cases with a fresh Idris2 oracle and exercise lifetime/reentrancy
contracts. Built-in HTTP/MCP clients and complete source-to-boundary refinement
remain open. See <<plan>> for the distinction between current and planned work.
====

== What this is

Two things already exist in the estate and are joined here:
This adapter connects two parts of the estate; connector-pool integration is
still planned:

* the *protocol taxonomy* from `boj-server` (`Boj.Protocol`): nine wire
protocols (MCP, LSP, DAP, BSP, NeSy, Agentic, Fleet, gRPC, REST) with an
Idris2-proven tag encoding (mirrored in Zig and seam-tested in `boj-server`;
here the Idris2 side exists and the Zig side is still to come);
here both the Idris2 model and Zig runtime classifier exist);
* the *HTTP connector pool* from `developer-ecosystem/zig-api`
(`connector.zig`, `uapi_connector_*`), the only one of those protocols with a
working client today.
Expand All @@ -51,9 +54,10 @@ In `boj-server` the taxonomy is a column of the cartridge catalogue: it records
which protocols a cartridge exposes, and nothing routes a call by it. This
adapter makes it a dispatch table.

The design rule: *every protocol the ABI names either works or refuses.* A
call on a protocol with no transport returns `UAPI_ERR_UNSUPPORTED`. It is
never silently accepted.
The design rule: *every protocol the ABI names either works or refuses.* The
current registry supports caller-supplied REST/MCP handlers; other known tags
refuse. See the installed `uaa_registry.h` for operation-specific status values.
A successful callback does not establish remote delivery.

[[plan]]
== Layers and plan
Expand All @@ -68,14 +72,14 @@ never silently accepted.
| `boj-server` `Boj.Protocol`, `zig-api` `ZigApi.ABI.Connector`

| Zig runtime (`src/interface/ffi/`)
| Transport table indexed by protocol tag. REST: the `zig-api` connector,
moved, not rewritten. MCP: a new JSON-RPC client over HTTP and stdio. The
other seven protocols are declared and refuse.
| Implemented: synchronous borrowed callback registry for REST/MCP; other tags
refuse. Planned: integrate the REST connector and add MCP HTTP/stdio clients.
| `zig-api` `connector.zig`, `core.zig`; MCP is new

| C header (`src/interface/generated/abi/`)
| Generated from the Idris2 ABI; never edited by hand
| —
| Foreign declarations (`src/interface/ffi/include/uaa_registry.h`)
| Implemented C-compatible declarations for the Zig runtime. Full mechanical
generation and correspondence with Idris2 remain proof obligations.
| Idris2 ABI contracts; Zig implementation
|===

Once the adapter is published, `developer-ecosystem/zig-api` and `boj-server`
Expand All @@ -87,10 +91,13 @@ Proof obligations follow the estate proof policy
(`standards/3-practice/PROOF-POLICY.adoc`): Idris2 for the ABI, Kani for the
`unsafe` and FFI seams of Rust callers.

*Proofs:* 10 proven of 15; 4 open, 1 argued, all named in
link:docs/EXPLAINME.adoc#proof-ledger[the proof ledger]. Proven means proven
for the Idris2 model; the Zig runtime and the C boundary are open rows, and
agreement with `boj-server`'s taxonomy is argued.
*Proof scope:* see link:docs/EXPLAINME.adoc#proof-ledger[the proof ledger].
Idris2 model proofs, exhaustive native checks and Atoma's closed scalar source
interpretation are distinct evidence. The scalar classifier is checked over
all 256 byte tags against the Idris2 decoder; compiler refinement, pointer
provenance and the stateful callback boundary remain open. Consumers must
serialize access, retain borrowed callback/context lifetimes and destroy each
live handle exactly once.

== Where to go next

Expand Down
53 changes: 53 additions & 0 deletions docs/decisions/2026-11-16-runtime-registry.adoc
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.
8 changes: 6 additions & 2 deletions docs/status/ROADMAP.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ Initial development phase. The finite decoder and partial registration model
now have total Idris proofs and an executable RefC matrix covering all 256 tags
and four registration states. See
link:../decisions/2026-11-16-registration-boundary.adoc[registration boundary]
for the evidence and limits. Actual Zig registration and transport invocation
remain pending; planned REST/MCP routes do not establish availability.
for the evidence and limits. The follow-up
link:../decisions/2026-11-16-runtime-registry.adoc[runtime registry] adds a real
Zig shared library and C caller with a 1,024-row Idris differential gate.
Comment thread
hyperpolymath marked this conversation as resolved.
Resolved
Its current PR must pass hosted CI before qualification. The required
`CI/gate` depends on the registry job and fails on failure, cancellation or skip. Built-in REST/MCP
network transports and source/compiler refinement remain pending.

== Milestones

Expand Down
17 changes: 16 additions & 1 deletion scripts/check-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,34 @@
cp "$root/src/interface/Abi/$module.idr" "$work/Abi/"
done
cp "$root/src/interface/RegistryCheck.idr" "$work/"
(cd "$work"; sha256sum Abi/*.idr RegistryCheck.idr) > "$evidence/inputs.sha256"
cp "$root/src/interface/ProtocolTagOracle.idr" "$work/Main.idr"
(cd "$work"; sha256sum Abi/*.idr RegistryCheck.idr Main.idr) > "$evidence/inputs.sha256"
(cd "$work"; "$idris" --total -Werror --codegen refc -o registry-check RegistryCheck.idr) > "$evidence/build.log" 2>&1
if grep -q '^Error:' "$evidence/build.log"; then cat "$evidence/build.log" >&2; exit 1; fi
test -x "$work/build/exec/registry-check"
(cd "$work"; printf ':m\n:q\n' | "$idris" --no-banner RegistryCheck.idr) > "$evidence/holes.log" 2>&1
grep -q 'No holes' "$evidence/holes.log"
if grep -q '^Error:' "$evidence/holes.log"; then cat "$evidence/holes.log" >&2; exit 1; fi
"$work/build/exec/registry-check" | tee "$evidence/registry.log"
grep '^case,' "$evidence/registry.log" > "$evidence/idris-oracle.csv"
test "$(wc -l < "$evidence/idris-oracle.csv")" -eq 1024

Check failure on line 29 in scripts/check-registry.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of 'test' command for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaHkJgsTY9sVxsanCGXR&open=AaHkJgsTY9sVxsanCGXR&pullRequest=20

# The scalar oracle consumes the authoritative decoder in the same fresh profile.
(cd "$work"; "$idris" --total -Werror --codegen refc -o tag-oracle Main.idr) > "$evidence/tag-build.log" 2>&1
if grep -q '^Error:' "$evidence/tag-build.log"; then cat "$evidence/tag-build.log" >&2; exit 1; fi
test -x "$work/build/exec/tag-oracle"

Check failure on line 34 in scripts/check-registry.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of 'test' command for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaIPV0qbG91SZQG43M4l&open=AaIPV0qbG91SZQG43M4l&pullRequest=20
(cd "$work"; printf ':m\n:q\n' | "$idris" --no-banner Main.idr) > "$evidence/tag-holes.log" 2>&1
grep -q 'No holes' "$evidence/tag-holes.log"
if grep -q '^Error:' "$evidence/tag-holes.log"; then cat "$evidence/tag-holes.log" >&2; exit 1; fi
"$work/build/exec/tag-oracle" > "$evidence/tag-oracle.tsv"
awk 'NF != 2 || $1 != NR-1 || $2 != (NR >= 2 && NR <= 10 ? 1 : 0) {exit 1}
END {if (NR != 256) exit 1}' "$evidence/tag-oracle.tsv"

# Mutate the actual decoder: unknown values must not turn into REST.
sed -i 's/)))))))))) = Nothing/)))))))))) = Just REST/' "$work/Abi/ProtocolFinite.idr"
if (cd "$work"; "$idris" --total -Werror --check Abi/ProtocolFinite.idr) > "$evidence/reject.log" 2>&1; then
# Idris versions that report errors with exit zero still fail this gate.
grep -q '^Error:' "$evidence/reject.log" || { echo 'FAIL: reverse-decoding proof accepted mutant' >&2; exit 1; }

Check warning on line 46 in scripts/check-registry.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of using the literal '^Error:' 5 times.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaIPV0qbG91SZQG43M4k&open=AaIPV0qbG91SZQG43M4k&pullRequest=20
fi
grep -q 'finiteDecodeSound' "$evidence/reject.log"
{
Expand All @@ -38,3 +52,4 @@
} > "$evidence/identity.log"
echo PASS > "$evidence/result.txt"
printf 'PASS: total proof modules, no holes, executable matrix, rejecting decoder mutation.\nEvidence: %s\n' "$evidence"

50 changes: 50 additions & 0 deletions scripts/check-runtime-registry.sh
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"
Comment thread
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of 'test' command for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaHkJgoWY9sVxsanCGXP&open=AaHkJgoWY9sVxsanCGXP&pullRequest=20
# 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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of 'test' command for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaHkO2A_Je4en-py6oPO&open=AaHkO2A_Je4en-py6oPO&pullRequest=20
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_unified-api-adapter&issues=AaHkJgoWY9sVxsanCGXQ&open=AaHkJgoWY9sVxsanCGXQ&pullRequest=20
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'

21 changes: 21 additions & 0 deletions src/interface/ProtocolTagOracle.idr
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
14 changes: 13 additions & 1 deletion src/interface/RegistryCheck.idr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Abi.ProtocolFinite
import Abi.Registry
import Abi.Status
import System
import Data.List
import Data.String

%default total

Expand All @@ -28,7 +30,17 @@ check rest mcp n =
in observe (dispatchTag r tag) == expected rest mcp n &&
map protocolTag (protocolFromWire tag) == map protocolTag (protocolFromTag tag)

row : Bool -> Bool -> Nat -> String
row rest mcp n =
let r = MkRegistry (if rest then Just 9 else Nothing)
(if mcp then Just 1 else Nothing)
(status, endpoint) = observe (dispatchTag r (cast n))
mask : Nat = (if rest then 1 else 0) + (if mcp then 2 else 0)
in "case," ++ show mask ++ "," ++ show n ++ "," ++ show status ++ "," ++ show endpoint

main : IO ()
main = if all (\rest => all (\mcp => all (check rest mcp) [0..255]) [False, True]) [False, True]
then putStrLn "PASS: all 256 tags x four registration states; original decoder agrees"
then do
putStr (unlines (concatMap (\rest => concatMap (\mcp => map (row rest mcp) [0..255]) [False, True]) [False, True]))
putStrLn "PASS: all 256 tags x four registration states; original decoder agrees"
else die "FAIL: registry, status or primitive decoder disagreement"
13 changes: 13 additions & 0 deletions src/interface/ffi/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const registry = b.addLibrary(.{
.name = "uaa_registry",
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("src/registry.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
b.installArtifact(registry);
b.installFile("include/uaa_registry.h", "include/uaa_registry.h");

const test_step = b.step("test", "Run the FFI unit and integration tests");
for ([_][]const u8{ "src/main.zig", "test/integration_test.zig" }) |path| {
const t = b.addTest(.{
Expand Down
Loading
Loading