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): AutoPilot chats driven from a linked chat bot no longer wait on an approval card the channel cannot show (#15068)

Reinier van der Leer5d4f2c596df5
diff --git a/autogpt_platform/backend/backend/copilot/gate/__init__.py b/autogpt_platform/backend/backend/copilot/gate/__init__.py
index 9d77bce681..e7d0ba6088 100644
--- a/autogpt_platform/backend/backend/copilot/gate/__init__.py
+++ b/autogpt_platform/backend/backend/copilot/gate/__init__.py
@@ -21,6 +21,7 @@ from pydantic import BaseModel, ConfigDict
from backend.copilot.model import ChatSession
from backend.copilot.tree import raise_ceiling, spent_past_ceiling
+from backend.platform_linking.models import Platform
from backend.util.feature_flag import Flag, is_feature_enabled
from . import chat_rules, held
@@ -57,6 +58,9 @@ _UNRECORDABLE = (
)
_ASK_FIRST = "Ask First is on for this chat, so this action needs your approval."
_OUTWARD = "This action reaches outside the platform, so it needs your approval."
+# A chat driven from a linked bot cannot show a card, so it runs ungated until
+# the channel gets its own approval buttons (plan layer L7c).
+CARDLESS_PLATFORMS = frozenset(p.value.lower() for p in Platform)
# One approval of a paid read over the ceiling buys one more dollar.
CEILING_UNIT_MICRODOLLARS = 1_000_000
# Paid steps that otherwise run in every mode; the costliest blocks are workspace.
@@ -92,6 +96,8 @@ async def gate_active(user_id: str | None, session: ChatSession) -> bool:
is watching stay ungated until they get their own path."""
if not user_id or session.metadata.origin != "interactive":
return False
+ if session.metadata.source_platform in CARDLESS_PLATFORMS:
+ return False
return await is_feature_enabled(Flag.COPILOT_AUTO_MODE, user_id, default=False)
diff --git a/autogpt_platform/backend/backend/copilot/gate/gate_test.py b/autogpt_platform/backend/backend/copilot/gate/gate_test.py
index 30202b83f1..7f9359d644 100644
--- a/autogpt_platform/backend/backend/copilot/gate/gate_test.py
+++ b/autogpt_platform/backend/backend/copilot/gate/gate_test.py
@@ -41,6 +41,7 @@ _MODES: tuple[AutopilotMode, ...] = ("ask_first", "auto", "unsupervised")
def _session(
mode: AutopilotMode | None = None,
origin: ChatSessionOrigin | None = "interactive",
+ source_platform: str | None = None,
) -> ChatSession:
return ChatSession(
session_id="session-1",
@@ -48,7 +49,9 @@ def _session(
usage=[],
started_at=datetime.now(UTC),
updated_at=datetime.now(UTC),
- metadata=ChatSessionMetadata(origin=origin, autopilot_mode=mode),
+ metadata=ChatSessionMetadata(
+ origin=origin, autopilot_mode=mode, source_platform=source_platform
+ ),
messages=[ChatMessage(role="user", content="do the thing")],
)
@@ -109,6 +112,17 @@ async def test_gate_is_inactive_for_anonymous_turns(gate_on):
assert not await gate_active(None, _session())
[email protected]("source_platform, gated", [(None, True), ("discord", False)])
+async def test_a_chat_driven_from_a_linked_bot_runs_ungated(
+ gate_on, clean_session_state, source_platform, gated
+):
+ """The channel cannot show a card, so a held call would strand the chat."""
+ session = _session("ask_first", source_platform=source_platform)
+ decision = await check_action("post_to_chat_platform", {"text": "hi"}, "u", session)
+ assert decision.allowed is not gated
+ assert (await active_mode("u", session) is not None) is gated
+
+
async def test_the_default_mode_is_auto(gate_on):
assert await active_mode("u", _session()) == "auto"