diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c5619f..b1d4177f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable user-visible changes are recorded here. Versions follow [Semantic Ve ## Unreleased +### Fixed + +- `npm run deploy:production` refuses a config that does not set + `POSTHOG_ENABLED` to `"0"` or `"1"`. Since 0.23.1 the relay has been + deployed with a config that left the flag out, and because Wrangler replaces + every Worker variable on deploy, relay analytics (downloads, installs, + sessions, viewers and MCP results) silently stopped on 23 September. The + accounts app was unaffected because its flag is committed. Production needs + `"POSTHOG_ENABLED": "1"` in `wrangler.production.jsonc` and a redeploy to + restore it. + ## [0.23.3] — 2026-09-25 ### Fixed diff --git a/docs/self-hosting.md b/docs/self-hosting.md index ee30ad38..e4bc3bad 100644 --- a/docs/self-hosting.md +++ b/docs/self-hosting.md @@ -70,7 +70,10 @@ Objects, Rate Limiting, Analytics Engine, and static assets. Keep every documentation path in `run_worker_first`: a page served straight from the assets binding is never counted. `npm run deploy:production` refuses a production config that routes fewer of these paths through the Worker than -`wrangler.example.jsonc` does. +`wrangler.example.jsonc` does, or one that does not set `POSTHOG_ENABLED` to +`"0"` or `"1"`. Wrangler replaces every Worker variable on deploy, so a config +that leaves the flag out turns relay analytics off without any error. The +example keeps it `"0"`; a self-hosted relay sends nothing to PostHog. The private statistics dashboard is optional and configured with Worker secrets (`npx wrangler secret put `): diff --git a/scripts/deploy-production.mjs b/scripts/deploy-production.mjs index 6e4b2e09..343ae67d 100644 --- a/scripts/deploy-production.mjs +++ b/scripts/deploy-production.mjs @@ -25,6 +25,12 @@ export function validateProductionConfig(config) { !["0", "1"].includes(config.vars?.MCP_CONTROL_ENABLED)) { throw new Error("production target, pinned account, or explicit control gate is invalid"); } + // Wrangler replaces every Worker var on deploy. A config that omits the flag + // silently turns relay analytics off (installs, sessions, viewers, MCP), so + // the choice must be written down, the same way as the control gate. + if (!["0", "1"].includes(config.vars?.POSTHOG_ENABLED)) { + throw new Error("production config must set vars.POSTHOG_ENABLED to \"0\" or \"1\""); + } } export function deployProduction({ argv = [], configPath = resolve("wrangler.production.jsonc"), executor } = {}) { diff --git a/tests/production-deploy.test.ts b/tests/production-deploy.test.ts index 7565e2fd..1f29d113 100644 --- a/tests/production-deploy.test.ts +++ b/tests/production-deploy.test.ts @@ -9,7 +9,7 @@ const valid = () => ({ name: "shell-online", account_id: "a".repeat(32), compatibility_flags: ["enable_request_signal"], routes: [{ pattern: "shell.online" }, { pattern: "stats.shell.online" }], - vars: { MCP_CONTROL_ENABLED: "0" }, + vars: { MCP_CONTROL_ENABLED: "0", POSTHOG_ENABLED: "1" }, }); describe("production deploy guard", () => { it("refuses an older or unknown release identity", () => { @@ -21,7 +21,17 @@ describe("production deploy guard", () => { }); it("accepts the explicit production target with either control state", () => { expect(() => validateProductionConfig(valid())).not.toThrow(); - expect(() => validateProductionConfig({ ...valid(), vars: { MCP_CONTROL_ENABLED: "1" } })).not.toThrow(); + expect(() => validateProductionConfig({ ...valid(), vars: { MCP_CONTROL_ENABLED: "1", POSTHOG_ENABLED: "1" } })).not.toThrow(); + }); + it("accepts relay analytics explicitly on or off", () => { + expect(() => validateProductionConfig({ ...valid(), vars: { MCP_CONTROL_ENABLED: "0", POSTHOG_ENABLED: "0" } })).not.toThrow(); + }); + // Regression: 0.23.1 deployed with a config that omitted the flag, and every + // relay event stopped reaching PostHog while the accounts app kept reporting. + it.each([undefined, "", "true", "yes", 1])("refuses a config whose relay analytics flag is %s", (value) => { + const vars: Record = { MCP_CONTROL_ENABLED: "0" }; + if (value !== undefined) vars.POSTHOG_ENABLED = value; + expect(() => validateProductionConfig({ ...valid(), vars })).toThrow("POSTHOG_ENABLED"); }); it.each([ { name: "shell-online-staging" }, { account_id: undefined }, { routes: [] }, diff --git a/wrangler.example.jsonc b/wrangler.example.jsonc index 58cc9dc5..85de4c8c 100644 --- a/wrangler.example.jsonc +++ b/wrangler.example.jsonc @@ -4,7 +4,7 @@ "main": "./worker/index.ts", "compatibility_date": "2026-08-19", "compatibility_flags": ["enable_request_signal"], - "vars": { "MCP_CONTROL_ENABLED": "0" }, + "vars": { "MCP_CONTROL_ENABLED": "0", "POSTHOG_ENABLED": "0" }, "workers_dev": true, "assets": { "directory": "./dist",