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.

fix(hex): classify unstructured 422s as non-retryable (#127084)

Tom Owers194222fa6726
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hex/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hex/source.py
index 198f396f73bc..83bdd277c2c0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hex/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hex/source.py
@@ -96,6 +96,15 @@ If your workspace runs on a single-tenant or self-hosted Hex deployment, enter i
# Matched on the stable error code rather than the per-request URL; every retry sends the
# identical request and fails identically, so there's nothing to gain from retrying.
"code=UNPROCESSABLE_CONTENT": "Hex rejected a request as unprocessable. This is usually caused by the state of a specific project in your Hex workspace rather than something PostHog can retry. Check the project in Hex, or contact Hex support if this persists.",
+ # Catch-all for every other 422: some Hex endpoints (e.g. GetQueriedTables) reject a
+ # request without a structured error code in the body, so the key above never matches
+ # and the message carries nothing past the stock "for url: ..." text. A 422 means the
+ # request itself was semantically rejected, so every retry fails identically regardless
+ # of which endpoint raised it. Kept last so the more specific, better-worded key above
+ # still wins when Hex does return a structured code. Matched on just the status, like
+ # the 401/403 keys above, since the reason phrase isn't guaranteed stable (RFC 9110
+ # renamed it "Unprocessable Content").
+ "422 Client Error": "Hex rejected a request as unprocessable. This is usually caused by the state of a specific resource in your Hex workspace rather than something PostHog can retry. Check your Hex workspace, or contact Hex support if this persists.",
}
def get_canonical_descriptions(self) -> CanonicalDescriptions:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hex/tests/test_hex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hex/tests/test_hex.py
index 19fa6094dadd..4ba939f2c106 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hex/tests/test_hex.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hex/tests/test_hex.py
@@ -168,6 +168,19 @@ class TestPerProjectCursorFanout:
assert result.paths[3] == "/api/v1/projects/p2/queriedTables"
assert result.requests[3].param("after") is None
+ def test_422_with_no_structured_error_code_is_still_classified_non_retryable(self) -> None:
+ # Unlike GetProjectRuns, GetQueriedTables's 422 body carries no `code` field at all (just
+ # `details`/`traceId`/`reason`), so the structured-code key never matches. The raised
+ # error must still match a `get_non_retryable_errors()` key via the generic 422 fallback,
+ # or this project would retry forever against an identical, permanently-rejected request.
+ result = _driver().run(
+ "queried_tables",
+ [_projects_page(["p1"]), ScriptedResponse(status=422, json={"details": [], "traceId": "t", "reason": "x"})],
+ )
+
+ assert result.raised is not None
+ assert error_message_matches(str(result.raised), HexSource().get_non_retryable_errors())
+
class TestRuntimeHostCheck:
def test_blocks_unsafe_workspace_host_before_any_request(self) -> None: