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(autoresearch): deploy autoresearch code to the self-driving worker (#110856)

posthog[bot]b3f5110c238d
diff --git a/.github/workflows/container-images-cd.yml b/.github/workflows/container-images-cd.yml
index 55a02c41e87d..967afb5f24b3 100644
--- a/.github/workflows/container-images-cd.yml
+++ b/.github/workflows/container-images-cd.yml
@@ -515,6 +515,7 @@ jobs:
selfDriving:
- 'products/signals/backend/**'
- 'products/signals/skills/**'
+ - 'products/autoresearch/backend/**'
- 'posthog/settings/temporal.py'
- 'posthog/temporal/common/**'
- 'posthog/management/commands/start_temporal_worker.py'
diff --git a/products/autoresearch/backend/inference/scoring.py b/products/autoresearch/backend/inference/scoring.py
index c8af45db4f55..70f29133b582 100644
--- a/products/autoresearch/backend/inference/scoring.py
+++ b/products/autoresearch/backend/inference/scoring.py
@@ -94,6 +94,8 @@ class InferenceRunError(Exception):
_RESERVED_COLS = frozenset({"distinct_id", _LABEL_COL, _FOLD_COL})
# The score columns scoring adds to a feature row, kept out of the features hash.
_SCORE_KEYS = frozenset({"p_y", "p_y_raw"})
+# A capture error description can hold a URL and an exception repr, so the run error clips it.
+_MAX_EMIT_ERROR_DESCRIPTION_CHARS = 200
# Namespace for deterministic prediction event UUIDs, so a retried scoring activity
@@ -101,6 +103,20 @@ _SCORE_KEYS = frozenset({"p_y", "p_y_raw"})
_PREDICTION_UUID_NAMESPACE = uuid.UUID("6f9a4a24-0e5c-4a5a-9d0e-2f6a0f0b1c3d")
+def _clip_middle(text: str, limit: int) -> str:
+ """
+ Keep both ends of ``text``. A requests transport error starts with the target host and
+ ends with the cause, such as ``[Errno 111] Connection refused``, so a head-only clip
+ makes a refused connection and a failed DNS lookup look the same.
+ """
+ if len(text) <= limit:
+ return text
+ marker = "..."
+ head = (limit - len(marker)) // 2
+ tail = limit - len(marker) - head
+ return f"{text[:head]}{marker}{text[-tail:]}"
+
+
def _is_uuid(value: str) -> bool:
try:
uuid.UUID(str(value))
@@ -526,11 +542,16 @@ def _emit_predictions(
error=result.error,
)
sample = [result.results.get(uid) for uid in result.warnings[:3]]
+ error_detail = ""
+ if result.error:
+ error_detail = f", {result.error.get('error')}"
+ if description := result.error.get("error_description"):
+ error_detail += f": {_clip_middle(str(description), _MAX_EMIT_ERROR_DESCRIPTION_CHARS)}"
raise InferenceRunError(
f"Prediction events were not all accepted ({len(result.dropped)} dropped, "
f"{len(result.retried)} exhausted retries, {len(result.unaccounted)} unaccounted, "
f"{len(result.warnings)} stored with a warning{f' e.g. {sample!r}' if sample else ''}"
- f"{', ' + str(result.error.get('error')) if result.error else ''}); failing the run so it is retried"
+ f"{error_detail}); failing the run so it is retried"
)
return _EmitResult(
diff --git a/products/autoresearch/backend/inference/test_inference.py b/products/autoresearch/backend/inference/test_inference.py
index accf350f0bbb..8d41b666d750 100644
--- a/products/autoresearch/backend/inference/test_inference.py
+++ b/products/autoresearch/backend/inference/test_inference.py
@@ -53,6 +53,11 @@ _STUB_ROWS = [
{"distinct_id": "user-1", "events_total_30d": 50, "days_since_last_seen": 2},
{"distinct_id": "user-2", "events_total_30d": 10, "days_since_last_seen": 15},
]
+_REFUSED_CONNECTION_ERROR = (
+ "HTTPConnectionPool(host='capture.example.com', port=8010): Max retries exceeded with url: "
+ "/i/v1/analytics/events (Caused by NewConnectionError('<urllib3.connection.HTTPConnection "
+ "object at 0x7f0000000000>: Failed to establish a new connection: [Errno 111] Connection refused'))"
+)
def _accepted(events: list[dict]) -> CaptureInternalResult:
@@ -195,13 +200,26 @@ class TestRunInferencePipeline(TeamScopedTestMixin, BaseTest):
@parameterized.expand(
[
- ("transport_failure", Exception("capture unavailable"), None),
+ ("transport_failure", Exception("capture unavailable"), None, "capture unavailable"),
+ (
+ "transport_error_result",
+ None,
+ lambda events: CaptureInternalResult(
+ status_code=0,
+ error={"error": "transport_error", "error_description": _REFUSED_CONNECTION_ERROR},
+ unaccounted=[event["event_uuid"] for event in events],
+ ),
+ "transport_error: HTTPConnectionPool(host='capture.example.com', port=8010): Max retries exceeded "
+ "with url: /i/v1/an... object at 0x7f0000000000>: Failed to establish a new connection: "
+ "[Errno 111] Connection refused')))",
+ ),
(
"one_event_dropped",
None,
lambda events: CaptureInternalResult(
status_code=200, ok=[events[0]["event_uuid"]], dropped=[events[1]["event_uuid"]]
),
+ "1 dropped",
),
(
"one_event_stored_with_a_warning",
@@ -212,20 +230,22 @@ class TestRunInferencePipeline(TeamScopedTestMixin, BaseTest):
warnings=[events[1]["event_uuid"]],
results={events[1]["event_uuid"]: {"result": "warning", "message": "person processing disabled"}},
),
+ "person processing disabled",
),
]
)
- def test_any_emit_failure_fails_the_run(self, _name, side_effect, result_for):
+ def test_any_emit_failure_fails_the_run(self, _name, side_effect, result_for, expected_message):
# Completing with a partial batch advanced last_scored_at past the people who never
# received their prediction; the deterministic UUIDs make a full replay safe instead.
pipeline, model = self._make_pipeline_and_model()
capture = MagicMock(side_effect=side_effect or (lambda **kwargs: result_for(kwargs["events"])))
- with self.assertRaises(InferenceRunError):
+ with self.assertRaisesMessage(InferenceRunError, expected_message):
self._run_live(pipeline, model, capture)
run = AutoresearchRun.objects.filter(pipeline=pipeline).latest("created_at")
assert run.status == AutoresearchRun.Status.FAILED
+ assert expected_message in run.error
pipeline.refresh_from_db()
assert pipeline.last_scored_at is None