Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): flag payload transport, in-app deep-link dispatch, version comparator (#78660)

Adam Bowker8877ead77679
diff --git a/products/desktop/apps/code/.storybook/withAppProviders.tsx b/products/desktop/apps/code/.storybook/withAppProviders.tsx
index aa006e31cc38..2f1d65fac9fe 100644
--- a/products/desktop/apps/code/.storybook/withAppProviders.tsx
+++ b/products/desktop/apps/code/.storybook/withAppProviders.tsx
@@ -152,6 +152,7 @@ function createProviderStack(): ProviderStack {
// every flag reads as enabled and useFeatureFlag's state never settles.
bindings.bind<FeatureFlags>(FEATURE_FLAGS).toConstantValue({
isEnabled: () => false,
+ getPayload: () => undefined,
onFlagsLoaded: () => () => {},
});
const container = storyContainer(bindings);
diff --git a/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts b/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts
index d3aee30baafc..f78eaa7310dc 100644
--- a/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts
+++ b/products/desktop/apps/code/src/renderer/platform-adapters/updates.ts
@@ -169,12 +169,29 @@ function maybeShowWhatsNew(): void {
);
}
+// The changelog defers to flag-driven surfaces (billing announcement, remote
+// announcements), so wait for flags before auto-opening — otherwise it can
+// open and immediately vanish behind an announcement that arrives with the
+// flag payload. The timeout keeps offline and keyless dev builds working.
+const FLAGS_SETTLE_TIMEOUT_MS = 3_000;
+
+function maybeShowWhatsNewOnceFlagsSettle(): void {
+ let evaluated = false;
+ const evaluate = () => {
+ if (evaluated) return;
+ evaluated = true;
+ maybeShowWhatsNew();
+ };
+ posthogFeatureFlags.onFlagsLoaded(evaluate);
+ setTimeout(evaluate, FLAGS_SETTLE_TIMEOUT_MS);
+}
+
function onSettingsReady(): void {
syncAutoDownload(useSettingsStore.getState().downloadUpdatesAutomatically);
useSettingsStore.subscribe((state) =>
syncAutoDownload(state.downloadUpdatesAutomatically),
);
- maybeShowWhatsNew();
+ maybeShowWhatsNewOnceFlagsSettle();
}
if (useSettingsStore.persist.hasHydrated()) {
diff --git a/products/desktop/apps/web/src/web-container.ts b/products/desktop/apps/web/src/web-container.ts
index 687426f07194..23cf5821417b 100644
--- a/products/desktop/apps/web/src/web-container.ts
+++ b/products/desktop/apps/web/src/web-container.ts
@@ -511,6 +511,7 @@ container.bind(FEATURE_FLAGS).toConstantValue({
// same behavior as the old stub, but real flags light up once a key is set.
isEnabled: (flagKey: string) =>
flagKey === SYNC_CLOUD_TASKS_FLAG || posthogFeatureFlags.isEnabled(flagKey),
+ getPayload: posthogFeatureFlags.getPayload,
onFlagsLoaded: posthogFeatureFlags.onFlagsLoaded,
});
diff --git a/products/desktop/packages/core/src/updates/updates.test.ts b/products/desktop/packages/core/src/updates/updates.test.ts
index f4e942d57fee..389383e7e6e4 100644
--- a/products/desktop/packages/core/src/updates/updates.test.ts
+++ b/products/desktop/packages/core/src/updates/updates.test.ts
@@ -105,7 +105,8 @@ const {
};
});
-import { isVersionNewer, UpdatesService } from "./updates";
+import { UpdatesService } from "./updates";
+import { isVersionNewer } from "./version";
function injectPorts(service: UpdatesService): void {
const s = service as unknown as Record<string, unknown>;
diff --git a/products/desktop/packages/core/src/updates/updates.ts b/products/desktop/packages/core/src/updates/updates.ts
index d7c7c4d5dbde..fec6e33cd281 100644
--- a/products/desktop/packages/core/src/updates/updates.ts
+++ b/products/desktop/packages/core/src/updates/updates.ts
@@ -29,25 +29,9 @@ import {
type UpdatesStatusPayload,
} from "./schemas";
-type CheckSource = "user" | "periodic";
-
-function versionTriple(version: string): number[] {
- return version
- .replace(/^v/, "")
- .split(".", 3)
- .map((segment) => Number.parseInt(segment, 10) || 0);
-}
+import { isVersionNewer } from "./version";
-export function isVersionNewer(candidate: string, current: string): boolean {
- const a = versionTriple(candidate);
- const b = versionTriple(current);
- for (let i = 0; i < 3; i++) {
- if ((a[i] ?? 0) !== (b[i] ?? 0)) {
- return (a[i] ?? 0) > (b[i] ?? 0);
- }
- }
- return false;
-}
+type CheckSource = "user" | "periodic";
type UpdateState =
| "idle"
| "checking"
diff --git a/products/desktop/packages/core/src/updates/version.ts b/products/desktop/packages/core/src/updates/version.ts
new file mode 100644
index 000000000000..3f6b990f8c3f
--- /dev/null
+++ b/products/desktop/packages/core/src/updates/version.ts
@@ -0,0 +1,17 @@
+function versionTriple(version: string): number[] {
+ return version
+ .replace(/^v/, "")
+ .split(".", 3)
+ .map((segment) => Number.parseInt(segment, 10) || 0);
+}
+
+export function isVersionNewer(candidate: string, current: string): boolean {
+ const a = versionTriple(candidate);
+ const b = versionTriple(current);
+ for (let i = 0; i < 3; i++) {
+ if ((a[i] ?? 0) !== (b[i] ?? 0)) {
+ return (a[i] ?? 0) > (b[i] ?? 0);
+ }
+ }
+ return false;
+}
diff --git a/products/desktop/packages/host-router/src/routers/deep-link.router.ts b/products/desktop/packages/host-router/src/routers/deep-link.router.ts
index 9d8703565e88..fb951c5827dc 100644
--- a/products/desktop/packages/host-router/src/routers/deep-link.router.ts
+++ b/products/desktop/packages/host-router/src/routers/deep-link.router.ts
@@ -54,9 +54,25 @@ import {
type TaskLinkService,
} from "@posthog/core/links/task-link";
import { publicProcedure, router } from "@posthog/host-trpc/trpc";
+import {
+ DEEP_LINK_SERVICE,
+ type IDeepLinkRegistry,
+} from "@posthog/platform/deep-link";
import type { NotificationTarget } from "@posthog/platform/notifications";
+import { z } from "zod";
export const deepLinkRouter = router({
+ // In-app surfaces (announcement CTAs) dispatch posthog-code:// urls through
+ // the same main-process handler OS-delivered links use — no OS round-trip,
+ // no browser bounce, and dev builds (posthog-code-dev scheme) stay in-app.
+ open: publicProcedure
+ .input(z.object({ url: z.string() }))
+ .mutation(({ ctx, input }) =>
+ ctx.container
+ .get<IDeepLinkRegistry>(DEEP_LINK_SERVICE)
+ .handleUrl(input.url),
+ ),
+
onOpenTask: publicProcedure.subscription(async function* (opts) {
const service = opts.ctx.container.get<TaskLinkService>(TASK_LINK_SERVICE);
const iterable = service.toIterable(TaskLinkEvent.OpenTask, {
diff --git a/products/desktop/packages/platform/src/deep-link.ts b/products/desktop/packages/platform/src/deep-link.ts
index 70147eed12cd..1c12c6eca407 100644
--- a/products/desktop/packages/platform/src/deep-link.ts
+++ b/products/desktop/packages/platform/src/deep-link.ts
@@ -7,6 +7,13 @@ export interface IDeepLinkRegistry {
registerHandler(key: string, handler: DeepLinkHandler): void;
unregisterHandler(key: string): void;
getProtocol(): string;
+ /**
+ * Dispatch a deep-link URL through the registered handlers — the same path
+ * OS-delivered links take, callable from in-app surfaces without an OS hop.
+ * Lives on the platform interface because host-router forwards to it
+ * (deepLink.open) and cannot import the host's own service token.
+ */
+ handleUrl(url: string): boolean;
}
export const DEEP_LINK_SERVICE = Symbol.for("posthog.platform.deepLink");
diff --git a/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts b/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts
index cb1e9411e454..a5aedd4154d4 100644
--- a/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts
+++ b/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts
@@ -5,6 +5,12 @@
*/
export interface FeatureFlags {
isEnabled(flagKey: string): boolean;
+ /**
+ * Remote JSON payload attached to a matched flag; undefined when the flag
+ * is unmatched or flags haven't loaded. Validate with Zod at the
+ * consumption boundary — the shape is whatever was typed into PostHog.
+ */
+ getPayload(flagKey: string): unknown;
onFlagsLoaded(handler: () => void): () => void;
}
diff --git a/products/desktop/packages/ui/src/features/feature-flags/useFeatureFlagPayload.ts b/products/desktop/packages/ui/src/features/feature-flags/useFeatureFlagPayload.ts
new file mode 100644
index 000000000000..422612894e5d
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/feature-flags/useFeatureFlagPayload.ts
@@ -0,0 +1,20 @@
+import { useService } from "@posthog/di/react";
+import { useEffect, useState } from "react";
+import { FEATURE_FLAGS, type FeatureFlags } from "./identifiers";
+
+export function useFeatureFlagPayload(flagKey: string): unknown {
+ const flags = useService<FeatureFlags>(FEATURE_FLAGS);
+ const [payload, setPayload] = useState<unknown>(() =>
+ flags.getPayload(flagKey),
+ );
+
+ useEffect(() => {
+ setPayload(flags.getPayload(flagKey));
+
+ return flags.onFlagsLoaded(() => {
+ setPayload(flags.getPayload(flagKey));
+ });
+ }, [flags, flagKey]);
+
+ return payload;
+}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx
index 6d5f0bf51acd..e1667248a761 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx
@@ -13,6 +13,7 @@ import { UserMessage } from "./UserMessage";
function renderWithFlags(node: ReactNode, bluebirdEnabled: boolean) {
const flags: FeatureFlags = {
isEnabled: () => bluebirdEnabled,
+ getPayload: () => undefined,
onFlagsLoaded: () => () => {},
};
const container = new Container();
diff --git a/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts b/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
index d2ae875d32ec..bbdcc88aea6c 100644
--- a/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
+++ b/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
@@ -374,6 +374,18 @@ export function onFeatureFlagsLoaded(callback: () => void): () => void {
};
}
+/**
+ * Remote JSON payload for a matched flag; undefined when uninitialized or
+ * unmatched. posthog-js returns the decoded value, not the raw string.
+ */
+export function getFeatureFlagPayload(flagKey: string): unknown {
+ if (!isInitialized) {
+ return undefined;
+ }
+
+ return posthog.getFeatureFlagPayload(flagKey);
+}
+
/**
* Reload feature flags from the server.
* Useful after a person property change (e.g., invite code redemption).
@@ -405,6 +417,7 @@ export const posthogAnalyticsTracker: AnalyticsTracker = {
*/
export const posthogFeatureFlags: FeatureFlags = {
isEnabled: isFeatureFlagEnabled,
+ getPayload: getFeatureFlagPayload,
onFlagsLoaded: onFeatureFlagsLoaded,
};