AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): serialize Linear OAuth refreshes (#15054)
Bently7b8977c1ebfb
diff --git a/autogpt_platform/backend/backend/blocks/linear/_oauth.py b/autogpt_platform/backend/backend/blocks/linear/_oauth.pyindex 89f6aa8fd5..14f3de4e41 100644--- a/autogpt_platform/backend/backend/blocks/linear/_oauth.py+++ b/autogpt_platform/backend/backend/blocks/linear/_oauth.py@@ -5,7 +5,7 @@ Linear OAuth handler implementation.import base64import jsonimport time-from typing import Optional+from typing import ClassVar, Optionalfrom urllib.parse import urlencodefrom backend.sdk import (@@ -35,6 +35,7 @@ class LinearOAuthHandler(BaseOAuthHandler):# Provider name will be set dynamically by the SDK when registered# We use a placeholder that will be replaced by AutoRegistry.register_provider()PROVIDER_NAME = ProviderName("linear")+ ROTATES_REFRESH_TOKEN: ClassVar[bool] = Truedef __init__(self, client_id: str, client_secret: str, redirect_uri: str):self.client_id = client_iddiff --git a/autogpt_platform/backend/backend/integrations/creds_manager_test.py b/autogpt_platform/backend/backend/integrations/creds_manager_test.pyindex a8a4730822..47d5bca97d 100644--- a/autogpt_platform/backend/backend/integrations/creds_manager_test.py+++ b/autogpt_platform/backend/backend/integrations/creds_manager_test.py@@ -177,6 +177,30 @@ async def test_locked_refresh_reloads_after_waiting_for_rotating_provider(mockeracquire_lock.assert_not_awaited()+async def test_linear_refresh_uses_locked_path_even_when_copilot_requests_unlocked(+ mocker,+):+ from backend.blocks.linear._oauth import LinearOAuthHandler++ manager = IntegrationCredentialsManager()+ credentials = _provider_runtime_credentials().model_copy(+ update={"provider": "linear", "refresh_strategy": "oauth_handler"}+ )+ handler = LinearOAuthHandler("client", "secret", "redirect")+ mocker.patch.object(manager, "_get_oauth_handler", AsyncMock(return_value=handler))+ locked = mocker.patch.object(+ manager, "_refresh_locked", AsyncMock(return_value=credentials)+ )+ unlocked = mocker.patch.object(manager, "_refresh_unlocked", AsyncMock())++ result = await manager.refresh_if_needed("user-a", credentials, lock=False)++ assert result is credentials+ locked.assert_awaited_once_with("user-a", credentials, handler=handler)+ unlocked.assert_not_awaited()++@pytest.mark.asyncioasync def test_locked_refresh_reports_a_credential_type_change(mocker):manager = IntegrationCredentialsManager()