Files
Pavlo Ratushnyi 1e0d11df1c
ci / build, test, smoke (push) Failing after 3m33s
ci / the same smoke on an image with no base (push) Successful in 8m10s
ci / lint the workflow and the shell (push) Failing after 19s
ci / the operator page in a real browser (push) Successful in 4m41s
ci / build the image and smoke it (push) Failing after 8m11s
the first query moves off ef, and the aot edge reads its own policy from the database
Wall 3 starts. Two projects, one query path, measured.

dotnet/OpenWaf.Data is the runtime: OrmContext (a DbDataSource plus an
ISqlDialect), Query<T>, RowReader, OrmMeta. It is typed over System.Data.Common
and carries no provider package; the driver is supplied at composition, which is
how the neighbouring deployment ships it too. Query<T> renders SQL by walking the
expression tree rather than compiling it — that is the exact difference from EF's
pipeline, and the reason it survives a NativeAOT link where EF does not. The
supported grammar is a closed set that refuses by name: joins, subqueries,
aggregates other than COUNT, updates, deletes, JSON columns and method calls each
raise UnsupportedQueryNodeException naming the node, because a renderer that
guesses is a renderer that ships wrong SQL.

dotnet/OpenWaf.Data.Generator is a Roslyn incremental generator attached to
OpenWaf.Infrastructure as an analyzer. For a [Table] class it emits the column
map, the row materializer and an OrmMeta.Register call inside a
[ModuleInitializer], so the question a NativeAOT binary cannot answer — what are
this type's properties — is never asked. The generated file is ordinary C#,
readable in obj/ and asserted against.

PolicySetting is the entity moved and EdgePolicyProvider.ReloadAsync the call
site, which was the first refusal in the probe log. Program.cs composes the
driver and dialect on the same Database:Provider switch EF uses, so one generated
query serves sqlite (the shipped image) and PostgreSQL (the migrations'
provider). EF still owns every write and every other read; the two layers
coexist on one composition root, which is what makes this incremental rather than
a rewrite.

Measured on the AOT binary, same probe, same window, before and after:
queries refused at run time 32 -> 18; EdgePolicyProvider reload failures 1 -> 0;
native binary 49,609,680 -> 49,676,016 bytes. The 18 that remain are named by
their own frames: 14 EdgeStateStore.RefreshAsync, 2 BlockStore.WriteBanAsync,
1 BlockStore.AddOperatorAsync, 1 admin endpoint.

The sqlite timestamp column turned out to be a contract, not a detail. The model
puts EF's DateTimeOffsetToBinaryConverter on every timestamp column, so every row
already written says (localTicks / 1000) * 2048 + (offsetMinutes & 2047); the
formula was derived by probing EF's converter and is now pinned by
SqliteTimestampEncodingTests against that converter over five instants including
+05:30, -05:00 and DateTimeOffset.MinValue — including the microsecond
truncation the /1000 imposes, which is EF's behaviour and is now a test rather
than a future surprise.

Two build traps, both paid for and both recorded where the next person will hit
them. -p:PublishAot on the command line is a global property, so it reaches every
project in the graph including a netstandard2.0 Roslyn analyzer, and the publish
dies with NETSDK1207; AOT is now switched by OpenWafAot=true, which only
OpenWaf.Edge.csproj turns into PublishAot — the same shape as the existing
OpenWafCompiledModel switch. And a raw Microsoft.Data.Sqlite data source needs
SQLitePCL.Batteries.Init() before its first open, because the order in which
EF's provider and this data source are first used is not guaranteed.

Gates on this tree: build 0 warnings, unit 391/391 (13 new: rendered SQL for both
dialects, null tests, the captured-null case, the refusals, the timestamp
encoding), integration 408/408, smoke 256/256, and the AOT probe above. One
earlier run of the 408 carried a single failure in AdminConsoleTests at a host
load average near 30 and the next run was clean; recorded rather than hidden, in
the same family as the load-sensitive compose gates this README already
documents.
2026-10-07 21:48:01 +02:00

192 lines
10 KiB
Bash
Executable File

#!/usr/bin/env bash
# What a NativeAOT edge actually does on this tree, measured rather than argued.
#
# This is not a gate. It is the reproduction of a verdict: the AOT build compiles,
# starts, and creates its own schema, and then every EF query it makes fails,
# because EF cannot compile a LINQ query at run time in a NativeAOT binary and the
# only alternative — precompiling them at build time — does not produce compilable
# code for this model. Run it when the EF version changes, before deciding again
# whether AOT is worth the price.
#
# scripts/aot-probe.sh # publish + start + curl
# scripts/aot-probe.sh --regen # regenerate the EF compiled model first
#
# Needs the NativeAOT toolchain (clang/lld) and takes a few minutes: the ILC step
# alone is over a minute. It is deliberately not in `ci-gates.sh all` — a machine
# without clang would then report a build failure as if the product were broken.
#
# The compiled model is generated for sqlite, the provider the shipped image uses,
# and is compiled into the binary only under -p:OpenWafCompiledModel=true; the
# framework-dependent build still builds its model at start-up and serves both
# providers. See dotnet/OpenWaf.Infrastructure/OpenWaf.Infrastructure.csproj.
set -uo pipefail
cd "$(dirname "$0")/.." || exit 2
RUNTIME=$(dotnet --info 2>/dev/null | sed -n 's/^ *RID: *//p' | head -1)
[ -n "$RUNTIME" ] || { printf 'cannot work out this RID from the dotnet --info output\n' >&2; exit 2; }
PUBLISH=dotnet/OpenWaf.Edge/bin/Release/net10.0/$RUNTIME/publish
BIN=$PUBLISH/OpenWaf.Edge
if [ "${1:-}" = "--regen" ]; then
printf '\n=== regenerate the EF compiled model (sqlite) ===\n'
rm -rf dotnet/OpenWaf.Infrastructure/Persistence/CompiledModel
# OPENWAF_MIGRATE_PROVIDER=sqlite: the design-time factory defaults to postgres,
# and a postgres compiled model in a sqlite image is a different kind of broken.
(cd dotnet && OPENWAF_MIGRATE_PROVIDER=sqlite dotnet ef dbcontext optimize \
--project OpenWaf.Infrastructure --startup-project OpenWaf.Infrastructure \
--context OpenWafDbContext --namespace OpenWaf.Infrastructure.Persistence.CompiledModel \
--output-dir Persistence/CompiledModel) || { printf 'compiled model generation failed\n' >&2; exit 1; }
fi
printf '\n=== publish NativeAOT (%s) ===\n' "$RUNTIME"
# IlcTreatWarningsAsErrors=false and the two NoWarn codes are what let the build
# finish at all: EF's assemblies produce IL2104/IL3053 trim warnings and the
# schema step still calls three design-time APIs. Those are recorded, not hidden —
# the counts are printed below from the same log.
AOT_LOG=/tmp/openwaf-aot-publish.log
# OpenWafAot, not PublishAot: the latter as a command-line property is global, and
# it then reaches the referenced Roslyn analyzer (netstandard2.0) and the publish
# dies with NETSDK1207. OpenWaf.Edge.csproj turns this switch into PublishAot for
# itself only.
(cd dotnet && dotnet publish OpenWaf.Edge/OpenWaf.Edge.csproj -c Release -r "$RUNTIME" \
-p:OpenWafAot=true \
-p:OpenWafCompiledModel=true -p:NoWarn=IL2026%3BIL3050 \
-p:IlcTreatWarningsAsErrors=false) >"$AOT_LOG" 2>&1
publish_status=$?
# The warning count only means something if the ILC actually ran. An up-to-date
# publish skips "Generating native code" and would otherwise report zero warnings
# for a build that produced no output at all.
generated=no
grep -q 'Generating native code' "$AOT_LOG" && generated=yes
printf 'publish exit %s; native code generated: %s; IL warnings: %s; errors: %s\n' \
"$publish_status" "$generated" "$(grep -c ' warning IL[0-9]' "$AOT_LOG")" \
"$(grep -c ' error ' "$AOT_LOG")"
[ "$publish_status" -eq 0 ] || { tail -20 "$AOT_LOG"; exit 1; }
[ -x "$BIN" ] || { printf 'no native binary at %s\n' "$BIN" >&2; exit 1; }
# Absolute, because --contentRoot is resolved against the binary's own directory
# rather than the caller's: measured, a relative one came back doubled
# (…/publish/dotnet/OpenWaf.Edge/…/publish/) and the host died in
# DirectoryNotFoundException before it could say anything useful.
PUBLISH="$(cd "$PUBLISH" && pwd)"
printf 'native binary: %s bytes\n' "$(wc -c < "$BIN" | tr -d ' ')"
EDGE_PORT=${EDGE_PORT:-18077}
UP_PORT=${UP_PORT:-18078}
DB=/tmp/openwaf-aot-probe-$$.db
LOG=/tmp/openwaf-aot-probe-edge.log
TOKEN=aot-probe-token
rm -f "$DB" "$DB-shm" "$DB-wal"
cleanup() {
[ -n "${EDGE_PID:-}" ] && kill "$EDGE_PID" 2>/dev/null
[ -n "${UP_PID:-}" ] && kill "$UP_PID" 2>/dev/null
rm -f "$DB" "$DB-shm" "$DB-wal"
}
trap cleanup EXIT
mkdir -p /tmp/openwaf-upstream && printf 'aot probe upstream\n' > /tmp/openwaf-upstream/body.txt
python3 -m http.server "$UP_PORT" --bind 127.0.0.1 -d /tmp/openwaf-upstream >/dev/null 2>&1 &
UP_PID=$!
# OPENWAF_SCHEMA=script is the point of the exercise: EnsureCreated and
# GenerateCreateScript both go through EF's design-time model, which a NativeAOT
# build refuses outright, so the DDL is generated at build time and read out of
# the binary. The schema-script gate keeps that file equal to what the model
# generates.
ASPNETCORE_URLS="http://127.0.0.1:$EDGE_PORT" \
OPENWAF_ADMIN_TOKEN="$TOKEN" \
OPENWAF_SCHEMA=script \
ConnectionStrings__OpenWaf="Data Source=$DB" \
Database__Provider=sqlite \
OpenWaf__Policy__Mode=Enforce \
OpenWaf__Policy__TrustProxyHeaders=true \
OpenWaf__Policy__StreakThreshold=3 \
ReverseProxy__Clusters__upstream__Destinations__upstream1__Address="http://127.0.0.1:$UP_PORT/" \
"$BIN" --contentRoot "$PUBLISH" >"$LOG" 2>&1 &
EDGE_PID=$!
for _ in $(seq 1 60); do
curl -fsS "http://127.0.0.1:$EDGE_PORT/healthz" >/dev/null 2>&1 && break
sleep 0.25
done
pass=0; fail=0
check() {
if [ "$2" = "$3" ]; then pass=$((pass+1)); printf ' ok %-52s %s\n' "$1" "$3"
else fail=$((fail+1)); printf ' FAIL %-52s expected %s, got %s\n' "$1" "$2" "$3"; fi
}
code() { curl -s -o /dev/null -m 5 -w '%{http_code}' "$@"; }
printf '\n=== the schema step ===\n'
tables=$(python3 -c "import sqlite3;print(len([r for r in sqlite3.connect('$DB').execute(\"select name from sqlite_master where type='table' and name != 'sqlite_sequence'\")]))" 2>/dev/null || echo 0)
check 'tables the shipped DDL created' 12 "$tables"
# Two halves, and the split is the finding, not a convenience. Measured 2026-10-07
# on this tree (osx-arm64, the same binary): the AOT edge reaches "Now listening
# on:", creates its 12 tables from the DDL it carries and proxies a request to the
# upstream for 200 — everything below in the first half passes. Every assertion in
# the second half fails, and fails with the SAME sentence 130 times in the log:
# "Query wasn't precompiled and dynamic code isn't supported with NativeAOT". They
# are recorded rather than checked because a check that fails for a reason this
# project already knows, and has a ticket for, stops being a signal; and they are
# recorded rather than deleted because the day EF compiles a query again, one of
# these answers changes and says so.
printf '\n=== the half that needs no query (gated) ===\n'
check 'healthz answers' 200 "$(code "http://127.0.0.1:$EDGE_PORT/healthz")"
check 'a request reaches the upstream' 200 "$(code "http://127.0.0.1:$EDGE_PORT/body.txt")"
HEALTHCHECK_PORT="$EDGE_PORT" "$BIN" --healthcheck >/dev/null 2>&1
check 'the healthcheck mode answers 0' 0 "$?"
# The header the edge actually reads. The probe used to send "Authorization:
# Bearer", which the admin surface does not look at, so three of these assertions
# were measuring a 401 rather than the query wall. Measured 2026-10-07: AdminAuth
# reads X-Admin-Token (or ?token=, which it names out loud).
printf '\n=== the half behind the query wall (recorded, not gated) ===\n'
recorded=0; drifted=0
record() {
if [ "$2" = "$3" ]; then
drifted=$((drifted+1)); printf ' MOVED %-50s %s — the query wall moved here, promote it back to a check\n' "$1" "$3"
else
recorded=$((recorded+1)); printf ' %-56s got %s, a working edge answers %s\n' "$1" "$3" "$2"
fi
}
record 'an operator block is accepted' 204 "$(code -X POST -H "X-Admin-Token: $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"ip":"198.51.100.7","reason":"aot probe","redirectTo":"https://honeypot.example.org/"}' \
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
record 'the blocked source is redirected' 301 "$(code -H 'X-Admin-Token: $TOKEN' -H 'X-Forwarded-For: 198.51.100.7' \
"http://127.0.0.1:$EDGE_PORT/body.txt")"
ban=""
for _ in 1 2 3 4; do ban="$ban $(code -H 'X-Forwarded-For: 203.0.113.66' "http://127.0.0.1:$EDGE_PORT/probe")"; done
record 'four probes draw the streak ban' " 403 403 403 403" "$ban"
record 'the state surface answers' 200 "$(code -H "X-Admin-Token: $TOKEN" \
"http://127.0.0.1:$EDGE_PORT/admin-api/state")"
record 'readiness answers' 200 "$(code "http://127.0.0.1:$EDGE_PORT/readyz")"
# The body, not just the code. Before ProblemDetails had a contract this endpoint
# answered 500 and said nothing; the point of registering it is that the 503
# names the failure an operator would otherwise have to find in the log.
printf ' what /readyz says about itself: %s\n' \
"$(curl -s -m 5 "http://127.0.0.1:$EDGE_PORT/readyz" | tr -d '\n\r' | head -c 220)"
printf '\npassed %s, failed %s; recorded behind the wall %s, moved %s\n' \
"$pass" "$fail" "$recorded" "$drifted"
printf '\n=== the two walls, counted from the edge log ===\n'
listening=$(grep -c 'Now listening on:' "$LOG")
json_refusals=$(grep -c 'JsonTypeInfo metadata for type' "$LOG")
queries=$(grep -c "Query wasn't precompiled and dynamic code isn't supported with NativeAOT" "$LOG")
printf ' lines where the edge started listening: %s\n' "$listening"
printf ' json metadata refusals: %s\n' "$json_refusals"
{ [ "$json_refusals" -gt 0 ] && grep -m1 -o "JsonTypeInfo metadata for type '[^']*'" "$LOG" | sed 's/^/ first type without a contract: /'; }
printf ' queries refused at run time: %s\n' "$queries"
grep -c "Application startup exception" "$LOG" | sed 's/^/ startup exceptions: /'
printf ' full log: %s\n' "$LOG"
# The API half is a claim now, so it is gated: the host must be listening, and no
# response may be refused for want of a compiled contract. Before 2026-10-06 the
# first number was 0 (the host threw before Kestrel opened a port); on 2026-10-07
# the second was 55, all of them one anonymous /healthz literal.
[ "$listening" -ge 1 ] || { printf 'the edge never listened: the API half regressed\n' >&2; exit 1; }
[ "$json_refusals" -eq 0 ] || { printf 'a response shape still has no compiled JSON contract\n' >&2; exit 1; }
[ "$fail" -eq 0 ] || exit 1