From 25db0c80acd66921f9f4955675ef1faf5e8254b8 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 13 Nov 2026 20:59:48 +0800 Subject: [PATCH 1/2] Read the AI logging policy from ROUTING KV in the proxy Since 1.8.0 the proxy asked the API for each project's AI logging policy on every AI call, and the API refused unless PLATFORM_AUTH_DATABASE_UNCACHED was set. Hosted Void Cloud never sets it, so every hosted AI call failed with 503 ai_logging_policy_unavailable. The proxy now reads `ai-logging:` from ROUTING KV (cacheTtl 30) in /ai/run, /ai/provider and /ai/toMarkdown, after body validation: - missing key: inherit (send no logging option, as in 1.7.0) - off / metadata / full: apply the 1.8.0 gateway mapping, kept in one place - KV error: 503 ai_logging_policy_unavailable with Retry-After, logged - any other value: 503 ai_logging_policy_invalid, logged without the value Caller-supplied logging keys are still stripped. /ai/models, unknown paths and 400 bodies never read the key. The modes, key names, parsers and resolver move to a new shared subpath, @void/platform/ai-logging, used by the proxy, the API and the installer. Adds a manual live-check script for the two Cloudflare behaviours the binding mapping depends on. Refs #793. Co-Authored-By: Claude Opus 5.5 --- packages/platform/package.json | 4 + packages/platform/src/ai-logging.ts | 288 +++++++++++++++ .../platform/test/unit/ai-logging.test.ts | 182 ++++++++++ packages/platform/vite.config.ts | 1 + platform/packages/proxy/README.md | 18 +- platform/packages/proxy/src/ai-logging.ts | 122 +++++-- platform/packages/proxy/src/ai.ts | 55 ++- platform/packages/proxy/src/types.ts | 4 +- .../packages/proxy/test/unit/proxy.test.ts | 332 ++++++++++++------ platform/scripts/ai-logging-live-check.ts | 309 ++++++++++++++++ 10 files changed, 1149 insertions(+), 166 deletions(-) create mode 100644 packages/platform/src/ai-logging.ts create mode 100644 packages/platform/test/unit/ai-logging.test.ts create mode 100644 platform/scripts/ai-logging-live-check.ts diff --git a/packages/platform/package.json b/packages/platform/package.json index 4d4b6c1bd..e3d86991d 100644 --- a/packages/platform/package.json +++ b/packages/platform/package.json @@ -33,6 +33,10 @@ "types": "./dist/plans.d.mts", "import": "./dist/plans.mjs" }, + "./ai-logging": { + "types": "./dist/ai-logging.d.mts", + "import": "./dist/ai-logging.mjs" + }, "./browser-page": { "types": "./dist/browser-page.d.mts", "import": "./dist/browser-page.mjs" diff --git a/packages/platform/src/ai-logging.ts b/packages/platform/src/ai-logging.ts new file mode 100644 index 000000000..1dcd31396 --- /dev/null +++ b/packages/platform/src/ai-logging.ts @@ -0,0 +1,288 @@ +/** + * AI Gateway logging policy shared by the platform API, proxy and installer. + * + * The API saves a project override (and plan defaults) in Postgres and publishes the + * effective mode to ROUTING KV under `aiLoggingKey(projectId)`. The proxy reads only + * that key. A missing key means `inherit`: the gateway's own `collect_logs` setting. + */ + +/** Every mode an operator can choose. `inherit` clears an override. */ +export const AI_LOGGING_MODES = ['inherit', 'off', 'metadata', 'full'] as const; +export type AiLoggingMode = (typeof AI_LOGGING_MODES)[number]; + +/** Modes that are saved and published. `inherit` is never stored: no row, no key. */ +export const PUBLISHED_AI_LOGGING_MODES = ['off', 'metadata', 'full'] as const; +export type PublishedAiLoggingMode = (typeof PUBLISHED_AI_LOGGING_MODES)[number]; + +/** Where an effective mode comes from. `gateway` means nothing is set (inherit). */ +export type AiLoggingSource = 'project' | 'plan' | 'gateway'; + +/** + * How a change between two effective modes moves logging. Only + * `off < metadata < full` has a known order: `inherit` follows the gateway setting, + * which the platform never reads, so any change to or from it is `unknown`. + */ +export type AiLoggingPublishOrder = 'same' | 'tighten' | 'loosen' | 'unknown'; + +const AI_LOGGING_KEY_PREFIX = 'ai-logging:'; + +export function isAiLoggingMode(value: unknown): value is AiLoggingMode { + return AI_LOGGING_MODES.some((mode) => mode === value); +} + +export function isPublishedAiLoggingMode(value: unknown): value is PublishedAiLoggingMode { + return PUBLISHED_AI_LOGGING_MODES.some((mode) => mode === value); +} + +/** ROUTING KV key that holds a project's published AI logging mode. */ +export function aiLoggingKey(projectId: string): string { + return `${AI_LOGGING_KEY_PREFIX}${projectId}`; +} + +/** + * Reads a published KV value: a missing key is `inherit`, a stored mode is that mode. + * Anything else, including a literal `inherit` or a mode from a newer platform, + * returns `undefined` so callers fail closed instead of logging more than intended. + */ +export function parsePublishedAiLogging(value: string | null): AiLoggingMode | undefined { + if (value === null) { + return 'inherit'; + } + return isPublishedAiLoggingMode(value) ? value : undefined; +} + +/** Effective mode: the project override, else the plan default, else inherit. */ +export function resolveAiLogging( + projectMode: AiLoggingMode | null | undefined, + planMode: AiLoggingMode | null | undefined, +): Readonly<{ mode: AiLoggingMode; source: AiLoggingSource }> { + if (projectMode && projectMode !== 'inherit') { + return { mode: projectMode, source: 'project' }; + } + if (planMode && planMode !== 'inherit') { + return { mode: planMode, source: 'plan' }; + } + return { mode: 'inherit', source: 'gateway' }; +} + +const LOGGING_RANK: Readonly> = { + off: 0, + metadata: 1, + full: 2, +}; + +/** Compares two effective modes (not saved project fields) to order a publish. */ +export function publishOrder( + previousEffective: AiLoggingMode, + nextEffective: AiLoggingMode, +): AiLoggingPublishOrder { + if (previousEffective === nextEffective) { + return 'same'; + } + if (previousEffective === 'inherit' || nextEffective === 'inherit') { + return 'unknown'; + } + return LOGGING_RANK[nextEffective] < LOGGING_RANK[previousEffective] ? 'tighten' : 'loosen'; +} + +/** + * How long after a KV write new requests are expected to follow it. KV may take up to + * 60 s (plus the proxy's 30 s `cacheTtl`) to reach other locations. A target, not a + * guarantee. + */ +export const AI_LOGGING_SETTLE_MS = 120_000; + +/** Edge cache time of the proxy's key read: KV's minimum, the same as the project token floor. */ +export const AI_LOGGING_CACHE_TTL_SECONDS = 30; + +const AI_LOGGING_CLEARED_KEY_PREFIX = 'ai-logging-cleared:'; + +/** + * ROUTING KV marker written just before `aiLoggingKey(projectId)` is removed for a + * project that now inherits. A removed key leaves no publish time behind, so readback + * reads this marker to report `pending` while other locations may still serve the old + * value. Only the API reads it (never the proxy), and it expires after the settle time. + * Its prefix does not start with the published key prefix, so key listings skip it. + */ +export function aiLoggingClearedKey(projectId: string): string { + return `${AI_LOGGING_CLEARED_KEY_PREFIX}${projectId}`; +} + +/** KV expiry of the cleared marker, in seconds (KV's minimum is 60). */ +export const AI_LOGGING_CLEARED_TTL_SECONDS: number = AI_LOGGING_SETTLE_MS / 1000; + +/** The KV value and options of a cleared marker written at `at` (ms). */ +export function aiLoggingClearedMarker(at: number): Readonly<{ + value: string; + metadata: Readonly<{ at: number }>; + expirationTtl: number; +}> { + return { value: 'inherit', metadata: { at }, expirationTtl: AI_LOGGING_CLEARED_TTL_SECONDS }; +} + +/** Reads a cleared marker's time; anything missing or malformed is `null`. */ +export function parseAiLoggingClearedAt(metadata: unknown): number | null { + if (typeof metadata !== 'object' || metadata === null || Array.isArray(metadata)) { + return null; + } + const { at } = metadata as Record; + return typeof at === 'number' && Number.isSafeInteger(at) ? at : null; +} + +/** ROUTING KV metadata written with every published key. `at` is the publish time in ms. */ +export type AiLoggingKeyMetadata = Readonly<{ mode: PublishedAiLoggingMode; at: number }>; + +/** Reads the metadata of a published key; anything malformed is `null` (treated as drift). */ +export function parseAiLoggingKeyMetadata(value: unknown): AiLoggingKeyMetadata | null { + if (typeof value !== 'object' || value === null || Array.isArray(value)) { + return null; + } + const { mode, at } = value as Record; + if (!isPublishedAiLoggingMode(mode) || typeof at !== 'number' || !Number.isSafeInteger(at)) { + return null; + } + return { mode, at }; +} + +/** `platform_settings` key that holds plan defaults, kept apart from `plans:catalog`. */ +export const PLAN_AI_LOGGING_SETTING = 'plans:ai-logging'; + +/** + * A key for a project with no row may belong to a project whose create transaction + * has written KV but not committed yet. Cleanup leaves keys this young alone. + */ +export const AI_LOGGING_ORPHAN_GRACE_MS: number = 10 * 60_000; + +/** + * A plan-default fan-out that is still running (or stopped on an error). + * `revision` is the plan catalog revision that started it, so a page that began + * before a newer plan change cannot move the newer run's cursor. + */ +export type PlanAiLoggingPublish = Readonly<{ + revision: number; + planIds: ReadonlyArray; + includeUnknown: boolean; + cursor: string | null; + complete: boolean; + error?: string; +}>; + +export type PlanAiLoggingSettings = Readonly<{ + /** Plan ID -> default mode. A missing plan inherits. */ + modes: Readonly>; + publish: PlanAiLoggingPublish | null; +}>; + +function settingsRecord(value: unknown, name: string): Record { + if (typeof value !== 'object' || value === null || Array.isArray(value)) { + throw new Error(`${name} must be an object.`); + } + return value as Record; +} + +function parsePlanAiLoggingPublish(value: unknown): PlanAiLoggingPublish | null { + if (value === null || value === undefined) { + return null; + } + const input = settingsRecord(value, 'AI logging publish'); + const { revision, planIds, includeUnknown, cursor, complete, error } = input; + if ( + !Number.isSafeInteger(revision) || + !Array.isArray(planIds) || + !planIds.every((id) => typeof id === 'string') || + typeof includeUnknown !== 'boolean' || + (cursor !== null && typeof cursor !== 'string') || + typeof complete !== 'boolean' || + (error !== undefined && typeof error !== 'string') + ) { + throw new Error('Invalid AI logging publish progress.'); + } + return { + revision: revision as number, + planIds: planIds as Array, + includeUnknown, + cursor, + complete, + ...(error === undefined ? {} : { error }), + }; +} + +/** + * Reads the saved plan defaults. A missing row means every plan inherits. A mode the + * platform does not know is refused (so a bad value never loosens logging); + * `inherit` entries are dropped. Entries for plans not in the catalog stay in the + * object but are never looked up (see `planAiLogging`). + */ +export function parsePlanAiLoggingSettings(value: unknown): PlanAiLoggingSettings { + if (value === null || value === undefined) { + return { modes: {}, publish: null }; + } + const input = settingsRecord(value, 'Plan AI logging settings'); + const saved = settingsRecord(input.modes ?? {}, 'Plan AI logging modes'); + const modes: Record = {}; + for (const [planId, mode] of Object.entries(saved)) { + if (!isAiLoggingMode(mode)) { + throw new Error(`Invalid AI logging mode for plan ${planId}.`); + } + if (mode !== 'inherit') { + modes[planId] = mode; + } + } + return { modes, publish: parsePlanAiLoggingPublish(input.publish) }; +} + +/** The parts of a plan catalog the logging resolver needs. */ +export type AiLoggingPlanCatalog = Readonly<{ + defaultPlanId: string; + plans: ReadonlyArray>; +}>; + +export type PlanAiLogging = Readonly<{ + planId: string; + /** False when the account's plan ID is not in the catalog. */ + planKnown: boolean; + /** The catalog default plan, whose logging an unknown plan ID follows. */ + defaultPlanId: string; + planMode: PublishedAiLoggingMode | null; +}>; + +/** + * The plan default for an account. A plan ID that is not in the catalog takes the + * default plan's logging (unlike limits, which fall back to the built-in free plan), + * so an operator who sets `off` on every plan gets `off` for every account. + */ +export function planAiLogging( + settings: PlanAiLoggingSettings, + catalog: AiLoggingPlanCatalog, + planId: string, +): PlanAiLogging { + const planKnown = catalog.plans.some((plan) => plan.id === planId); + const lookup = planKnown ? planId : catalog.defaultPlanId; + const planMode = Object.hasOwn(settings.modes, lookup) ? settings.modes[lookup]! : null; + return { planId, planKnown, defaultPlanId: catalog.defaultPlanId, planMode }; +} + +/** Whether a running plan publish still has to reach accounts on this plan. */ +export function planPublishPending( + publish: PlanAiLoggingPublish | null, + plan: Pick, +): boolean { + if (!publish || publish.complete) { + return false; + } + return plan.planKnown ? publish.planIds.includes(plan.planId) : publish.includeUnknown; +} + +/** + * Reads a plan's `aiLogging` field from a plan change. `undefined` keeps the current + * value and `inherit` clears it. + */ +export function parsePlanAiLoggingInput(value: unknown): AiLoggingMode | undefined { + if (value === undefined) { + return undefined; + } + if (!isAiLoggingMode(value)) { + throw new Error(`aiLogging must be one of ${AI_LOGGING_MODES.join(', ')}.`); + } + return value; +} diff --git a/packages/platform/test/unit/ai-logging.test.ts b/packages/platform/test/unit/ai-logging.test.ts new file mode 100644 index 000000000..9d40fbe57 --- /dev/null +++ b/packages/platform/test/unit/ai-logging.test.ts @@ -0,0 +1,182 @@ +import { describe, expect, it } from 'vite-plus/test'; +import { + AI_LOGGING_MODES, + aiLoggingKey, + isAiLoggingMode, + isPublishedAiLoggingMode, + parseAiLoggingKeyMetadata, + parsePlanAiLoggingInput, + parsePlanAiLoggingSettings, + parsePublishedAiLogging, + planAiLogging, + planPublishPending, + publishOrder, + resolveAiLogging, +} from '../../src/ai-logging.ts'; + +describe('AI logging policy', () => { + it('accepts exactly the four operator modes', () => { + expect(AI_LOGGING_MODES).toEqual(['inherit', 'off', 'metadata', 'full']); + for (const mode of AI_LOGGING_MODES) { + expect(isAiLoggingMode(mode)).toBe(true); + } + for (const value of ['OFF', ' off', '', 'none', null, undefined, 0, false, {}]) { + expect(isAiLoggingMode(value)).toBe(false); + } + }); + + it('never stores inherit', () => { + expect(isPublishedAiLoggingMode('inherit')).toBe(false); + expect(['off', 'metadata', 'full'].every(isPublishedAiLoggingMode)).toBe(true); + }); + + it('names the ROUTING key after the project', () => { + expect(aiLoggingKey('proj_000000000042')).toBe('ai-logging:proj_000000000042'); + }); + + it('reads a missing key as inherit and refuses values it does not know', () => { + expect(parsePublishedAiLogging(null)).toBe('inherit'); + expect(parsePublishedAiLogging('off')).toBe('off'); + expect(parsePublishedAiLogging('metadata')).toBe('metadata'); + expect(parsePublishedAiLogging('full')).toBe('full'); + for (const value of ['inherit', '', 'OFF', 'off ', '"off"', 'future-mode']) { + expect(parsePublishedAiLogging(value)).toBeUndefined(); + } + }); + + it('prefers the project override, then the plan default, then the gateway', () => { + expect(resolveAiLogging('full', 'off')).toEqual({ mode: 'full', source: 'project' }); + expect(resolveAiLogging('off', 'full')).toEqual({ mode: 'off', source: 'project' }); + expect(resolveAiLogging(null, 'metadata')).toEqual({ mode: 'metadata', source: 'plan' }); + expect(resolveAiLogging('inherit', 'off')).toEqual({ mode: 'off', source: 'plan' }); + expect(resolveAiLogging(undefined, 'inherit')).toEqual({ mode: 'inherit', source: 'gateway' }); + expect(resolveAiLogging(null, null)).toEqual({ mode: 'inherit', source: 'gateway' }); + }); + + it('orders known changes and treats any change with inherit as unknown', () => { + expect(publishOrder('full', 'off')).toBe('tighten'); + expect(publishOrder('full', 'metadata')).toBe('tighten'); + expect(publishOrder('metadata', 'off')).toBe('tighten'); + expect(publishOrder('off', 'metadata')).toBe('loosen'); + expect(publishOrder('off', 'full')).toBe('loosen'); + expect(publishOrder('metadata', 'full')).toBe('loosen'); + for (const mode of AI_LOGGING_MODES) { + expect(publishOrder(mode, mode)).toBe('same'); + } + for (const mode of ['off', 'metadata', 'full'] as const) { + expect(publishOrder('inherit', mode)).toBe('unknown'); + expect(publishOrder(mode, 'inherit')).toBe('unknown'); + } + }); + + it('orders by effective values, not by the saved project field', () => { + // A project override removed (`full` -> no row) while its plan says `off`. + const before = resolveAiLogging('full', 'off').mode; + const after = resolveAiLogging(null, 'off').mode; + expect(publishOrder(before, after)).toBe('tighten'); + }); + + it('reads key metadata and treats anything malformed as missing', () => { + expect(parseAiLoggingKeyMetadata({ mode: 'off', at: 1700000000000 })).toEqual({ + mode: 'off', + at: 1700000000000, + }); + for (const value of [ + null, + undefined, + 'off', + [], + { mode: 'inherit', at: 1 }, + { mode: 'off' }, + { mode: 'off', at: '1' }, + { mode: 'off', at: 1.5 }, + ]) { + expect(parseAiLoggingKeyMetadata(value)).toBeNull(); + } + }); +}); + +describe('plan AI logging defaults', () => { + const catalog = { defaultPlanId: 'free', plans: [{ id: 'free' }, { id: 'pro' }] }; + + it('reads a missing row as every plan inheriting', () => { + expect(parsePlanAiLoggingSettings(null)).toEqual({ modes: {}, publish: null }); + expect(planAiLogging(parsePlanAiLoggingSettings(null), catalog, 'pro')).toEqual({ + planId: 'pro', + planKnown: true, + defaultPlanId: 'free', + planMode: null, + }); + }); + + it('keeps known modes, drops inherit and refuses modes it does not know', () => { + const settings = parsePlanAiLoggingSettings({ + modes: { pro: 'metadata', free: 'inherit', gone: 'off' }, + publish: null, + }); + expect(settings.modes).toEqual({ pro: 'metadata', gone: 'off' }); + for (const modes of [{ pro: 'OFF' }, { pro: null }, { pro: 1 }, []]) { + expect(() => parsePlanAiLoggingSettings({ modes, publish: null })).toThrow(); + } + expect(() => parsePlanAiLoggingSettings('off')).toThrow(); + expect(() => + parsePlanAiLoggingSettings({ modes: {}, publish: { planIds: 'pro', complete: false } }), + ).toThrow(); + }); + + it('ignores entries for plans that are no longer in the catalog', () => { + const settings = parsePlanAiLoggingSettings({ modes: { gone: 'off' } }); + expect(planAiLogging(settings, catalog, 'free').planMode).toBeNull(); + expect(planAiLogging(settings, catalog, 'pro').planMode).toBeNull(); + }); + + it('gives an account on an unknown plan the logging of the default plan', () => { + const settings = parsePlanAiLoggingSettings({ modes: { free: 'off', pro: 'full' } }); + expect(planAiLogging(settings, catalog, 'legacy-x')).toEqual({ + planId: 'legacy-x', + planKnown: false, + defaultPlanId: 'free', + planMode: 'off', + }); + expect(planAiLogging(settings, catalog, 'pro').planMode).toBe('full'); + }); + + it('knows which accounts a running plan publish still has to reach', () => { + const publish = parsePlanAiLoggingSettings({ + modes: {}, + publish: { + revision: 3, + planIds: ['pro'], + includeUnknown: true, + cursor: null, + complete: false, + }, + }).publish!; + expect(planPublishPending(publish, { planId: 'pro', planKnown: true })).toBe(true); + expect(planPublishPending(publish, { planId: 'free', planKnown: true })).toBe(false); + expect(planPublishPending(publish, { planId: 'legacy-x', planKnown: false })).toBe(true); + expect( + planPublishPending({ ...publish, complete: true }, { planId: 'pro', planKnown: true }), + ).toBe(false); + expect(planPublishPending(null, { planId: 'pro', planKnown: true })).toBe(false); + }); + + it('requires the catalog revision that started a publish', () => { + const publish = { planIds: ['pro'], includeUnknown: false, cursor: null, complete: false }; + expect(() => parsePlanAiLoggingSettings({ modes: {}, publish })).toThrow(); + expect( + parsePlanAiLoggingSettings({ modes: {}, publish: { ...publish, revision: 4, error: 'x' } }) + .publish, + ).toEqual({ ...publish, revision: 4, error: 'x' }); + }); + + it('reads a plan change: omitted keeps, inherit clears, anything else is refused', () => { + expect(parsePlanAiLoggingInput(undefined)).toBeUndefined(); + for (const mode of AI_LOGGING_MODES) { + expect(parsePlanAiLoggingInput(mode)).toBe(mode); + } + for (const value of [null, '', 'OFF', 'everything', 1]) { + expect(() => parsePlanAiLoggingInput(value)).toThrow('aiLogging must be one of'); + } + }); +}); diff --git a/packages/platform/vite.config.ts b/packages/platform/vite.config.ts index d6cbc5da5..84c7423a5 100644 --- a/packages/platform/vite.config.ts +++ b/packages/platform/vite.config.ts @@ -18,6 +18,7 @@ export default defineConfig({ 'src/installer.ts', 'src/email-protocol.ts', 'src/plans.ts', + 'src/ai-logging.ts', 'src/browser-page.ts', ], format: 'esm', diff --git a/platform/packages/proxy/README.md b/platform/packages/proxy/README.md index f6efb7fa9..e1b0f94fe 100644 --- a/platform/packages/proxy/README.md +++ b/platform/packages/proxy/README.md @@ -104,6 +104,22 @@ the route and project. That value never leaves the platform. `/ai/*` also checks `ROUTING` for `ai-block:{projectId}` before forwarding. +`/ai/run`, `/ai/provider`, and `/ai/toMarkdown` read the project's AI Gateway +logging mode from `ROUTING` key `ai-logging:{projectId}` (`cacheTtl: 30`) after +the body is checked. The API publishes it; the proxy never asks the API. + +| Value | AI Gateway logging | +| ------------- | ----------------------------------------------------- | +| missing | inherit: the gateway's own setting, nothing is sent | +| `off` | no log entry | +| `metadata` | log entry without the request and response bodies | +| `full` | log entry with the request and response bodies | +| anything else | 503 `ai_logging_policy_invalid` | +| read fails | 503 `ai_logging_policy_unavailable`, `Retry-After: 5` | + +Caller gateway logging options and `cf-aig-*` logging headers are always dropped, +so an app cannot change this. `/ai/models` does not read the key. + `/ai/provider` forwards to `AI.gateway("void").getUrl(provider)` plus the relative `path`. JSON, text, binary, and multipart bodies are serialized by the SDK and reconstructed before forwarding. OpenAI-style providers default to `Authorization: Bearer `; Google AI Studio uses `x-goog-api-key`. Non-JSON responses are returned without JSON coercion so provider-native binary and streaming responses can pass through. ### Remote bindings @@ -191,7 +207,7 @@ test/unit/ | `AI` | Workers AI | Real inference binding | | `API` | Service binding | Internal API calls (`revalidate`, resource resolution) | | `DISPATCH` | Dispatch namespace | Fast path to deployed user workers | -| `ROUTING` | KV | AI limit flags and the platform disabled marker | +| `ROUTING` | KV | AI limit and logging keys, platform disabled marker | | `SEND_EMAIL` | send_email | Account-level outbound mail | | `JWT_SECRET` | Secret | HMAC/JWT verification | | `EMAIL_SIGNING_SECRET` | Secret | Email request proofs, credential leases, and receipts | diff --git a/platform/packages/proxy/src/ai-logging.ts b/platform/packages/proxy/src/ai-logging.ts index 0b3114388..f0004ded3 100644 --- a/platform/packages/proxy/src/ai-logging.ts +++ b/platform/packages/proxy/src/ai-logging.ts @@ -1,36 +1,104 @@ -import { isAiLoggingMode, type AiLoggingMode } from '@voidcloud/api/ai-logging-policy'; -import { deriveProxyInternalAuth, PROXY_INTERNAL_AUTH_HEADER } from '@voidcloud/api/proxy-token'; -import type { Env } from './types.ts'; +import { + AI_LOGGING_CACHE_TTL_SECONDS, + aiLoggingKey, + parsePublishedAiLogging, + type AiLoggingMode, +} from '@void/platform/ai-logging'; +import type { Context } from 'hono'; +import type { ProxyEnv } from './types.ts'; -/** Never cache a privacy policy or fall back to gateway defaults on a failed read. */ -export async function readAiLoggingMode( - env: Env, - projectId: string, - signal?: AbortSignal, -): Promise { - const response = await env.API.fetch(`https://api/internal/ai-logging/${projectId}`, { - signal, - headers: { - [PROXY_INTERNAL_AUTH_HEADER]: await deriveProxyInternalAuth( - env.JWT_SECRET, - 'ai-logging', - projectId, +export type AiLoggingRead = + | Readonly<{ ok: true; mode: AiLoggingMode }> + | Readonly<{ ok: false; response: Response }>; + +/** + * Reads the project's published AI logging mode from ROUTING KV. A missing key + * inherits the gateway setting. A failed read or an unknown value refuses the AI + * call, so an operator's choice is never silently replaced by the gateway default. + */ +export async function readAiLoggingMode(context: Context): Promise { + const projectId = context.get('projectId'); + let value: string | null; + try { + value = await context.env.ROUTING.get(aiLoggingKey(projectId), { + cacheTtl: AI_LOGGING_CACHE_TTL_SECONDS, + }); + } catch (error) { + console.error('[ai] logging setting unavailable', { + projectId, + reason: 'kv_error', + error: error instanceof Error ? error.name : typeof error, + }); + return { + ok: false, + response: context.json( + { + error: 'ai_logging_policy_unavailable', + message: + 'AI is temporarily unavailable because its logging setting could not be read. Try again shortly.', + }, + 503, + { 'Retry-After': '5' }, ), - }, - }); - if (!response.ok) { - throw new Error('AI logging policy unavailable.'); + }; } - const policy = await response.json<{ mode?: unknown }>(); - if (!policy || !isAiLoggingMode(policy.mode)) { - throw new Error('Invalid AI logging policy.'); + const mode = parsePublishedAiLogging(value); + if (mode === undefined) { + // Log the length only: the value is operator data and never echoed. + console.error('[ai] logging setting unavailable', { + projectId, + reason: 'invalid_value', + valueLength: value?.length ?? 0, + }); + return { + ok: false, + response: context.json( + { + error: 'ai_logging_policy_invalid', + message: + 'AI is unavailable because the AI logging setting for this project is not valid. Ask a platform administrator to set the AI logging setting again.', + }, + 503, + ), + }; } - return policy.mode; + return { ok: true, mode }; +} + +type LoggingControls = Readonly<{ collectLog: boolean; payload: boolean }>; + +/** + * The one place that maps a mode to AI Gateway logging controls. `null` sends + * nothing, so the gateway's own setting applies. + * + * Binding calls (`run`, `toMarkdown`) send `gateway.collectLog` plus the + * `cf-aig-collect-log-payload` extra header. Cloudflare documents only + * `collectLog` for the binding; if the payload header turns out to be ignored + * there, change `metadata` here to `{ collectLog: false, payload: false }`. + */ +const BINDING_LOGGING: Readonly> = { + inherit: null, + off: { collectLog: false, payload: false }, + metadata: { collectLog: true, payload: false }, + full: { collectLog: true, payload: true }, +}; + +/** Provider-native calls send `cf-aig-collect-log` and `cf-aig-collect-log-payload`. */ +const PROVIDER_LOGGING: Readonly> = { + inherit: null, + off: { collectLog: false, payload: false }, + metadata: { collectLog: true, payload: false }, + full: { collectLog: true, payload: true }, +}; + +export function bindingAiLogging(mode: AiLoggingMode): LoggingControls | null { + return BINDING_LOGGING[mode]; } export function applyAiLoggingHeaders(headers: Headers, mode: AiLoggingMode): void { - if (mode !== 'inherit') { - headers.set('cf-aig-collect-log', String(mode !== 'off')); - headers.set('cf-aig-collect-log-payload', String(mode === 'full')); + const controls = PROVIDER_LOGGING[mode]; + if (controls) { + headers.set('cf-aig-collect-log', String(controls.collectLog)); + headers.set('cf-aig-collect-log-payload', String(controls.payload)); } } diff --git a/platform/packages/proxy/src/ai.ts b/platform/packages/proxy/src/ai.ts index 2e484a20c..10320d7bb 100644 --- a/platform/packages/proxy/src/ai.ts +++ b/platform/packages/proxy/src/ai.ts @@ -1,8 +1,8 @@ import { isRecord } from '@void/deploy-core'; -import type { AiLoggingMode } from '@voidcloud/api/ai-logging-policy'; +import type { AiLoggingMode } from '@void/platform/ai-logging'; import { deriveAiUsageTag } from '@voidcloud/api/proxy-token'; import { Hono } from 'hono'; -import { applyAiLoggingHeaders, readAiLoggingMode } from './ai-logging.ts'; +import { applyAiLoggingHeaders, bindingAiLogging, readAiLoggingMode } from './ai-logging.ts'; import { asRecord, asString } from './body.ts'; import type { ProxyEnv } from './types.ts'; @@ -31,27 +31,6 @@ class BadRequestError extends Error {} const ai = new Hono(); -ai.use('*', async (context, next) => { - if (context.req.path === '/ai/models') { - return next(); - } - try { - context.set( - 'aiLoggingMode', - await readAiLoggingMode(context.env, context.get('projectId'), context.req.raw.signal), - ); - } catch { - return context.json( - { - error: 'ai_logging_policy_unavailable', - message: 'AI is temporarily unavailable because its logging policy could not be verified.', - }, - 503, - ); - } - await next(); -}); - function hasStreamFlag(value: unknown): value is { stream?: boolean } { return typeof value === 'object' && value !== null && 'stream' in value; } @@ -237,21 +216,22 @@ function gatewayOptions( gateway.cacheKey = projectCacheKey(projectId, gateway.cacheKey); } + const logging = bindingAiLogging(loggingMode); const result: Record = { ...options, gateway: { ...gateway, id: gatewayId, metadata: { projectId: usageTag }, - ...(loggingMode !== 'inherit' ? { collectLog: loggingMode !== 'off' } : {}), + ...(logging ? { collectLog: logging.collectLog } : {}), }, }; - if ('extraHeaders' in options || loggingMode !== 'inherit') { + if ('extraHeaders' in options || logging) { const headers = withoutKeys(asRecord(options.extraHeaders), (key) => GATEWAY_CONTROL_HEADER.test(key), ); - if (loggingMode !== 'inherit') { - headers['cf-aig-collect-log-payload'] = String(loggingMode === 'full'); + if (logging) { + headers['cf-aig-collect-log-payload'] = String(logging.payload); } result.extraHeaders = headers; } @@ -441,12 +421,16 @@ ai.post('/run', async (context) => { return context.json({ error: 'model required' }, 400); } + const logging = await readAiLoggingMode(context); + if (!logging.ok) { + return logging.response; + } const options = gatewayOptions( body.options, projectId, await deriveAiUsageTag(context.env.JWT_SECRET, projectId), context.env.AI_GATEWAY_ID ?? DEFAULT_GATEWAY_ID, - context.get('aiLoggingMode'), + logging.mode, ); try { @@ -486,9 +470,14 @@ ai.post('/provider', async (context) => { } try { + // Decode the body first so a malformed file is a 400 that never reads the policy. + const requestBody = providerRequestBody(providerBody(body.body)); + const logging = await readAiLoggingMode(context); + if (!logging.ok) { + return logging.response; + } const gateway = context.env.AI.gateway(context.env.AI_GATEWAY_ID ?? DEFAULT_GATEWAY_ID); const baseUrl = await gateway.getUrl(provider); - const requestBody = providerRequestBody(providerBody(body.body)); const headers = applyProviderHeaders({ headers: headersFromRecord(body.headers), provider, @@ -498,7 +487,7 @@ ai.post('/provider', async (context) => { apiKeyPrefix, contentType: requestBody.contentType, }); - applyAiLoggingHeaders(headers, context.get('aiLoggingMode')); + applyAiLoggingHeaders(headers, logging.mode); const response = await fetch(gatewayEndpointUrl(baseUrl, path), { method, headers, @@ -543,12 +532,16 @@ ai.post('/models', async (context) => { ai.post('/toMarkdown', async (context) => { const body = context.get('body'); const projectId = context.get('projectId'); + const logging = await readAiLoggingMode(context); + if (!logging.ok) { + return logging.response; + } const options = gatewayOptions( body.options, projectId, await deriveAiUsageTag(context.env.JWT_SECRET, projectId), context.env.AI_GATEWAY_ID ?? DEFAULT_GATEWAY_ID, - context.get('aiLoggingMode'), + logging.mode, ); try { const result = await context.env.AI.toMarkdown(body.inputs, options); diff --git a/platform/packages/proxy/src/types.ts b/platform/packages/proxy/src/types.ts index 13d08aacb..115291a5b 100644 --- a/platform/packages/proxy/src/types.ts +++ b/platform/packages/proxy/src/types.ts @@ -1,5 +1,3 @@ -import type { AiLoggingMode } from '@voidcloud/api/ai-logging-policy'; - export type AiGatewayRequest = Readonly<{ provider: string; endpoint: string; @@ -76,5 +74,5 @@ export type JwtPayload = Readonly<{ export type ProxyEnv = Readonly<{ Bindings: Env; - Variables: { projectId: string; body: ProxyBody; aiLoggingMode: AiLoggingMode }; + Variables: { projectId: string; body: ProxyBody }; }>; diff --git a/platform/packages/proxy/test/unit/proxy.test.ts b/platform/packages/proxy/test/unit/proxy.test.ts index a716c53f8..a6266cbda 100644 --- a/platform/packages/proxy/test/unit/proxy.test.ts +++ b/platform/packages/proxy/test/unit/proxy.test.ts @@ -123,27 +123,13 @@ function createMockApi( }); } - if (url.includes('/internal/ai-logging/')) { - return Response.json({ mode: 'inherit' }); - } - // Default: generic success response return new Response(JSON.stringify({ purged: 1 }), { headers: { 'content-type': 'application/json' }, }); }; - return { - fetch: handler - ? async (input: string | Request, init?: RequestInit) => { - const url = typeof input === 'string' ? input : input.url; - if (url.includes('/internal/ai-logging/')) { - return Response.json({ mode: 'inherit' }); - } - return handler(input, init); - } - : defaultHandler, - }; + return { fetch: vi.fn(handler ?? defaultHandler) }; } function createEnv( @@ -752,7 +738,7 @@ describe('proxy worker', () => { env, ); expect(allowed.status).toBe(200); - expect(apiFetch).toHaveBeenCalledTimes(2); + expect(apiFetch).toHaveBeenCalledTimes(1); expect(String(apiFetch.mock.calls[0]?.[0])).toContain( '/internal/verify-prerender-build/proj_000000000001', ); @@ -770,7 +756,7 @@ describe('proxy worker', () => { error: 'forbidden', message: expect.stringMatching(/does not match.*Restart the build/), }); - expect(apiFetch).toHaveBeenCalledTimes(2); + expect(apiFetch).toHaveBeenCalledTimes(1); expect(env.AI.run).toHaveBeenCalledTimes(1); }); @@ -1502,27 +1488,91 @@ describe('proxy worker', () => { }); describe('operator-controlled AI logging', () => { + const PROJECT = 'proj_000000000042'; + const POLICY_KEY = `ai-logging:${PROJECT}`; + const AI_LOGGING_PATHS = ['/ai/run', '/ai/toMarkdown', '/ai/provider'] as const; + + function aiBody(path: string, extra: Record = {}) { + const base: Record = + path === '/ai/provider' + ? { provider: 'openai', providerKey: 'test-key', path: 'chat/completions', body: {} } + : { model: 'm', inputs: {} }; + return { projectId: PROJECT, aiToken: aiTokens[PROJECT], ...base, ...extra }; + } + + function loggingEnv(kvData: Record = {}) { + const env = createEnv( + { + gateway: vi.fn(() => ({ + getUrl: async () => 'https://gateway.test/v1/account/void/openai', + run: vi.fn(), + })), + }, + kvData, + ); + const upstream = vi.fn(async () => Response.json({ ok: true })); + vi.stubGlobal('fetch', upstream); + return { env, upstream }; + } + + function policyReads(env: ReturnType) { + return env.ROUTING.get.mock.calls.filter(([key]) => String(key).startsWith('ai-logging:')); + } + + function apiPolicyCalls(env: ReturnType) { + return (env.API.fetch as ReturnType).mock.calls.filter(([input]) => + String(typeof input === 'string' ? input : input.url).includes('/internal/ai-logging/'), + ); + } + + it.each(AI_LOGGING_PATHS)( + 'reads the policy for %s from ROUTING with a 30 second cache and never from the API', + async (path) => { + const { env } = loggingEnv({ [POLICY_KEY]: 'off' }); + const response = await worker.fetch(post(path, aiBody(path)), env); + expect(response.status).toBe(200); + expect(policyReads(env)).toEqual([[POLICY_KEY, { cacheTtl: 30 }]]); + expect(apiPolicyCalls(env)).toEqual([]); + }, + ); + + it('inherits the gateway setting when no policy is published', async () => { + const { env, upstream } = loggingEnv(); + for (const path of AI_LOGGING_PATHS) { + const response = await worker.fetch(post(path, aiBody(path)), env); + expect(response.status).toBe(200); + } + for (const method of [env.AI.run, env.AI.toMarkdown]) { + const options = method.mock.calls[0]!.at(-1) as Record; + expect(options.gateway).toStrictEqual({ + id: 'void', + metadata: { projectId: usageTags[PROJECT] }, + }); + expect(options).not.toHaveProperty('extraHeaders'); + } + const headers = new Headers(upstream.mock.calls[0]![1]!.headers); + expect([...headers.keys()].filter((name) => name.startsWith('cf-aig-'))).toEqual([]); + expect(apiPolicyCalls(env)).toEqual([]); + }); + it('strips logging controls from binding session headers as well as request headers', async () => { - const env = createEnv(undefined, undefined, { - fetch: vi.fn(async () => Response.json({ mode: 'metadata' })), - }); + const { env } = loggingEnv({ [POLICY_KEY]: 'metadata' }); await worker.fetch( - post('/ai/run', { - projectId: 'proj_000000000042', - aiToken: aiTokens['proj_000000000042'], - model: 'm', - inputs: {}, - options: { - sessionOptions: { - extraHeaders: { - 'CF-AIG-Collect-Log': 'false', - 'cf-aig-collect-log-payload': 'true', - 'cf-aig-metadata': '{"projectId":"forged"}', - 'x-keep': 'session-header', + post( + '/ai/run', + aiBody('/ai/run', { + options: { + sessionOptions: { + extraHeaders: { + 'CF-AIG-Collect-Log': 'false', + 'cf-aig-collect-log-payload': 'true', + 'cf-aig-metadata': '{"projectId":"forged"}', + 'x-keep': 'session-header', + }, }, }, - }, - }), + }), + ), env, ); expect(env.AI.run).toHaveBeenCalledWith( @@ -1534,99 +1584,173 @@ describe('proxy worker', () => { }), ); }); - it.each(['off', 'metadata', 'full'])( - 'enforces %s logging for inference and Markdown conversion', - async (mode) => { - const api = { fetch: vi.fn(async () => Response.json({ mode })) }; - const env = createEnv(undefined, undefined, api); + + it.each([ + { mode: 'off', collectLog: false, payload: 'false' }, + { mode: 'metadata', collectLog: true, payload: 'false' }, + { mode: 'full', collectLog: true, payload: 'true' }, + ])( + 'enforces $mode logging for inference and Markdown conversion', + async ({ mode, collectLog, payload }) => { + const { env } = loggingEnv({ [POLICY_KEY]: mode }); for (const path of ['/ai/run', '/ai/toMarkdown']) { const response = await worker.fetch( - post(path, { - projectId: 'proj_000000000042', - aiToken: aiTokens['proj_000000000042'], - model: 'm', - inputs: {}, - options: { - gateway: { collectLog: mode === 'off', metadata: { projectId: 'forged' } }, - extraHeaders: { - 'CF-AIG-Collect-Log-Payload': 'true', - 'cf-aig-collect-log': 'true', - 'x-keep': 'yes', + post( + path, + aiBody(path, { + options: { + gateway: { collectLog: !collectLog, collectLogPayload: true }, + extraHeaders: { + 'CF-AIG-Collect-Log-Payload': 'true', + 'cf-aig-collect-log': 'true', + 'x-keep': 'yes', + }, }, - }, - }), + }), + ), env, ); expect(response.status).toBe(200); } for (const method of [env.AI.run, env.AI.toMarkdown]) { - const options = method.mock.calls[0]!.at(-1); - expect(options).toMatchObject({ - gateway: { - collectLog: mode !== 'off', - metadata: { projectId: usageTags['proj_000000000042'] }, - }, - extraHeaders: { - 'cf-aig-collect-log-payload': String(mode === 'full'), - 'x-keep': 'yes', - }, + const options = method.mock.calls[0]!.at(-1) as Record; + expect(options.gateway).toStrictEqual({ + id: 'void', + metadata: { projectId: usageTags[PROJECT] }, + collectLog, + }); + expect(options.extraHeaders).toStrictEqual({ + 'cf-aig-collect-log-payload': payload, + 'x-keep': 'yes', }); } - expect(api.fetch).toHaveBeenCalledTimes(2); }, ); - it.each(['off', 'metadata', 'full'])('enforces %s logging for provider calls', async (mode) => { - const env = createEnv( - { - gateway: vi.fn(() => ({ - getUrl: async () => 'https://gateway.test/v1/account/void/openai', - run: vi.fn(), - })), - }, - undefined, - { fetch: vi.fn(async () => Response.json({ mode })) }, - ); - const request = vi.spyOn(globalThis, 'fetch').mockResolvedValue(Response.json({ ok: true })); + it.each([ + { mode: 'off', collectLog: 'false', payload: 'false' }, + { mode: 'metadata', collectLog: 'true', payload: 'false' }, + { mode: 'full', collectLog: 'true', payload: 'true' }, + ])('enforces $mode logging for provider calls', async ({ mode, collectLog, payload }) => { + const { env, upstream } = loggingEnv({ [POLICY_KEY]: mode }); const response = await worker.fetch( - post('/ai/provider', { - projectId: 'proj_000000000042', - aiToken: aiTokens['proj_000000000042'], - provider: 'openai', - providerKey: 'test-key', - path: 'chat/completions', - body: {}, - headers: { 'CF-AIG-Collect-Log': 'true', 'cf-aig-collect-log-payload': 'true' }, - }), + post( + '/ai/provider', + aiBody('/ai/provider', { + headers: { 'CF-AIG-Collect-Log': 'true', 'cf-aig-collect-log-payload': 'true' }, + }), + ), env, ); expect(response.status).toBe(200); - const headers = new Headers(request.mock.calls[0]![1]!.headers); - expect(headers.get('cf-aig-collect-log')).toBe(String(mode !== 'off')); - expect(headers.get('cf-aig-collect-log-payload')).toBe(String(mode === 'full')); + const headers = new Headers(upstream.mock.calls[0]![1]!.headers); + expect([...headers].filter(([name]) => name.startsWith('cf-aig-'))).toStrictEqual([ + ['cf-aig-collect-log', collectLog], + ['cf-aig-collect-log-payload', payload], + ]); }); - it.each([null, { mode: 'invalid' }, { mode: false }])( - 'refuses inference if the saved policy cannot be verified: %j', - async (policy) => { - const env = createEnv(undefined, undefined, { - fetch: vi.fn(async () => - policy === null ? new Response(null, { status: 503 }) : Response.json(policy), - ), + it.each(AI_LOGGING_PATHS)( + 'refuses %s with a retryable 503 when the policy cannot be read', + async (path) => { + const { env, upstream } = loggingEnv(); + const routingGet = env.ROUTING.get.getMockImplementation()!; + env.ROUTING.get.mockImplementation(async (key: string) => { + if (key.startsWith('ai-logging:')) { + throw new TypeError('kv unavailable'); + } + return routingGet(key); }); - const response = await worker.fetch( - post('/ai/run', { - projectId: 'proj_000000000042', - aiToken: aiTokens['proj_000000000042'], - model: 'm', - inputs: {}, - }), - env, - ); - expect(response.status).toBe(503); + const logged = vi.spyOn(console, 'error').mockImplementation(() => {}); + try { + const response = await worker.fetch(post(path, aiBody(path)), env); + expect(response.status).toBe(503); + expect(response.headers.get('retry-after')).toBe('5'); + expect(await response.json()).toMatchObject({ error: 'ai_logging_policy_unavailable' }); + expect(logged).toHaveBeenCalledWith('[ai] logging setting unavailable', { + projectId: PROJECT, + reason: 'kv_error', + error: 'TypeError', + }); + } finally { + logged.mockRestore(); + } expect(env.AI.run).not.toHaveBeenCalled(); + expect(env.AI.toMarkdown).not.toHaveBeenCalled(); + expect(env.AI.gateway).not.toHaveBeenCalled(); + expect(upstream).not.toHaveBeenCalled(); }, ); + + it.each( + ['inherit', 'bogus', '', 'OFF', ' off'].flatMap((value) => + AI_LOGGING_PATHS.map((path) => ({ value, label: JSON.stringify(value), path })), + ), + )('refuses $path when the published value is $label', async ({ value, path }) => { + const { env, upstream } = loggingEnv({ [POLICY_KEY]: value }); + const logged = vi.spyOn(console, 'error').mockImplementation(() => {}); + try { + const response = await worker.fetch(post(path, aiBody(path)), env); + expect(response.status).toBe(503); + expect(response.headers.get('retry-after')).toBeNull(); + expect(await response.json()).toMatchObject({ error: 'ai_logging_policy_invalid' }); + expect(logged).toHaveBeenCalledWith('[ai] logging setting unavailable', { + projectId: PROJECT, + reason: 'invalid_value', + valueLength: value.length, + }); + // The value itself is never logged. + for (const call of logged.mock.calls) { + expect(JSON.stringify(call)).not.toContain('bogus'); + } + } finally { + logged.mockRestore(); + } + expect(env.AI.run).not.toHaveBeenCalled(); + expect(env.AI.toMarkdown).not.toHaveBeenCalled(); + expect(upstream).not.toHaveBeenCalled(); + }); + + it.each([ + { name: '/ai/models', path: '/ai/models', body: { inputs: {} }, status: 200 }, + { name: 'an unknown AI route', path: '/ai/foo', body: {}, status: 404 }, + { name: '/ai/run without a model', path: '/ai/run', body: { inputs: {} }, status: 400 }, + { + name: '/ai/provider without a provider', + path: '/ai/provider', + body: { path: 'x' }, + status: 400, + }, + { + name: '/ai/provider with an unsafe path', + path: '/ai/provider', + status: 400, + body: { provider: 'openai', providerKey: 'k', path: '../escape' }, + }, + { + name: '/ai/provider with malformed file data', + path: '/ai/provider', + status: 400, + body: { + provider: 'openai', + providerKey: 'k', + path: 'files', + body: { + type: 'form', + entries: [{ name: 'file', value: { __voidFile: true, data: '%%%' } }], + }, + }, + }, + ])('never reads the policy for $name', async ({ path, body, status }) => { + const { env } = loggingEnv({ [POLICY_KEY]: 'bogus' }); + const response = await worker.fetch( + post(path, { projectId: PROJECT, aiToken: aiTokens[PROJECT], ...body }), + env, + ); + expect(response.status).toBe(status); + expect(policyReads(env)).toEqual([]); + expect(apiPolicyCalls(env)).toEqual([]); + }); }); describe('AI: /ai/run', () => { diff --git a/platform/scripts/ai-logging-live-check.ts b/platform/scripts/ai-logging-live-check.ts new file mode 100644 index 000000000..71fd0da5c --- /dev/null +++ b/platform/scripts/ai-logging-live-check.ts @@ -0,0 +1,309 @@ +/** + * Live checks for the AI Gateway logging modes (design doc 0094, checks A and B). + * Run by hand against a scratch Cloudflare account before a release; not in CI. + * + * CLOUDFLARE_ACCOUNT_ID=... CLOUDFLARE_API_TOKEN=... AI_LOGGING_CHECK_GATEWAY=... \ + * node platform/scripts/ai-logging-live-check.ts + * + * The gateway must be a scratch gateway with request logging turned on, so a call + * that sends no logging option is logged. The token needs Workers Scripts Edit, + * Workers AI Read, AI Gateway Read and Account Analytics Read. The script uploads a + * temporary Worker named `void-ai-logging-check-