Skip to content

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.py
index 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 base64
import json
import time
-from typing import Optional
+from typing import ClassVar, Optional
from urllib.parse import urlencode
from 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] = True
def __init__(self, client_id: str, client_secret: str, redirect_uri: str):
self.client_id = client_id
diff --git a/autogpt_platform/backend/backend/integrations/creds_manager_test.py b/autogpt_platform/backend/backend/integrations/creds_manager_test.py
index 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(mocker
acquire_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.asyncio
async def test_locked_refresh_reports_a_credential_type_change(mocker):
manager = IntegrationCredentialsManager()