Files
openwaf/dotnet/OpenWaf.Edge/Admin/EdgeJson.cs
T
Pavlo Ratushnyi 0a3d28184f
ci / lint the workflow and the shell (push) Failing after 54s
ci / build, test, smoke (push) Successful in 6m4s
ci / the operator page in a real browser (push) Failing after 4m53s
ci / build the image and smoke it (push) Failing after 10m29s
ci / the same smoke on an image with no base (push) Failing after 9m2s
the aot edge serves traffic now, and the shape still missing a contract was its own healthcheck
Measured on this tree with scripts/aot-probe.sh (osx-arm64, a 49,609,680-byte
native binary, 10 IL warnings, 0 errors): the AOT edge reaches "Now listening
on:", creates its 12 tables from the DDL it carries, proxies a request to the
upstream for 200, and its own --healthcheck mode exits 0. The API wall that
stood between the first cut and a serving edge came down in two edits, and the
json-refusal count went 55 -> 1 -> 0.

The 55 were one shape. The anonymous 8-property /healthz literal had no
compiled contract, so the edge was serving traffic while the endpoint a scratch
container's HEALTHCHECK asks answered 500 - an edge that serves and is restarted
anyway. Health/HealthDtos.cs names it (HealthDto, ReadinessDto). The 1 after
that was Microsoft.AspNetCore.Mvc.ProblemDetails, the body Results.Problem
writes and nobody's DTO in this project: its visible cost was a /readyz 500
naming nothing where a 503 naming the failure is the truth. It now says
"Query wasn't precompiled and dynamic code isn't supported with NativeAOT."

The probe's scoreboard is split the way the finding is. Three assertions that
need no query are gated (healthz 200, proxy 200, --healthcheck exit 0), and the
host must be listening with no response refused for want of a contract. Five
that do need a query are recorded with the answer a working edge would give -
operator block 503 where 204 is right, the streak ban never forms, /readyz 503
where 200 is right - and any of them that ever matches prints MOVED, which is
the signal that the query wall moved. queries refused at run time: 32 in that
window, 30 in the run before it; it counts a window, not a total, because the
background refresh loop retries on its own clock.

Two probe bugs surfaced doing this. It sent "Authorization: Bearer" to the admin
API, which AdminAuth does not read, so three of its assertions were measuring a
401 rather than the query wall; and it asserted nothing about whether the host
had listened at all.

Gates on this tree: build 0 warnings, unit 378/378, integration 408/408 in 51 s
(the new one demands a contract for ProblemDetails and ValidationProblemDetails),
smoke 256/256.

Two stale figures corrected rather than left standing. The registered-type count
was 24 in README and ARCHITECTURE while the file at that commit holds 25 -
CountrySummaryDto arrived without the count being re-derived - and it is 29 now.
The anonymous-literal count is 29 in 23 shapes: 22 response shapes, and 7 inside
an EF query's Select, which belong to the query wall rather than this one. The
"48.8 MB" native binary in ARCHITECTURE matches no measured binary of this tree.
2026-10-07 19:28:22 +02:00

79 lines
3.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using System.Text.Json.Serialization;
using OpenWaf.Edge.Health;
namespace OpenWaf.Edge.Admin;
/// <summary>
/// The edge's source-generated JSON contract — the half of the NativeAOT slice
/// that is not the database.
///
/// Measured on 2026-10-06, the AOT edge did not start at all: the host died with
/// <c>JsonTypeInfo metadata for type 'OpenWaf.Edge.Admin.NewBlockRequest' was not
/// provided by TypeInfoResolver</c> (3 refusals in the probe window), while the
/// route handlers in that same stack are already the generated ones
/// (<c>GeneratedRouteBuilderExtensionsCore</c>). So the API half is not missing
/// code generation; it is missing a registered contract for the types that cross
/// the wire. A NativeAOT binary has no reflection resolver to fall back on, and
/// the fallback it would need is exactly the thing the runtime refuses
/// (<c>Dynamic code isn't supported with NativeAOT</c>).
///
/// What registering it bought, measured on 2026-10-07 with the same probe: the
/// edge now reaches <c>Now listening on:</c>, creates its 12 tables from the DDL
/// it carries and proxies a request to the upstream for 200. The one shape still
/// refused at run time was <c>/healthz</c> — 55 refusals, all of them the same
/// anonymous 8-property literal, now <see cref="HealthDto"/>. That is the shape
/// the container's own HEALTHCHECK asks, so the edge was serving traffic while
/// declaring itself dead.
///
/// The recipe is taken, not invented: this is how the neighbouring .NET 10
/// NativeAOT deployment does it (<c>app/lib/Kernel/KernelJson.cs</c> and
/// <c>api/Domain/AppJson.cs</c> in <c>~/work/tskr</c> — one context per assembly,
/// registered by one line in <c>Program.cs</c>).
///
/// <see cref="JsonSourceGenerationOptionsAttribute"/> is load-bearing, not
/// decoration: the generated contract carries the property names, so a context
/// without the camelCase policy would answer <c>{"Error": …}</c> where the console,
/// the smoke gate and every integration assertion read <c>{"error": …}</c>. The
/// options below are the ones minimal APIs use today (<c>JsonSerializerDefaults.Web</c>),
/// so registering this context changes no byte on a non-AOT build.
/// </summary>
[JsonSourceGenerationOptions(
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.Never)]
[JsonSerializable(typeof(ErrorDto))]
[JsonSerializable(typeof(ReadOnlyRefusalDto))]
[JsonSerializable(typeof(NewBlockRequest))]
[JsonSerializable(typeof(NewAllowRequest))]
[JsonSerializable(typeof(NewRuleRequest))]
[JsonSerializable(typeof(NewRateRuleRequest))]
[JsonSerializable(typeof(PolicyUpdateRequest))]
[JsonSerializable(typeof(BlockDto))]
[JsonSerializable(typeof(AllowDto))]
[JsonSerializable(typeof(RuleDto))]
[JsonSerializable(typeof(RateRuleDto))]
[JsonSerializable(typeof(PolicyDto))]
[JsonSerializable(typeof(NetblockDto))]
[JsonSerializable(typeof(RateSourceDto))]
[JsonSerializable(typeof(ObservationDto))]
[JsonSerializable(typeof(StreakDto))]
// The body Results.Problem writes — the error path of /readyz and of every
// handler that catches. Measured 2026-10-07: once /healthz got its contract this
// was the ONLY remaining refusal in the probe window (1 of them), and it turned a
// 503 that names the failure into a 500 that names nothing.
[JsonSerializable(typeof(ProblemDetails))]
[JsonSerializable(typeof(ValidationProblemDetails))]
[JsonSerializable(typeof(HealthDto))]
[JsonSerializable(typeof(ReadinessDto))]
[JsonSerializable(typeof(CountrySummaryDto))]
[JsonSerializable(typeof(HistoryEvent))]
[JsonSerializable(typeof(HorizonRow))]
[JsonSerializable(typeof(HorizonAfter))]
[JsonSerializable(typeof(SearchHit))]
[JsonSerializable(typeof(ImpactSource))]
[JsonSerializable(typeof(ImpactRow))]
[JsonSerializable(typeof(ConfigImportDocument))]
[JsonSerializable(typeof(RejectedItem))]
internal partial class EdgeJson : JsonSerializerContext;