Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion docs/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NAME>`):
Expand Down
6 changes: 6 additions & 0 deletions scripts/deploy-production.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {}) {
Expand Down
14 changes: 12 additions & 2 deletions tests/production-deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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<string, unknown> = { 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: [] },
Expand Down
2 changes: 1 addition & 1 deletion wrangler.example.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading