: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(tasks): give scout runs a $30 per-run gateway cap (#115737)
Alessandro Pogliaghi72007f75fa22
diff --git a/posthog/settings/temporal.py b/posthog/settings/temporal.pyindex 31b3087b9c77..8dcd2e5894d9 100644--- a/posthog/settings/temporal.py+++ b/posthog/settings/temporal.py@@ -106,6 +106,7 @@ SANDBOX_AI_GATEWAY_TOKEN_CAP_USD_OVERRIDES: str = get_from_env("SANDBOX_AI_GATEW# retries behind a cap that binds mid-run. Suggestion runs stay on the default. A PostHog# Desktop cloud run has no duration cap, so its cap only bounds a runaway run.SANDBOX_AI_GATEWAY_TOKEN_CAP_USD_PRODUCT_DEFAULTS: dict[str, str] = {+ "signals_scout": "30","signals_implementation": "20","signals_inbox": "75","signals_chat": "30",diff --git a/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py b/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.pyindex ef2c02592a63..8e2309a0a0b5 100644--- a/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py+++ b/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py@@ -199,7 +199,7 @@ class TestMintScopedToken:expected_key = gateway_config.api_key if gateway_config else "phs_test_mint"assert post.call_args[0][0] == f"{expected_url}/tokens"assert kwargs["json"] == {- "cap_usd": "3",+ "cap_usd": "30","ttl_seconds": 600 if private else 14400,"product": "signals_scout","obo": "123",@@ -421,7 +421,7 @@ class TestAiGatewayEnvVars:"AI_GATEWAY_URL": "https://ai-gateway.dev.posthog.dev","AI_GATEWAY_PRODUCTS": "signals_scout,signals_research","AI_GATEWAY_TOKEN": "phe_abc",- "AI_GATEWAY_TOKEN_CAP_USD": "3",+ "AI_GATEWAY_TOKEN_CAP_USD": "30","AI_GATEWAY_PRODUCT": "signals_scout","AI_GATEWAY_AI_STAGE": "scout:logs",}@@ -727,7 +727,7 @@ class TestProvisioningBoundaries:"AI_GATEWAY_URL": mint_settings.SANDBOX_AI_GATEWAY_URL,"AI_GATEWAY_PRODUCTS": "signals_scout","AI_GATEWAY_TOKEN": "phe_private",- "AI_GATEWAY_TOKEN_CAP_USD": "3",+ "AI_GATEWAY_TOKEN_CAP_USD": "30","AI_GATEWAY_PRODUCT": "signals_scout","AI_GATEWAY_AI_STAGE": "scout:logs",}@@ -934,8 +934,8 @@ class TestUserPinAndCapOverride:mint_settings.SANDBOX_AI_GATEWAY_TOKEN_CAP_USD_OVERRIDES = '{"2": "10"}'with patch("products.tasks.backend.temporal.process_task.ai_gateway_token.requests.post") as post:post.return_value = self._response({"token": "phe_abc"})- mint_scoped_token(ai_product="signals_scout", team_id=2)- mint_scoped_token(ai_product="signals_scout", team_id=123)+ mint_scoped_token(ai_product="signals_scout_suggestions", team_id=2)+ mint_scoped_token(ai_product="signals_scout_suggestions", team_id=123)assert post.call_args_list[0].kwargs["json"]["cap_usd"] == "10"assert post.call_args_list[1].kwargs["json"]["cap_usd"] == "3"@@ -945,7 +945,7 @@ class TestUserPinAndCapOverride:with patch("products.tasks.backend.temporal.process_task.ai_gateway_token.requests.post") as post:post.return_value = self._response({"token": "phe_abc"})mint_scoped_token(ai_product="signals_implementation", team_id=2)- mint_scoped_token(ai_product="signals_scout", team_id=2)+ mint_scoped_token(ai_product="signals_scout_suggestions", team_id=2)assert post.call_args_list[0].kwargs["json"]["cap_usd"] == "15"assert post.call_args_list[1].kwargs["json"]["cap_usd"] == "10"@@ -953,18 +953,19 @@ class TestUserPinAndCapOverride:def test_invalid_product_cap_keeps_the_product_default(self, mint_settings, invalid_product_cap):mint_settings.SANDBOX_AI_GATEWAY_TOKEN_CAP_USD_OVERRIDES = '{"2": "10"}'mint_settings.SANDBOX_AI_GATEWAY_TOKEN_CAP_USD_PRODUCT_OVERRIDES = json.dumps(- {"signals_implementation": invalid_product_cap, "signals_scout": invalid_product_cap}+ {"signals_implementation": invalid_product_cap, "signals_scout_suggestions": invalid_product_cap})with patch("products.tasks.backend.temporal.process_task.ai_gateway_token.requests.post") as post:post.return_value = self._response({"token": "phe_abc"})mint_scoped_token(ai_product="signals_implementation", team_id=2)- mint_scoped_token(ai_product="signals_scout", team_id=2)+ mint_scoped_token(ai_product="signals_scout_suggestions", team_id=2)# The code default for a product that has one, else the team override.assert [c.kwargs["json"]["cap_usd"] for c in post.call_args_list] == ["20", "10"]@pytest.mark.parametrize("ai_product,expected_cap",[+ ("signals_scout", "30"),("signals_implementation", "20"),("signals_inbox", "75"),("signals_chat", "30"),@@ -992,7 +993,7 @@ class TestUserPinAndCapOverride:mint_settings.SANDBOX_AI_GATEWAY_TOKEN_CAP_USD_OVERRIDES = "not json"with patch("products.tasks.backend.temporal.process_task.ai_gateway_token.requests.post") as post:post.return_value = self._response({"token": "phe_abc"})- mint_scoped_token(ai_product="signals_scout", team_id=2)+ mint_scoped_token(ai_product="signals_scout_suggestions", team_id=2)assert post.call_args.kwargs["json"]["cap_usd"] == "3"