4 Commits
Author SHA1 Message Date
Pavlo Ratushnyi 1e0d11df1c the first query moves off ef, and the aot edge reads its own policy from the database
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
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
Pavlo Ratushnyi 0a2cbee558 sqlite is baked into the static link, and the AOT probe now names two walls instead of one
The probe used to report one wall: the binary died in
`Microsoft.Data.Sqlite.SqliteConnection..cctor` with `DllNotFoundException:
e_sqlite3` / `Dynamic loading not supported`. That sentence described a build that
did not link sqlite at all. Two musl-only items in `OpenWaf.Edge.csproj` close it
— `NativeLibrary` puts Alpine's `sqlite-static` `/usr/lib/libsqlite3.a` on the
link line, `DirectPInvoke` makes ILC emit a direct call to the symbol instead of a
run-time module load — and `Dockerfile.aot-probe` installs the package.

Both items are needed, and the order was measured, not guessed. With
`NativeLibrary` alone the link is still fully static (0 interpreters, 0 NEEDED) and
the binary still calls `NativeLibrary.Load("e_sqlite3")` at the first query and
NativeAOT refuses it. The pair is what the runtime pack itself uses for
`System.Native` and the OpenSSL shim (`Microsoft.NETCore.Native.Unix.targets`
140-155), so this is the SDK's mechanism rather than a fork of it.

Measured on the arm64/musl half, this host, 2026-10-06: 58,343,456-byte
`static-pie linked` binary, `readelf -l` 0 interpreters, `readelf -d` 0 NEEDED,
96.4 MB scratch image, and a log with 0 `e_sqlite3` lines that says the edge
created 12 tables from the DDL it carries. Two standalone probes with the same
link say the same thing one level down: direct P/Invoke to sqlite3 opens
`:memory:`, writes two rows and reads `2` back (sqlite 3.53.4); and
`Microsoft.Data.Sqlite` — the ADO layer this tree already uses — opens a
connection and reads `sqlite_version()` back. So the ADO layer survives and only
EF's query compilation is left standing.

The check that sqlite is inside the binary is behavioural, and had to be: the
binary is stripped and `nm` reports 0 `sqlite3_` symbols on a binary that
demonstrably runs sqlite. No tool that only reads the file can answer this.
`.github/workflows/aot-probe.yml` therefore gates four things after the link — no
interpreter, no NEEDED, no `e_sqlite3` line, and the schema line as the positive
half, because a gate that only forbids an error string also passes when the
feature is simply absent. The step was run verbatim against the real artifact
before committing (exit 0), and both failure branches were tested against a
doctored log. It also had a bug caught by that run: it read the log after a fixed
20 s sleep and reported "no schema" on a loaded host, so it now waits up to 180 s
and prints how long it waited — measured 6 s on a quiet host, past 22 s under
load, 3 s in the verification run.

What the probe reports now, which is what closing the first wall buys:

  * hosting refuses to start — `JsonTypeInfo metadata for type
    'OpenWaf.Edge.Admin.NewBlockRequest' was not provided by TypeInfoResolver`,
    3 refusals. The route handlers in the stack are already the generated ones
    (`GeneratedRouteBuilderExtensionsCore`), so the API half is not missing code
    generation; it is missing a registered JSON contract for the admin DTOs.
  * every query is refused — `Query wasn't precompiled and dynamic code isn't
    supported with NativeAOT`, 2 refusals. That is EF's precompiler, whose four
    untranslatable shapes and codegen bug `docs/ARCHITECTURE.md` already carries.

Also measured: `dotnet build OpenWaf.Edge -c Release` (non-musl) 0 warnings, unit
378/378 — the two items are conditioned on the musl RID and the shipped images do
not take this path. Not measured here: the x86-64 musl half, because the musl ILC
crashes under emulation on Apple Silicon; the weekly workflow is the only place
that number exists, and it now carries this gate.
2026-10-06 22:45:59 +02:00
Pavlo Ratushnyi cbafca491b the static-link gate asks the binary, not the build log, because a cache prints nothing
ci / lint the workflow and the shell (push) Successful in 10s
ci / the operator page in a real browser (push) Successful in 2m36s
ci / the same smoke on an image with no base (push) Successful in 4m4s
ci / build the image and smoke it (push) Successful in 4m4s
ci / build, test, smoke (push) Successful in 2m19s
Run 2503 turned a good artifact red: the publish layer was cached, the report
layer was cached with it, the build log carried no report lines, and the gate
that greps that log found nothing to match. The report is now a script
(scripts/aot-link-report.sh) that the build stage copies in and runs, and that CI
runs again with `docker run --entrypoint sh … /report.sh` — a container start is
never cached, so the gate asks the binary. It exits non-zero when the link names
an interpreter or needs a shared object, which is the one claim a scratch layer
depends on.

Verified here: the script prints `binary bytes: 56820992`, `static-pie linked`,
`program headers naming an interpreter: 0`, `NEEDED shared objects: 0`,
`static: no interpreter, no NEEDED shared object`, exit 0 — both as a build step
and as a `docker run`. .dockerignore keeps `scripts/` out of the context and now
makes one named exception for it.
2026-10-06 09:35:16 +02:00
Pavlo Ratushnyi d08ec30e0a the AOT edge links fully static and dies on sqlite, which names the wall exactly
ci / lint the workflow and the shell (push) Successful in 10s
ci / build, test, smoke (push) Failing after 2m11s
ci / the operator page in a real browser (push) Successful in 2m29s
ci / build the image and smoke it (push) Successful in 4m15s
ci / the same smoke on an image with no base (push) Successful in 4m15s
Dockerfile.aot-probe applies the packaging recipe a neighbouring .NET 10 service
already ships — musl RID, StaticExecutable, StaticOpenSslLinking, IlcSingleThreaded,
scratch plus a CA bundle — and the link claim is checked inside the build rather
than asserted in a comment. Measured here (arm64, native): `file` says
`static-pie linked`, `readelf -l` reports 0 program interpreters, `readelf -d`
reports 0 NEEDED shared objects, the binary is 56,820,992 bytes and the image is
94 MB — against 222 MB for the self-contained scratch image and 262 MB chiseled.

It does not serve, and the reason is one step earlier than the query wall:
`Microsoft.Data.Sqlite.SqliteConnection..cctor` throws `DllNotFoundException:
e_sqlite3` with `Dynamic loading not supported`, because SQLitePCLRaw resolves
sqlite by loading a shared library and a NativeAOT binary has no way to load one.
`scripts/compose-smoke.sh` against that image therefore never gets past
readiness: the container reports exited/unhealthy and every curl answers 000.
Behind that sits the EF precompiler wall measured at 7c5e1ef and today.

So the static scratch shape is reachable for this program and the data layer is
the thing in the way. The deployment that ships it has no EF Core and no SQLite:
Npgsql plus a Roslyn source generator that emits queries at build time
(app/lib/MicroOrm there), which is why its AOT binary can be one static file.

.github/workflows/aot-probe.yml re-runs this on the x86-64 runner weekly and
gates only the static-link claim (0 interpreters, 0 NEEDED, static-pie), because
the musl AOT ILC crashes under emulation on Apple Silicon. docker-compose.aot.yml
runs the production smoke against the probe image for whoever wants the failure
in full rather than summarised.
2026-10-06 09:15:29 +02:00