Skip to main content

The middleware pipeline

Every request to api.dualmindlab.tech passes through the same steps before it reaches a controller.
1

Cloudflare Worker

cf-worker/src/index.js forwards the request unchanged to the default container through its Durable Object. On the first request after a deploy it also makes sure the Telegram webhook points at /api/telegram/webhook.
2

Exception handler

Unhandled exceptions become 500 application/problem+json with the title “An unexpected error occurred”. Most controllers catch their own errors first and return a JSON error body instead.
3

Request logging

Assigns an 8-character correlation ID, returns it as the X-Correlation-Id header, and logs method, path, status and duration. Quote this ID when you report a failing request.
4

CORS

The AllowAll policy accepts any origin, method and header.
5

Authentication

JWT bearer validation against the Supabase issuer {SUPABASE_URL}/auth/v1, audience authenticated, HS256 with JWT_SECRET, one minute of clock skew. See Authentication.
6

Claims transformation

RoleClaimsTransformation looks up public.users.role for the token’s sub and adds it as a role claim.
7

Authorization, then the action

Endpoint routing (added implicitly by WebApplication at the start of the pipeline) has already selected the action from its route attributes. The authorization middleware now evaluates that endpoint’s [Authorize], [AllowAnonymous] and [Authorize(Policy = "AdminOnly")] metadata, and only then does the action run.

A battle

responseTimeMs on both agents is the wall-clock time of the whole battle (both calls run in parallel), not each model’s own time. The same value is stored as model1_time_ms and model2_time_ms.
The response also contains an arena.comparison block with a length-and-token heuristic (winnerByLength, winnerByTokens, verdict). The arena doesn’t show it; treat it as debug output.

An admin call

Timeouts at a glance

Last modified on October 18, 2026