Runtime, startup and configuration
69 functions in 15 subgroups. Open a row for inputs, outputs, state and safeguards.
- 69 functions
- 15 subgroups
- Optional 1
- Deprecated 1
- Development only 7
69 of 69
Entry 3 of 3
Chooses between a synchronous or async-bootstrap export and builds the app through startup. It reads the KMS and config-secrets provider settings and exits with code 1 if bootstrap fails (fail-closed).
QODIQA_KMS_ QODIQA_PROVIDER CONFIG_ Direct entry with KMS/SECRETS_ PROVIDER config- app exportPromisesecret gate fail-closed exit 1- What it does
- Choose sync or async-bootstrap export; build app via startup
- Inputs
- QODIQA_KMS_PROVIDER, QODIQA_CONFIG_SECRETS_PROVIDER
- Outputs
- exports app (+) or Promise
- Safeguards
- fail-closed exit 1 on bootstrap
Runs the production entry: bootstraps KMS, then config secrets, then loads the server. Any failure ends the process with exit 1, so the gateway fails closed instead of starting half-configured.
envProduction entryprocess exit 1fail-closed Depends on same- What it does
- KMS bootstrap, config-secrets bootstrap, load server
- Inputs
- env
- Outputs
- process exit 1 on any failure
- Depends on
- same
- Safeguards
- fail-closed
Dispatches the development command line by spawning a child process and forwarding signals to it. It reports its result through exit codes 0, 1 and 2, relying on node child_process.
argvDev CLI dispatcherexit codes 0/1/ 2 node child_process Depends on node child_process - What it does
- spawn; signal forwarding
- Inputs
- argv
- Outputs
- exit codes 0/1/2
- Depends on
- node child_process
Startup 19 of 19
Hardens the process at startup: sets the process title and umask 027, installs crash handlers and runs a cluster check. It crashes on unknown state rather than continuing, and reads NODE_ENV.
NODE_ENV Process hardeningprocess-level umaskcrash-on- unknown- state Depends on /- What it does
- title, umask 027, crash handlers, cluster check
- Inputs
- NODE_ENV
- Outputs
- process-level
- Depends on
- /
- Safeguards
- umask, crash-on-unknown-state
Resolves the deployment mode and rewrites related settings from QODIQA_DEPLOYMENT_MODE, QODIQA_PG_ENABLED and QODIQA_AUDIT_ORDERING_MODE plus replica and migrate variables. Invalid input exits 1, fail-closed with a webhook.
QODIQA_DEPLOYMENT_ QODIQA_MODE PG_ audit ordering modeDeployment mode resolutionexit 1 invalidENABLED fail-closed webhook- What it does
- resolve, rewrite
- Inputs
- QODIQA_DEPLOYMENT_MODE, QODIQA_PG_ENABLED, QODIQA_AUDIT_ORDERING_MODE, replica/migrate vars
- Outputs
- exit 1 on invalid
- Safeguards
- fail-closed + webhook
Validates the whole environment at boot against a Zod schema and 41 rules. Fatal problems raise BOOT_VALIDATION_FATAL and exit 1; others become warnings. Rules cover secret strength, TLS, anchoring and semantic override bans.
whole envBoot validation (41 rules)BOOT_VALIDATION_ exit 1warningsFATAL secret strengthTLSsemantic override bansDepends on zod- What it does
- Zod schema + RULES
- Inputs
- whole env
- Outputs
- BOOT_VALIDATION_FATAL + exit 1, warnings
- Depends on
- zod
- State
- memory
- Safeguards
- secret strength, TLS, anchoring, semantic override bans
Holds the pattern lists used to judge the quality of placeholder and secret strings. It takes strings in and returns status codes; its safeguard is placeholder detection.
stringsPlaceholder/secret quality rules status codesplaceholder detection- What it does
- pattern lists
- Inputs
- strings
- Outputs
- status codes
- Safeguards
- placeholder detection
Deprecated wrapper around the environment shape that delegates to ST-006. It takes the environment as input and returns arrays of results, and it is flagged as deprecated.
envEnv shape wrapperarrays- What it does
- delegates to ST-006
- Inputs
- env
- Outputs
- arrays
Parses the ops, admin and diagnostics configuration into a frozen object from QODIQA_OPS_*, QODIQA_ADMIN_ENABLED, QODIQA_DIAGNOSTICS_ENABLED and health variables. It emits OPS_CONFIG_* events and checks allowlist syntax; planes default off in prod.
QODIQA_OPS_ QODIQA_* ADMIN_ health varsOps/ENABLED admin/ OPS_diagnostics config CONFIG_ * events allowlist syntax checkplanes off (prod)loggerDepends on logger- What it does
- parse + frozen object
- Inputs
- QODIQA_OPS_*, QODIQA_ADMIN_ENABLED, QODIQA_DIAGNOSTICS_ENABLED, health vars
- Outputs
- events OPS_CONFIG_*
- Depends on
- logger
- Safeguards
- allowlist syntax check, planes default off in prod
Gathers PG, Redis, keys and semantic facts into a boot report. It writes a BOOT_REPORT log and optionally a JSON file at QODIQA_BOOT_REPORT_PATH. The report is secret-free.
factsdepsBoot reportBOOT_REPORT log optional JSON filesecret-free pg poolredis cfgDepends on pg pool, redis cfg, semantic cfg- What it does
- gather PG/Redis/keys/semantic facts
- Inputs
- facts + deps
- Outputs
- BOOT_REPORT log, optional file QODIQA_BOOT_REPORT_PATH
- Depends on
- pg pool, redis cfg, semantic cfg
- State
- optional JSON file
- Safeguards
- secret-free
Initialises, fetches and applies config-secrets providers, mutating the environment from the provider type and Vault variables. It clears stale managed secrets; the vault-kv path uses node-vault.
Copy linkprovider typeVault varsConfig-secrets providers env mutationclears stale secretsnode-vault Runs phase-1 module-load initialisation from the environment, starting stores and monitors. It depends on many modules, and fail-closed gates guard the startup so a failed step stops it.
Copy linkenvPhase-1 module- stores startedmonitors startedload init fail-closed gates Covers the startup sequence that takes the app to an HTTP listener and schedulers, with all other parts as dependencies. The S1–S24 gates protect it.
Copy linkappsequenceHTTP listenerschedulersS1–S24 gatesfail-closed Enforces the production durability gate: requires PG and readable evidence stores when NODE_ENV says production. If the requirement is not met, it exits with a FATAL error (fail-closed).
NODE_ENV Production durability gateFATAL exitfail-closed - What it does
- require PG + readable evidence stores
- Inputs
- NODE_ENV
- Outputs
- FATAL exit
- Safeguards
- fail-closed
Attempts a login with the migration role's placeholder credential, controlled by QODIQA_PG_ROLE_CREDENTIAL_GATE. Outcomes are FATAL, ERROR or WARN, and roles with public passwords are blocked.
QODIQA_PG_ Migration-ROLE_ CREDENTIAL_ GATE role placeholder login probe FATALERRORWARNblocks public-password roles PGDepends on PG- What it does
- attempt login
- Inputs
- QODIQA_PG_ROLE_CREDENTIAL_GATE
- Outputs
- FATAL/ERROR/WARN
- Depends on
- PG
- Safeguards
- blocks public-password roles
Refuses to start when STRICT_REPLAY would be unsafe, judging from Redis persistence diagnostics. The result is exit 1, which keeps replay protection intact.
Redis persistence diagSTRICT_REPLAY gate exit 1replay protection- What it does
- refuse start if unsafe
- Inputs
- Redis persistence diag
- Outputs
- exit 1
- Safeguards
- replay protection
Monitors runtime degradation by turning gateway state events into gauges, including redis_store_up and execution_integrity_full. It listens to store emitters and depends on metrics.
store emittersRuntime degradation monitoringredis_store_ execution_up integrity_ full metricsDepends on metrics- What it does
- gateway state events + gauges
- Inputs
- store emitters
- Outputs
- metrics redis_store_up, execution_integrity_full
- Depends on
- metrics
Sets server timeouts before the server begins listening, using PORT, QODIQA_BIND_HOST and timeout settings. The timeouts guard against slowloris-style attacks.
PORTQODIQA_BIND_ timeoutsListen with transport hardeninglistenerHOST slowloris-style timeouts httpDepends on http- What it does
- set server timeouts before listen
- Inputs
- PORT, QODIQA_BIND_HOST, timeouts
- Outputs
- listener
- Depends on
- http
- Safeguards
- slowloris-style timeouts
Validates proxy configuration with warnings at boot and answers per-request with 400 BLOCK bodies. It reads TRUSTED_PROXY, QODIQA_ALLOWED_HOSTS, ENFORCE_HTTPS_PROTO and MAX_FORWARDED_DEPTH, defending against host-header injection and XFF forging.
TRUSTED_PROXY QODIQA_ALLOWED_ ENFORCE_HOSTS HTTPS_ Proxy config validation + runtime guardBLOCK bodiesPROTO host-header injection XFF forging- What it does
- warnings at boot; per-request 400s
- Inputs
- TRUSTED_PROXY, QODIQA_ALLOWED_HOSTS, ENFORCE_HTTPS_PROTO, MAX_FORWARDED_DEPTH
- Outputs
- BLOCK bodies
- Safeguards
- host-header injection, XFF forging
Gates startup on mirror, chain and checkpoint checks over PG and audit files, exiting 1 on failure. It depends on the audit modules and is fail-closed.
Copy linkPGaudit filesMirror/chain/ exit 1checkpoint boot gates fail-closed audit modulesStarts the embedding classifier pool and initialises it, using QODIQA_INFERENCE_WORKERS and QODIQA_SEM_EMBEDDING_ENABLED. If it is not READY the process exits 1, refusing to start without the screening layer.
QODIQA_INFERENCE_ QODIQA_WORKERS SEM_ Embedding classifier boot gatenot READYEMBEDDING_ ENABLED screening requiredsemantic modulesDepends on semantic modules- What it does
- pool + init
- Inputs
- QODIQA_INFERENCE_WORKERS, QODIQA_SEM_EMBEDDING_ENABLED
- Outputs
- exit 1 if not READY
- Depends on
- semantic modules
- Safeguards
- refuse start without screening layer
Starts the schedulers after the server is listening, based on PG flags. It depends on the scanners and similar components, and it starts the timers only once the listener is up.
PG flagsSchedulers started post-listen scannersDepends on scanners etc.- What it does
- start timers
- Inputs
- PG flags
- Depends on
- scanners etc.
Network 1 of 1
Resolves the client IP using a trust predicate and a right-to-left walk over socket, XFF and X-Real-IP values. It never trusts a proxy blindly.
socketXFFX-Real- Client IP resolutionIP no blind trust- What it does
- trust predicate, right-to-left walk
- Inputs
- socket, XFF, X-Real-IP
- Safeguards
- no blind proxy trust
App 8 of 8
Composes the Express app by wiring the middleware chain and mounting the routers from a context object. The layered composition is its stated safeguard.
ctxExpress compositionExpress applayeredroutersDepends on routers- What it does
- middleware + mounts
- Inputs
- ctx
- Outputs
- Express app
- Depends on
- routers
- Safeguards
- layered
Patches async handlers so a rejected promise is passed on through next(err), relying on Express internals. This prevents a crash on async rejection.
Copy linkAsync handler safety patchnext(err)prevents crashexpress internalsSets security headers using helmet plus a Permissions-Policy, depending on NODE_ENV. Safeguards include HSTS in prod, frame deny and CSP.
NODE_ENV Security headersheadersHSTS (prod)frame denyCSPDepends on helmet- What it does
- helmet + Permissions-Policy
- Inputs
- NODE_ENV
- Outputs
- headers
- Depends on
- helmet
- Safeguards
- HSTS (prod), frame deny, CSP
Overrides the Content-Security-Policy header for API responses by wrapping it in a strict CSP. The strict policy is the safeguard, and the CSP header is the output of this step.
Copy linkAPI CSP overrideCSP headerstrict CSPGenerates a request id as a UUID using the crypto module and exposes it both as a response header and in the request locals, so each request can be identified in later steps.
Copy linkRequest idheaderlocalscryptoParses request bodies with a size limit taken from MAX_BODY_BYTES, plus a verify step. It rejects invalid UTF-8 and answers 400 or 413 when a body is refused.
MAX_BODY_ Body parsing / UTF-BYTES 8 / size 400413rejects invalid UTF-8 - What it does
- + verify
- Inputs
- MAX_BODY_BYTES
- Outputs
- 400/413
- Safeguards
- rejects invalid UTF-8
Drains requests using a counter and answers 503 once draining has started, so new requests are turned away while the count of active requests falls.
- What it does
- counter + 503
Gates requests with the kill switch: answers 503 when the switch is active or its state is unavailable, and emits a metric. State lives in the control plane, and the gate fails closed.
Kill-switch gate 503metricfail-closed control plane- What it does
- 503 when active/unavailable
- Outputs
- metric
- State
- control plane
- Safeguards
- fail-closed
Auth 10 of 10
Optional operator authentication for ops routes using a Bearer or X-Ops-Token credential, with federation as a dependency. Comparison is timing-safe and failures lock out, with lockout state kept in Redis.
Copy linkBearerX-Ops- Ops/Token operator authentication timing-safe lockoutfederationMatches client addresses against an IP allowlist by CIDR, configured through QODIQA_OPS_IP_ALLOWLIST*. Non-matching requests get 403, and a misconfiguration denies all.
QODIQA_OPS_ IP allowlist403IP_ ALLOWLIST* deny-all on misconfig - What it does
- CIDR match
- Inputs
- QODIQA_OPS_IP_ALLOWLIST*
- Outputs
- 403
- Safeguards
- deny-all on misconfig
Gates the plane routes, answering 404 when a plane is disabled. Because disabled planes return 404, the planes cannot be enumerated from outside.
Plane gates404non-enumerable planes - What it does
- 404 when disabled
- Safeguards
- non-enumerable planes
Hardens the health probe with optional ops authentication or loopback-only access, controlled by flags. Rejected callers receive 401 or 403.
flagsHealth probe hardening401403- What it does
- optional ops auth / loopback only
- Inputs
- flags
- Outputs
- 401/403
Resolves RBAC and checks a permission, answering 403 on denial. It emits RBAC_* events and a metric, and the default is deny.
permissionRBAC resolve + permission403RBAC_* events metricdefault deny- What it does
- 403 deny
- Inputs
- permission
- Outputs
- RBAC_* events/metric
- Safeguards
- default deny
Assembles the admin protection stack as ordered arrays of layers, applied in the order rate-limit, allowlist, auth, RBAC, gate. It lists no outputs or dependencies.
layersAdmin protection stackordered arraysrate-limit allowlistRBAC- What it does
- ordered arrays
- Inputs
- layers
- Safeguards
- rate-limit→allowlist→auth→RBAC→gate
Requires MFA step-up using the X-QODIQA-OTP header and the MFA module, with an MFA store. Failures return 4xx or 5xx, and an exemption list of 18 applies.
Copy linkX-QODIQA- MFA step-OTP up 4xx5xxmfa moduleMFA storeexemption list 18Authenticates signing credentials from a Bearer token through identity lookup and lockout. Lockout and assurance checks protect the path.
BearerSigning-credential auth lockoutassurance- What it does
- identity lookup, lockout
- Inputs
- Bearer
- Safeguards
- lockout, assurance
Authenticates portal sessions by verifying a Bearer session token and checking the user is live. Session version revocation invalidates old sessions.
Bearer session tokenPortal session authsession version revocation- What it does
- verify, live user check
- Inputs
- Bearer session token
- Safeguards
- session version revocation
Wraps authentication so the layers run only if a credential header is present. There is no silent downgrade of a presented credential.
Optional auth wrapperno silent downgrade- What it does
- run layers iff credential header present
- Safeguards
- no silent downgrade
API 2 of 2
Sets the API version header and the deprecation headers on responses, so clients can see which API version served them and whether an endpoint is deprecated.
Version + deprecation headersheaders- What it does
- set headers
- Outputs
- headers
Enforces the request content type by answering 415 and producing a BLOCK outcome for any content type that is not supported.
Copy linkContent-type enforcement BLOCK415
Runtime 10 of 10
Performs graceful shutdown on signals, ending with exit codes. It flushes in order across all stores it depends on, which is its stated safeguard.
signalsGraceful shutdownexit codesordered flushall storesDepends on all stores- What it does
- Active
- Inputs
- signals
- Outputs
- exit codes
- Depends on
- all stores
- Safeguards
- ordered flush
Monitors the event loop with a histogram and a state, using perf_hooks and the QODIQA_EVENT_LOOP_* settings. It publishes gauges and events.
QODIQA_EVENT_ Event-LOOP_ * loop monitor gaugeseventsperf_hooks Depends on perf_hooks - What it does
- histogram, state
- Inputs
- QODIQA_EVENT_LOOP_*
- Outputs
- gauges/events
- Depends on
- perf_hooks
Tracks readiness as a flag with state transitions, and publishes the changes as metrics and events so other components can follow whether the service is ready.
Readiness state/tracker metricsevents- What it does
- flag + transitions
- Outputs
- metrics/events
Logs startup and clock diagnostics as events, drawing on the redis configuration. No credentials are logged, so the diagnostics can be read without exposing secrets.
Copy linkStartup/clock diagnostics eventsno credentials loggedredis cfgSends an early critical notification with a fetch POST that times out after 3 s, to the address in ALERT_WEBHOOK_URL. It never throws, so a failed notification cannot break startup.
ALERT_WEBHOOK_ Early critical notifywebhookURL never throwsfetchDepends on fetch- What it does
- fetch POST, 3 s
- Inputs
- ALERT_WEBHOOK_URL
- Outputs
- webhook
- Depends on
- fetch
- Safeguards
- never throws
Runs a named background task function and returns results and metrics, using the task registry and metrics. Failure isolation keeps one failing task from affecting others.
Copy linknamefnBackground task runnerresultsmetricsfailure isolationregistryRegisters the background tasks in a registry of 19 entries. Each entry is explicitly classified, which is the safeguard that keeps the set of tasks reviewable.
Task registryexplicit classification- What it does
- 19 entries
- Safeguards
- explicit classification
Keeps task context using AsyncLocalStorage, so that work run by the background task runner can be tied to the task registry entry it belongs to.
- What it does
- AsyncLocalStorage
Writes raw diagnostics by emitting JSON objects directly to stderr. It takes no listed inputs and sends its output straight to the standard error stream.
Raw stderr diagnosticsstderr- What it does
- write JSON
- Outputs
- stderr
Provides the NTP documentation check, covering the documentation that relates to network time synchronisation for the platform.
Copy link
Config 1 of 1
Covers the bootstrap for the split between the deployment and the KMS provider, which separates deployment configuration from the key management service provider.
Copy link
Dev 4 of 4
Starts an isolated development bootstrap with npm run dev, reading .env and QODIQA_DEV_*. It launches a child gateway using a temp dir and an optional dev DB, protected by an isolation guard.
.env QODIQA_DEV_ Isolated dev bootstrapchild gateway* isolation guardtemp diroptional dev DB- What it does
- Active (npm run dev)
- Inputs
- .env, QODIQA_DEV_*
- Outputs
- child gateway
- State
- temp dir, optional dev DB
- Safeguards
- isolation guard
Command line that brings up a local sandbox gateway using Docker Redis and PG plus the sandbox provider. PG runs on tmpfs, and real provider keys are stripped.
flagsSandbox gateway CLIlocal gatewayreal keys strippedtmpfs PGdockerDepends on docker- What it does
- Docker Redis/PG + sandbox provider
- Inputs
- flags
- Outputs
- local gateway
- Depends on
- docker
- State
- tmpfs PG
- Safeguards
- real provider keys stripped
Sandbox LLM provider that echoes requests and streams SSE responses over HTTP. It binds only to 127.0.0.1, which is its stated safeguard.
HTTPSandbox LLM providerresponsesbinds 127.0. 0. 1 Depends on http- What it does
- echo + SSE
- Inputs
- HTTP
- Outputs
- responses
- Depends on
- http
- Safeguards
- binds 127.0.0.1
Supplies the policy set used by the sandbox. The policies are kept in a file and loaded from it, so the sandbox runs against a defined set of rules.
- What it does
- policy set for sandbox
- State
- file
Ops 1 of 1
Standalone runtime preflight tool that runs 5 checks against REDIS_URL, QODIQA_PG_*, OLLAMA_BASE_URL and QODIQA_KEYS_PATH, using redis and pg. It exits 0 or 1, with optional files.
REDIS_URL QODIQA_PG_ OLLAMA_* BASE_ Runtime preflight TOOLexit 0/URL 1 redispgDepends on redis, pg- What it does
- 5 checks
- Inputs
- REDIS_URL, QODIQA_PG_*, OLLAMA_BASE_URL, QODIQA_KEYS_PATH
- Outputs
- exit 0/1
- Depends on
- redis, pg
Perf 1 of 1
Standalone benchmark command line tool. It runs the suites chosen through its flags and writes reports as output, and it can keep optional files for its state.
Copy linkflagsBenchmark CLI TOOLreports
Harness 1 of 1
Standalone protocol harness that loops through sign, verify and policy steps and reports an exit code. It depends on many core modules.
Protocol harness TOOLexit codecore modulesDepends on many core modules- What it does
- sign/verify/policy loop
- Outputs
- exit code
- Depends on
- many core modules
Errors 1 of 1
Holds the error catalog of 182 codes, which feeds an OpenAPI extension so that the documented API errors match the codes the platform can return.
Error catalogOpenAPI extension- What it does
- 182 codes
- Outputs
- OpenAPI extension
Utils 6 of 6
Produces canonical JSON by normalising and sorting any input into a string, using fast-json-stable-stringify. It rejects unsafe keys and types.
anyCanonical JSONstringrejects unsafe keysfast-json- stable- stringify Depends on fast-json- stable- stringify - What it does
- normalize+sort
- Inputs
- any
- Outputs
- string
- Depends on
- fast-json-stable-stringify
- Safeguards
- rejects unsafe keys/types
Parses pagination from query parameters and builds the pagination meta for a response. The page size is capped at 500, which bounds how much one response can return.
queryPaginationpage cap 500- What it does
- parse/meta
- Inputs
- query
- Safeguards
- caps page size 500
Builds a Content-Disposition header from a filename in an injection-safe way. CRLF characters are stripped from the filename, preventing header injection.
filenameContent-Disposition headerCRLF strip- What it does
- header injection-safe
- Inputs
- filename
- Outputs
- header
- Safeguards
- CRLF strip
Guards CSV cells against formula injection by prefixing a quote to the cell value. It takes a cell as input and protects spreadsheet users who open exported files.
cellCSV injection guardformula injection- What it does
- prefix quote
- Inputs
- cell
- Safeguards
- formula injection
Reorders rows into hash-link order and provides a streaming linker. It takes rows as input and detects forks in the chain.
rowsHash-link ordering detects forks- What it does
- reorder / streaming linker
- Inputs
- rows
- Safeguards
- detects forks
Implements a timeout race, a small helper that lets an operation compete against a timer so a slow call can be cut off. It is active.
Copy link
Policy 1 of 1
Defines the policy files. The dev set has 5 policies: POL-001 REQUIRE_CONSENT, POL-002 BLOCK_IP, POL-003 TIME_WINDOW (disabled), POL-004 RATE_LIMIT and POL-NEW RATE_LIMIT; the prod example adds 4. A policy loader reads them from a file.
Policy filespolicy loaderDepends on policy loader- What it does
- dev: 5 policies POL-001 REQUIRE_CONSENT, POL-002 BLOCK_IP, POL-003 TIME_WINDOW(disabled), POL-004 RATE_LIMIT, POL-NEW RATE_LIMIT; prod example: + 4 (REQUIRE_CONSENT_BASELINE, BLOCK_IP_DENYLIST(disabled), PER_USER_RATE_LIMIT, BUSINESS_HOURS_WINDOW(disabled))
- Depends on
- policy loader
- State
- file
