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.

chore(signals): declare the response schemas the frontend reads (#104383)

Julian Bezb2f8aae99237
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 1c58455c29e5..5e6d9747f70b 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -618,6 +618,10 @@ SPECTACULAR_SETTINGS = {
"ResolvedAccessSourceEnum": "products.access_control.backend.facade.enums.RESOLVED_ACCESS_SOURCE_CHOICES",
"ResolvedAccessSourceSubjectEnum": "products.access_control.backend.facade.enums.RESOLVED_ACCESS_SOURCE_SUBJECT_CHOICES",
"TaskArtifactStatusEnum": ["active", "failed"],
+ # signals maps a warehouse import's status down to these three. Same values as the
+ # warehouse's own SyncStatus, but that class carries different labels, so the two are
+ # distinct choice sets and this one needs its own name.
+ "SignalSourceSyncStatusEnum": ["running", "completed", "failed"],
"RunSourceEnum": ["manual", "signal_report", "agent"],
"TaskBootstrapRunSourceEnum": ["manual", "signal_report"],
#
diff --git a/products/signals/backend/serializers.py b/products/signals/backend/serializers.py
index d497e9938345..926f416cf333 100644
--- a/products/signals/backend/serializers.py
+++ b/products/signals/backend/serializers.py
@@ -160,6 +160,13 @@ class _SourceConfigField(serializers.JSONField):
plain JSONField; steering-key validation stays in the serializer's `validate`."""
+# The three states get_status maps the warehouse import's status down to. Declared so the generated
+# client narrows to them rather than to a bare string, which is what the frontend already does by
+# hand. `status` is too generic a field name for drf-spectacular to name a set on its own, so the
+# name comes from ENUM_NAME_OVERRIDES.
+SIGNAL_SOURCE_CONFIG_STATUSES = ["running", "completed", "failed"]
+
+
class SignalSourceConfigSerializer(serializers.ModelSerializer):
status = serializers.SerializerMethodField(
help_text=(
@@ -189,6 +196,7 @@ class SignalSourceConfigSerializer(serializers.ModelSerializer):
# Absent key means "not read yet", a `None` value means the read failed.
self._data_import_statuses_by_team: dict[int, dict[_DataImportSchema, set[str]] | None] = {}
+ @extend_schema_field(serializers.ChoiceField(choices=SIGNAL_SOURCE_CONFIG_STATUSES, allow_null=True))
def get_status(self, obj: SignalSourceConfig) -> str | None:
schema = _DATA_IMPORT_SOURCE_MAP.get((obj.source_product, obj.source_type))
if schema is None:
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index bcc14996697c..610575eeafd3 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -5644,6 +5644,15 @@ export const SignalSourceConfigSourceTypeEnumApi = {
SearchOpportunity: 'search_opportunity',
} as const
+export type SignalSourceSyncStatusEnumApi =
+ (typeof SignalSourceSyncStatusEnumApi)[keyof typeof SignalSourceSyncStatusEnumApi]
+
+export const SignalSourceSyncStatusEnumApi = {
+ Running: 'running',
+ Completed: 'completed',
+ Failed: 'failed',
+} as const
+
/**
* Per-source settings as a JSON object. Keys read by the emission actionability gate on sources that define one (most data warehouse imports, and Conversations): `steering` (string, max 2000 characters) holds the team's preferences about this source's records in plain language: what matters, what to skip, what's out of scope. The emission actionability gate applies it when deciding which records become signals; rules apply from the next sync and nothing already emitted is retracted. `default_not_actionable` (boolean, default false) flips the gate's default: instead of keeping every record the steering rules don't exclude, only records that clearly match the team's preferences are kept. Other sources store these keys without reading them yet; future pipeline stages will consume the same steering text. Some sources read additional keys, for example `recording_filters` and `sample_rate` for session analysis.
*/
@@ -5658,11 +5667,8 @@ export interface SignalSourceConfigApi {
config?: SignalSourceConfigApiConfig
readonly created_at: string
readonly updated_at: string
- /**
- * Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read.
- * @nullable
- */
- readonly status: string | null
+ /** Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read. */
+ readonly status: SignalSourceSyncStatusEnumApi | null
}
export interface PaginatedSignalSourceConfigListApi {
@@ -5688,11 +5694,8 @@ export interface PatchedSignalSourceConfigApi {
config?: PatchedSignalSourceConfigApiConfig
readonly created_at?: string
readonly updated_at?: string
- /**
- * Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read.
- * @nullable
- */
- readonly status?: string | null
+ /** Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read. */
+ readonly status?: SignalSourceSyncStatusEnumApi | null
}
export interface SignalUserAutonomyConfigApi {
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 464271dd1f77..f9a2b158e507 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -65112,6 +65112,15 @@ export namespace Schemas {
SearchOpportunity: 'search_opportunity',
} as const;
+ export type SignalSourceSyncStatusEnum = typeof SignalSourceSyncStatusEnum[keyof typeof SignalSourceSyncStatusEnum];
+
+
+ export const SignalSourceSyncStatusEnum = {
+ Running: 'running',
+ Completed: 'completed',
+ Failed: 'failed',
+ } as const;
+
/**
* Per-source settings as a JSON object. Keys read by the emission actionability gate on sources that define one (most data warehouse imports, and Conversations): `steering` (string, max 2000 characters) holds the team's preferences about this source's records in plain language: what matters, what to skip, what's out of scope. The emission actionability gate applies it when deciding which records become signals; rules apply from the next sync and nothing already emitted is retracted. `default_not_actionable` (boolean, default false) flips the gate's default: instead of keeping every record the steering rules don't exclude, only records that clearly match the team's preferences are kept. Other sources store these keys without reading them yet; future pipeline stages will consume the same steering text. Some sources read additional keys, for example `recording_filters` and `sample_rate` for session analysis.
*/
@@ -65126,11 +65135,8 @@ export namespace Schemas {
config?: SignalSourceConfigConfig;
readonly created_at: string;
readonly updated_at: string;
- /**
- * Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read.
- * @nullable
- */
- readonly status: string | null;
+ /** Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read. */
+ readonly status: SignalSourceSyncStatusEnum | null;
}
export interface PaginatedSignalSourceConfigList {
@@ -75167,11 +75173,8 @@ export namespace Schemas {
config?: PatchedSignalSourceConfigConfig;
readonly created_at?: string;
readonly updated_at?: string;
- /**
- * Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read.
- * @nullable
- */
- readonly status?: string | null;
+ /** Sync state of the warehouse import behind this source: `running`, `failed`, or `completed`. Null for a source that imports nothing from the warehouse, for an import that has never synced, and when the sync state could not be read. */
+ readonly status?: SignalSourceSyncStatusEnum | null;
}
/**