: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
chore(signals): document the self-driving temporal worker (#108578)
posthog[bot]54395048028f
diff --git a/docs/internal/self-driving-temporal-worker-runbook.md b/docs/internal/self-driving-temporal-worker-runbook.mdnew file mode 100644index 000000000000..5b3a303f2ef3--- /dev/null+++ b/docs/internal/self-driving-temporal-worker-runbook.md@@ -0,0 +1,137 @@+# Self-driving Temporal worker runbook++How to operate the `temporal-worker-self-driving` fleet, and how to check that the inbox ranking sweep runs on it.++## What the fleet is++The fleet is a dedicated Temporal worker for low-priority self-driving background jobs.+It keeps heavy, memory-hungry work off the video-export fleet, which runs the rest of Signals.++| Item | Value |+| ----------- | --------------------------------------------------------------------------------- |+| Release | `temporal-worker-self-driving` in the `PostHog/charts` repo |+| Owner team | `signals` |+| Task queue | `self-driving-task-queue` (`settings.SELF_DRIVING_TASK_QUEUE`) |+| Regions | dev, prod-us, and prod-eu |+| Pods | 2 fixed pods, no autoscaling |+| Resources | Requests `cpu: 1` and `memory: 4Gi`. Limit `memory: 6Gi`. |+| Worker env | `TEMPORAL_TASK_QUEUE` and `SELF_DRIVING_TASK_QUEUE` are `self-driving-task-queue` |+| App secrets | None. The fleet has no worker secret. |++The worker starts with `start_temporal_worker --task-queue self-driving-task-queue`.+`WORKFLOWS_DICT` in `posthog/management/commands/start_temporal_worker.py` maps that queue to `SELF_DRIVING_WORKFLOWS` and `SELF_DRIVING_ACTIVITIES` from `products/signals/backend/temporal/__init__.py`.++## What runs on it++Only the inbox ranking scoring sweep runs on this fleet:++- Workflow `inbox-ranking-scoring-sweep` (`InboxRankingScoringWorkflow`).+- Activity `score_inbox_reports_activity`.++Both live in `products/signals/backend/ranking/sweep.py`.+The video-export fleet does not register them.+All other Signals workflows (ingestion, grouping, summaries, scouts) stay on the video-export fleet.++## The ranking sweep schedule++`create_inbox_ranking_scoring_schedule` in `products/signals/backend/ranking/schedule.py` registers the schedule.+The `schedule_temporal_workflows` management command calls it on each Django deploy.++| Setting | Value |+| ----------------- | --------------------------------------------------------------------- |+| Schedule ID | `inbox-ranking-scoring-sweep-schedule` |+| Task queue | `settings.SELF_DRIVING_TASK_QUEUE`, default `self-driving-task-queue` |+| Interval | `INBOX_RANKING_SCORING_INTERVAL_MINUTES`, default 15 |+| Overlap policy | `SKIP` |+| Execution timeout | One interval |+| Activity timeout | 10 minutes, with one attempt and no retry |+| Time budget | 8 minutes. The pass starts no new team after this budget. |++A deploy keeps the live schedule state.+If an operator pauses the schedule, the next deploy does not resume it.++`INBOX_RANKING_SCORING_ENABLED` gates the work, not the schedule.+The fleet sets it to `"false"`, so each tick logs `inbox_ranking_sweep_skipped` with `skipped_reason="disabled"` and returns.+Scoring stays off until [#108197](https://github.com/PostHog/posthog/issues/108197) is resolved.++## Deploys++The `selfDriving` path filter in `.github/workflows/container-images-cd.yml` builds the worker image.+A merge to master that touches those paths sends a `commit_state_update` dispatch to `PostHog/charts` for the `temporal-worker-self-driving` release.++The filter shares `products/signals/backend/**` and `products/signals/skills/**` with the `videoExport` filter.+A change to Signals backend code deploys both fleets.+A change to `posthog/settings/temporal.py` deploys only the self-driving fleet.++## Checks after a deploy or cut-over++Do these checks in each region.++1. Make sure that the fleet polls the queue.+ Run `temporal task-queue describe --task-queue self-driving-task-queue`.+ The output must show pollers from the `temporal-worker-self-driving` pods.+2. Make sure that the schedule targets the new queue.+ Run `temporal schedule describe --schedule-id inbox-ranking-scoring-sweep-schedule`.+ The action task queue must be `self-driving-task-queue`.+3. Make sure that ticks complete on the new fleet.+ In the Temporal UI, filter by workflow type `inbox-ranking-scoring-sweep`.+ Each recent run must show task queue `self-driving-task-queue` and status `Completed`.+4. Make sure that the pod logs show each tick.+ Search the fleet logs for `inbox_ranking_sweep_skipped`, `inbox_ranking_sweep_started`, and `inbox_ranking_sweep_finished`.+ The `started` and `finished` events carry `peak_rss_mb`.+5. Make sure that no other Signals workflow moved.+ `temporal task-queue describe --task-queue video-export-task-queue` must still show pollers.+ Scout, grouping, and summary workflows must still run on `video-export-task-queue`.+6. Make sure that no video-export pod restarts with `OOMKilled` after the cut-over.++## Common operations++**Pause the sweep.**+Run `temporal schedule toggle --schedule-id inbox-ranking-scoring-sweep-schedule --pause --reason "<why>"`.+Use `--unpause` to resume it.++**Run one tick now.**+Run `temporal schedule trigger --schedule-id inbox-ranking-scoring-sweep-schedule`.++**Turn scoring on.**+Set `INBOX_RANKING_SCORING_ENABLED` to `"true"` on the charts release for one region.+Watch `peak_rss_mb` and pod memory against the 6Gi limit before the next region.++**Move a workload to this fleet.**++A running workflow stays on the task queue that it started on.+`continue_as_new` keeps that queue, so a long-running entity workflow does not move by itself.+Do these steps in this order, so that no run is left without a worker.++1. Add its workflow and activities to `SELF_DRIVING_WORKFLOWS` and `SELF_DRIVING_ACTIVITIES`.+ Deploy, then run check 1.+2. Change every start path of the workflow to `settings.SELF_DRIVING_TASK_QUEUE`.+ Search `products/signals/backend` for `VIDEO_EXPORT_TASK_QUEUE`.+ Start paths include schedules, API views, the facade, management commands, child workflow starts, and signal-with-start helpers such as `TeamSignalGroupingV2Workflow.pause_until()`.+3. Wait until no open run of the workflow is left on `video-export-task-queue`.+ A signal-with-start call sends the signal to the open run on the old queue, and does not start a new run.+ Plan how to close the open runs of an entity workflow before you continue.+4. Remove the workflow from the Signals `WORKFLOWS` list.+ Remove an activity from `ACTIVITIES` only if no workflow that stays on video-export uses it.+5. Update `test_module_integrity.py` and `test_start_temporal_worker.py`.+6. Add a worker secret to the charts release if the workload needs app-specific keys.++## Troubleshooting++**Runs stay in `Running` with no activity progress.**+No worker polls `self-driving-task-queue` in that region.+Check the pod status of the charts release, then run check 1.++**Runs show `TimedOut` each tick.**+The pass took longer than the activity timeout.+The next tick continues from where the last one stopped, because the vector comparison finds the unscored reports again.+If this happens on each tick, lower `INBOX_RANKING_SCORING_MAX_REPORTS_PER_TICK`.++**Pods restart with `OOMKilled`.**+Compare `peak_rss_mb` in the last `inbox_ranking_sweep_started` log with the 6Gi limit.+A killed pass logs no `finished` event.+Lower `INBOX_RANKING_SCORING_BATCH_SIZE` or pause the schedule.++**Local development.**+With `DEBUG` on, every queue collapses to `development-task-queue`.+The local worker runs the sweep with all other workflows.diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.mdindex 438aa2c539bd..51bfbb4c60bf 100644--- a/products/signals/ARCHITECTURE.md+++ b/products/signals/ARCHITECTURE.md@@ -16,7 +16,8 @@ Signals ingestion uses a three-stage pipeline: **emitter → buffer → groupingThe original `TeamSignalGroupingWorkflow` (v1) in `backend/temporal/grouping.py` is still registered but is no longer started by `emit_signal()`. Its shared activities and `_process_signal_batch()` implementation are still actively used by v2.-Signals workflows and activities are registered in `backend/temporal/__init__.py` and wired into the `VIDEO_EXPORT_TASK_QUEUE` worker by `posthog/management/commands/start_temporal_worker.py`.+Signals workflows and activities are registered in `backend/temporal/__init__.py` and wired into the `VIDEO_EXPORT_TASK_QUEUE` worker (the `temporal-worker-video-export` fleet) by `posthog/management/commands/start_temporal_worker.py`.+The inbox ranking scoring sweep is the one exception. `SELF_DRIVING_WORKFLOWS` and `SELF_DRIVING_ACTIVITIES` register it only on `SELF_DRIVING_TASK_QUEUE`, which the `temporal-worker-self-driving` fleet polls. See the [self-driving Temporal worker runbook](../../docs/internal/self-driving-temporal-worker-runbook.md) for the fleet, its schedule, and its checks.If you add or remove a Signals workflow/activity from `backend/temporal/__init__.py`, you also need to update `posthog/temporal/tests/ai/test_module_integrity.py` (`TestSignalsProductModuleIntegrity`). That test intentionally snapshots the registered workflow/activity lists and will fail until its expected names are updated.Several additional Signals workflows also exist but are not part of the main report pipeline:@@ -1663,7 +1664,8 @@ Signal {index}:| `SIGNAL_EMISSION_LLM_MODEL` | `claude-sonnet-5` | LLM model for emission-stage summarization and actionability checks || `MAX_RESPONSE_TOKENS` | `4096` | Base max tokens for LLM responses (thinking uses 3× for max_tokens, 2× for budget) || Embedding model | `text-embedding-3-small-1536` | OpenAI embedding model used for signal content |-| Task queue | `VIDEO_EXPORT_TASK_QUEUE` | Temporal task queue for all workflows |+| Task queue | `VIDEO_EXPORT_TASK_QUEUE` | Temporal task queue for all workflows except the ranking sweep |+| Ranking sweep task queue | `SELF_DRIVING_TASK_QUEUE` | Temporal task queue for the inbox ranking scoring sweep, polled by the `temporal-worker-self-driving` fleet || `BUFFER_MAX_SIZE` | `20` | Max signals buffered in memory before flush to S3 || `BUFFER_FLUSH_TIMEOUT_SECONDS` | `5` | Max seconds to wait for buffer to fill before flushing || S3 prefix | `signals/signal_batches/` | Object storage path for signal batch files (cleaned up by S3 lifecycle policies) |