: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): name the project timezone on scout cadences (#98640)
posthog[bot]e74aaaa451a8
diff --git a/products/desktop/packages/core/src/scouts/scoutPresentation.test.ts b/products/desktop/packages/core/src/scouts/scoutPresentation.test.tsindex 2d46dc026711..cbade8982fa0 100644--- a/products/desktop/packages/core/src/scouts/scoutPresentation.test.ts+++ b/products/desktop/packages/core/src/scouts/scoutPresentation.test.ts@@ -34,6 +34,7 @@ import {scoutCreatorKey,scoutCronScheduleError,scoutRunOutcomeLabel,+ scoutScheduleNamesClockTime,sortConfigsForDisplay,summarizeRunWindow,weeklyCronToDayTime,@@ -751,6 +752,26 @@ describe("schedule modes", () => {).toBe(expected);});+ it.each([+ ["a rolling interval", null, 1440, false],+ ["an hourly interval", null, 60, false],+ ["a plain daily cron", "0 9 * * *", 1440, true],+ ["a weekly cron", "30 8 * * 4", 1440, true],+ ["a cron the presets cannot name", "0 9 * * 1-5", 1440, true],+ ["a cron stepped by the hour", "0 */3 * * *", 1440, true],+ ["a cron running through the day", "*/30 * * * *", 1440, false],+ ])(+ "tells whether %s states a clock time",+ (_label, cron, minutes, expected) => {+ expect(+ scoutScheduleNamesClockTime({+ run_interval_minutes: minutes as number,+ run_cron_schedule: cron as string | null,+ }),+ ).toBe(expected);+ },+ );+it.each([["a rolling interval", null, "1440"],["a plain daily cron", "0 9 * * *", SCOUT_DAILY_AT_SCHEDULE_MODE],diff --git a/products/desktop/packages/core/src/scouts/scoutPresentation.ts b/products/desktop/packages/core/src/scouts/scoutPresentation.tsindex 0a91e1ff7c1f..9c31d5840f53 100644--- a/products/desktop/packages/core/src/scouts/scoutPresentation.ts+++ b/products/desktop/packages/core/src/scouts/scoutPresentation.ts@@ -1000,6 +1000,17 @@ export function formatScoutScheduleShort(config: ScoutScheduleFields): string {return formatRunIntervalShort(config.run_interval_minutes);}+/**+ * Whether the schedule picks hours of the day, and so needs the project timezone said next to it.+ * A stepped hour field counts, because it anchors on midnight in the project timezone.+ */+export function scoutScheduleNamesClockTime(+ config: ScoutScheduleFields,+): boolean {+ const hours = config.run_cron_schedule?.trim().split(/\s+/)[1];+ return hours !== undefined && hours !== "*";+}+/*** Enabled scouts first, then the ones the system switched off (they need a* human to switch them back on, so they lead the off-block), then the restdiff --git a/products/desktop/packages/core/src/scouts/scoutSuggestions.test.ts b/products/desktop/packages/core/src/scouts/scoutSuggestions.test.tsindex 0e80084c8225..031d60a961cf 100644--- a/products/desktop/packages/core/src/scouts/scoutSuggestions.test.ts+++ b/products/desktop/packages/core/src/scouts/scoutSuggestions.test.ts@@ -30,6 +30,25 @@ describe("suggestionMetaLine", () => {])("reads back %s", (_name, config, expected) => {expect(suggestionMetaLine(config)).toBe(expected);});++ it.each([+ [+ "a clock time",+ {+ run_cron_schedule: "0 9 * * *",+ run_interval_minutes: null,+ emit: true,+ },+ "Runs daily at 09:00 (PST) · sends what it finds to Self-driving",+ ],+ [+ "a rolling interval",+ { run_cron_schedule: null, run_interval_minutes: 180, emit: true },+ "Runs every 3h · sends what it finds to Self-driving",+ ],+ ])("names the project timezone beside %s", (_name, config, expected) => {+ expect(suggestionMetaLine(config, "PST")).toBe(expected);+ });});describe("suggestionBrief", () => {diff --git a/products/desktop/packages/core/src/scouts/scoutSuggestions.ts b/products/desktop/packages/core/src/scouts/scoutSuggestions.tsindex 8e13fb7b6f53..be111e4c7cdd 100644--- a/products/desktop/packages/core/src/scouts/scoutSuggestions.ts+++ b/products/desktop/packages/core/src/scouts/scoutSuggestions.ts@@ -2,30 +2,39 @@ import type {ScoutSuggestionItem,ScoutSuggestionProposedConfig,} from "@posthog/api-client/posthog-client";-import { formatScoutScheduleShort } from "./scoutPresentation";+import {+ formatScoutScheduleShort,+ scoutScheduleNamesClockTime,+} from "./scoutPresentation";/** Minutes between runs for a suggestion that names no schedule of its own. */export const DEFAULT_SUGGESTION_INTERVAL_MINUTES = 1440;-/** How often the suggested agent would run, in the roster's own words. */+/** How often the suggested agent would run, in the roster's own words and project timezone. */export function suggestionCadenceLabel(config: ScoutSuggestionProposedConfig,+ timezoneAbbreviation?: string | null,): string {- return formatScoutScheduleShort({+ const schedule = {run_cron_schedule: config.run_cron_schedule,run_interval_minutes:config.run_interval_minutes ?? DEFAULT_SUGGESTION_INTERVAL_MINUTES,- });+ };+ const label = formatScoutScheduleShort(schedule);+ return timezoneAbbreviation && scoutScheduleNamesClockTime(schedule)+ ? `${label} (${timezoneAbbreviation})`+ : label;}/** One line on what the agent would do: how often, and where its output goes. */export function suggestionMetaLine(config: ScoutSuggestionProposedConfig,+ timezoneAbbreviation?: string | null,): string {const output = config.emit? "sends what it finds to Self-driving": "dry run, sends nothing";- return `Runs ${suggestionCadenceLabel(config)} · ${output}`;+ return `Runs ${suggestionCadenceLabel(config, timezoneAbbreviation)} · ${output}`;}/** What the primary action on a suggestion does. */diff --git a/products/desktop/packages/ui/src/features/projects/useProjectTimezone.ts b/products/desktop/packages/ui/src/features/projects/useProjectTimezone.tsnew file mode 100644index 000000000000..83dfe554ce59--- /dev/null+++ b/products/desktop/packages/ui/src/features/projects/useProjectTimezone.ts@@ -0,0 +1,23 @@+import { useAuthenticatedQuery } from "@posthog/ui/hooks/useAuthenticatedQuery";+import { useAuthStateValue } from "../auth/store";++/** The project's IANA timezone, or null while it is unknown. Scout cron schedules resolve in it. */+export function useProjectTimezone(): string | null {+ const projectId = useAuthStateValue((state) => state.currentProjectId);+ const { data } = useAuthenticatedQuery<string | null>(+ ["project", "timezone", projectId],+ async (client) => {+ if (!projectId) return null;+ const project = await client.getProject(projectId);+ return project.timezone ?? null;+ },+ {+ enabled: !!projectId,+ staleTime: Number.POSITIVE_INFINITY,+ // "always" is what beats the infinite stale time; a plain focus refetch obeys it, and+ // would leave a user who just changed the setting looking at the old timezone.+ refetchOnWindowFocus: "always",+ },+ );+ return data ?? null;+}diff --git a/products/desktop/packages/ui/src/features/scouts/components/ScoutCadenceLabel.tsx b/products/desktop/packages/ui/src/features/scouts/components/ScoutCadenceLabel.tsxnew file mode 100644index 000000000000..943c933a97d0--- /dev/null+++ b/products/desktop/packages/ui/src/features/scouts/components/ScoutCadenceLabel.tsx@@ -0,0 +1,59 @@+import type { ScoutConfig } from "@posthog/api-client/posthog-client";+import {+ formatScoutScheduleShort,+ scoutScheduleNamesClockTime,+} from "@posthog/core/scouts/scoutPresentation";+import {+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+} from "@posthog/quill";+import { useProjectTimezone } from "@posthog/ui/features/projects/useProjectTimezone";+import { formatTimezoneAbbreviation } from "@posthog/ui/primitives/timezone";+import { projectTimezoneSettingsUrl } from "@posthog/ui/utils/posthogLinks";++/**+ * How often the scout runs, with the project timezone beside a schedule that picks hours of the+ * day: without it a reader in another timezone takes the time for their own.+ */+export function ScoutCadenceLabel({ config }: { config: ScoutConfig }) {+ const timezone = useProjectTimezone();+ const settingsUrl = projectTimezoneSettingsUrl();+ const label = formatScoutScheduleShort(config);+ if (!settingsUrl || !scoutScheduleNamesClockTime(config)) return <>{label}</>;++ // Still loading, or the request failed: a clock time is qualified either way.+ const suffix = timezone+ ? formatTimezoneAbbreviation(timezone)+ : "project timezone";+ const tooltip = timezone+ ? `Times use the project timezone (${timezone}). Open settings to change it.`+ : "Times use the project timezone. Open settings to see or change it.";++ return (+ <>+ {label}{" "}+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ className="appearance-none border-0 bg-transparent p-0 text-gray-10 underline decoration-dotted underline-offset-2"+ // The row and card around this label carry their own click targets.+ onClick={(event) => {+ event.stopPropagation();+ window.open(settingsUrl, "_blank", "noreferrer");+ }}+ >+ ({suffix})+ </button>+ }+ />+ <TooltipContent>{tooltip}</TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </>+ );+}diff --git a/products/desktop/packages/ui/src/features/scouts/components/ScoutDetailHeader.tsx b/products/desktop/packages/ui/src/features/scouts/components/ScoutDetailHeader.tsxindex ea17ef4439a8..c072696e06f9 100644--- a/products/desktop/packages/ui/src/features/scouts/components/ScoutDetailHeader.tsx+++ b/products/desktop/packages/ui/src/features/scouts/components/ScoutDetailHeader.tsx@@ -9,7 +9,6 @@ import {deriveScoutLifecycle,formatNextRun,formatRunDuration,- formatScoutScheduleShort,getScoutOrigin,hasPendingScoutRun,nextRunAt,@@ -26,6 +25,7 @@ import { Fragment, type ReactNode } from "react";import type { ScoutConfigUpdate } from "../hooks/useScoutConfigMutations";import { useScoutRunNow } from "../hooks/useScoutRunNow";import { useScoutSkillCreators } from "../hooks/useScoutSkillCreators";+import { ScoutCadenceLabel } from "./ScoutCadenceLabel";import { ScoutChatButton } from "./ScoutChatButton";import { ScoutEnabledSwitch } from "./ScoutConfigControls";import { ScoutHealthBanner } from "./ScoutLifecycleBadges";@@ -136,7 +136,7 @@ function ScoutDetailHeading({creator ? `${origin} · by ${scoutCreatorDisplayName(creator)}` : origin,];if (!config.emit) meta.push("Dry run");- meta.push(formatScoutScheduleShort(config));+ meta.push(<ScoutCadenceLabel config={config} />);if (running) {meta.push(<span className="text-(--blue-11)">@@ -158,14 +158,12 @@ function ScoutDetailHeading({Next run <span className="text-gray-12">{next}</span></>,);- } else {- meta.push(- !config.enabled- ? "Switched off"- : config.run_cron_schedule- ? "Uses the project timezone"- : "Next run time is unavailable",- );+ } else if (!config.enabled) {+ meta.push("Switched off");+ } else if (!config.run_cron_schedule) {+ // A cron scout has no computed next run, but its cadence already names the time and the+ // project timezone, so the slot stays empty rather than repeating them.+ meta.push("Next run time is unavailable");}if (latest && latestOutcome !== "running") {meta.push(diff --git a/products/desktop/packages/ui/src/features/scouts/components/ScoutSuggestions.tsx b/products/desktop/packages/ui/src/features/scouts/components/ScoutSuggestions.tsxindex 2765ff5d6b2e..ac1f24367776 100644--- a/products/desktop/packages/ui/src/features/scouts/components/ScoutSuggestions.tsx+++ b/products/desktop/packages/ui/src/features/scouts/components/ScoutSuggestions.tsx@@ -9,6 +9,8 @@ import {} from "@posthog/core/scouts/scoutSuggestions";import { Badge, Button } from "@posthog/quill";import { ANALYTICS_EVENTS } from "@posthog/shared";+import { useProjectTimezone } from "@posthog/ui/features/projects/useProjectTimezone";+import { formatTimezoneAbbreviation } from "@posthog/ui/primitives/timezone";import { track } from "@posthog/ui/shell/analytics";import type { ScoutConfigUpdate } from "../hooks/useScoutConfigMutations";@@ -75,6 +77,7 @@ function SuggestionCard({// A canonical pick names an agent this project already has, off. Without that// agent there is nothing to switch on, so the card offers the draft instead.const canTurnOn = item.kind === "canonical" && config !== undefined;+ const timezone = useProjectTimezone();const act = () => {track(ANALYTICS_EVENTS.SCOUT_ACTION, {@@ -102,7 +105,10 @@ function SuggestionCard({{item.why_here}</p><span className="text-[11px] text-gray-9">- {suggestionMetaLine(item.proposed_config)}+ {suggestionMetaLine(+ item.proposed_config,+ timezone && formatTimezoneAbbreviation(timezone),+ )}</span><div className="mt-1 flex items-center gap-1.5"><Buttondiff --git a/products/desktop/packages/ui/src/features/scouts/components/ScoutTableRow.tsx b/products/desktop/packages/ui/src/features/scouts/components/ScoutTableRow.tsxindex 1f984e9cafc0..3e9e82bb04b8 100644--- a/products/desktop/packages/ui/src/features/scouts/components/ScoutTableRow.tsx+++ b/products/desktop/packages/ui/src/features/scouts/components/ScoutTableRow.tsx@@ -14,7 +14,6 @@ import {deriveScoutLifecycle,formatNextRun,formatRunDuration,- formatScoutScheduleShort,hasPendingScoutRun,nextRunAt,prettifyScoutSkillName,@@ -48,6 +47,7 @@ import type { ScoutConfigUpdate } from "../hooks/useScoutConfigMutations";import { useScoutRunNow } from "../hooks/useScoutRunNow";import { AgentNameLink } from "./AgentNameLink";import { DryRunBadge } from "./ScoutBadges";+import { ScoutCadenceLabel } from "./ScoutCadenceLabel";import { ScoutEnabledSwitch } from "./ScoutConfigControls";import { ScoutLifecycleBadge } from "./ScoutLifecycleBadges";import { ScoutRunBoxes } from "./ScoutRunBoxes";@@ -164,9 +164,11 @@ function ScoutTableRowInner({</TableCell><TableCell>- <div className="flex flex-col gap-0.5 truncate">+ {/* Wraps rather than truncates, because a clipped cadence loses the timezone first.+ Breaks inside a word too: a hand-written cron can hold no space to wrap at. */}+ <div className="flex min-w-0 flex-col gap-0.5 break-words"><span className="text-[12.5px] text-gray-12">- {formatScoutScheduleShort(config)}+ <ScoutCadenceLabel config={config} /></span>{rollup?.runningRun &&deriveRunOutcome(rollup.runningRun, now) === "running" ? (diff --git a/products/desktop/packages/ui/src/utils/posthogLinks.ts b/products/desktop/packages/ui/src/utils/posthogLinks.tsindex 57a1b63cde06..cf5604d1a25d 100644--- a/products/desktop/packages/ui/src/utils/posthogLinks.ts+++ b/products/desktop/packages/ui/src/utils/posthogLinks.ts@@ -70,6 +70,16 @@ export function experimentUrl();}+/** The project's date and time settings, where its timezone is set. */+export function projectTimezoneSettingsUrl(+ overrides?: LinkOverrides,+): string | null {+ return withProjectId(+ (pid) => `/project/${pid}/settings/environment-customization#date-and-time`,+ overrides,+ );+}+export function skillUrl(skillName: string,overrides?: LinkOverrides,