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(platform): stop the e2e and CI flakes from GC stalls, keep-alive resets, a refused first send and partial codecov verdicts (#15759)

Reinier van der Leer2b08ce32a9a1
diff --git a/.secrets.baseline b/.secrets.baseline
index 58903372b5..705ae50425 100644
--- a/.secrets.baseline
+++ b/.secrets.baseline
@@ -432,7 +432,7 @@
"filename": "autogpt_platform/docker-compose.platform.yml",
"hashed_secret": "de6b16a1aa2c97b8963a4f966774ae09fbe47300",
"is_verified": false,
- "line_number": 37,
+ "line_number": 35,
"is_secret": false
}
],
@@ -640,5 +640,5 @@
}
]
},
- "generated_at": "2026-09-27T20:56:19Z"
+ "generated_at": "2026-10-20T07:41:23Z"
}
diff --git a/autogpt_platform/backend/backend/api/rest_api.py b/autogpt_platform/backend/backend/api/rest_api.py
index fbcae42e01..44c4513f20 100644
--- a/autogpt_platform/backend/backend/api/rest_api.py
+++ b/autogpt_platform/backend/backend/api/rest_api.py
@@ -112,6 +112,7 @@ from backend.util.exceptions import (
NotFoundError,
PreconditionFailed,
)
+from backend.util.process import freeze_startup_heap
from backend.util.service import UnhealthyServiceError
from backend.util.url_redaction import redact_url
from backend.util.workspace_storage import shutdown_workspace_storage
@@ -196,6 +197,8 @@ async def lifespan_context(app: fastapi.FastAPI):
# Fail-hard: the catalog is load-bearing — a broken load stops the boot.
backend.data.llm_registry.load_catalog()
+ freeze_startup_heap()
+
yield
try:
diff --git a/autogpt_platform/backend/backend/copilot/executor/manager.py b/autogpt_platform/backend/backend/copilot/executor/manager.py
index 07c096be3d..754f0859b3 100644
--- a/autogpt_platform/backend/backend/copilot/executor/manager.py
+++ b/autogpt_platform/backend/backend/copilot/executor/manager.py
@@ -18,6 +18,7 @@ from pika.spec import Basic, BasicProperties
from prometheus_client import Gauge, start_http_server
import backend.data.llm_registry
+from backend.blocks import get_blocks
from backend.copilot import engine_switch
from backend.copilot.executor.utils import schedule_turn
from backend.data import redis_client as redis
@@ -26,7 +27,7 @@ from backend.executor.cluster_lock import ClusterLock
from backend.integrations.codex.transport import get_codex_transport
from backend.util.decorator import error_logged
from backend.util.logging import TruncatedLogger
-from backend.util.process import AppProcess
+from backend.util.process import AppProcess, freeze_startup_heap
from backend.util.retry import continuous_retry
from backend.util.settings import Settings
@@ -115,6 +116,14 @@ class CoPilotExecutor(AppProcess):
logger.info(f"Spawn max-{self.pool_size} workers...")
_load_catalog()
+ # Load the block registry before taking turns. A turn's first tool call
+ # loads it otherwise, and the collections over the grown heap stall every turn.
+ load_started = time.monotonic()
+ block_count = len(get_blocks())
+ logger.info(
+ f"Loaded {block_count} blocks in {time.monotonic() - load_started:.1f}s"
+ )
+ freeze_startup_heap()
# Materialise the active-tasks lock NOW, before any worker threads
# exist, so subsequent multi-threaded reads of the lazy property
diff --git a/autogpt_platform/backend/backend/copilot/executor/manager_block_warmup_test.py b/autogpt_platform/backend/backend/copilot/executor/manager_block_warmup_test.py
new file mode 100644
index 0000000000..20e663b857
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/executor/manager_block_warmup_test.py
@@ -0,0 +1,42 @@
+"""The copilot executor must load the block registry before it takes any turn."""
+
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+from backend.copilot.executor.manager import CoPilotExecutor
+
+
+class _StopRunLoop(Exception):
+ pass
+
+
+def test_run_loads_blocks_and_freezes_the_heap_before_taking_turns() -> None:
+ """Otherwise a turn's first tool call loads every block, and the full
+ collections over the grown heap stall every turn on the pod for seconds."""
+ executor = CoPilotExecutor()
+ order: list[str] = []
+ executor._cancel_thread = MagicMock()
+ executor._cancel_thread.start.side_effect = lambda: order.append("cancel_thread")
+ executor._run_thread = MagicMock()
+ executor._run_thread.start.side_effect = lambda: order.append("run_thread")
+
+ def load_blocks() -> dict:
+ order.append("load_blocks")
+ return {}
+
+ with (
+ patch("backend.copilot.executor.manager._load_catalog"),
+ patch("backend.copilot.executor.manager.get_blocks", side_effect=load_blocks),
+ patch(
+ "backend.copilot.executor.manager.freeze_startup_heap",
+ side_effect=lambda: order.append("freeze_heap"),
+ ),
+ patch("backend.copilot.executor.manager.start_http_server"),
+ patch.object(CoPilotExecutor, "_update_metrics"),
+ patch("backend.copilot.executor.manager.time.sleep", side_effect=_StopRunLoop),
+ pytest.raises(_StopRunLoop),
+ ):
+ executor.run()
+
+ assert order == ["load_blocks", "freeze_heap", "cancel_thread", "run_thread"]
diff --git a/autogpt_platform/backend/backend/data/e2e_redis_restart_test.py b/autogpt_platform/backend/backend/data/e2e_redis_restart_test.py
index cad8210e24..7ed07eca56 100644
--- a/autogpt_platform/backend/backend/data/e2e_redis_restart_test.py
+++ b/autogpt_platform/backend/backend/data/e2e_redis_restart_test.py
@@ -55,7 +55,35 @@ def _wait_port(port: int, *, deadline_s: float = 60.0) -> None:
return
except OSError:
time.sleep(0.5)
- raise TimeoutError(f"port {port} never opened within {deadline_s:.0f}s")
+ raise TimeoutError(
+ f"port {port} never opened within {deadline_s:.0f}s\n{_shard_state(port)}"
+ )
+
+
+def _shard_state(port: int) -> str:
+ """The containers' state and the shard's own log, so a shard that never
+ listens says why."""
+ name = f"{ISOLATED_PROJECT}-redis-{ISOLATED_PORTS.index(port)}"
+ return _diagnostic(
+ [
+ "docker",
+ "ps",
+ "-a",
+ "--filter",
+ f"name={ISOLATED_PROJECT}",
+ "--format",
+ "{{.Names}} {{.Status}} {{.Ports}}",
+ ]
+ ) + _diagnostic(["docker", "logs", "--tail", "50", name])
+
+
+def _diagnostic(cmd: list[str]) -> str:
+ # Best-effort: a hung or missing docker must not replace the error it explains.
+ try:
+ rc = _run(cmd, timeout=5.0)
+ except (subprocess.TimeoutExpired, OSError) as e:
+ return f"{' '.join(cmd)}: unavailable ({type(e).__name__})\n"
+ return f"{' '.join(cmd)}:\n{rc.stdout}{rc.stderr}"
def _start_isolated_cluster() -> None:
diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.py
index 388639d9a6..41f06306a2 100644
--- a/autogpt_platform/backend/backend/executor/manager.py
+++ b/autogpt_platform/backend/backend/executor/manager.py
@@ -81,7 +81,7 @@ from backend.util.exceptions import (
from backend.util.file import clean_exec_files
from backend.util.llm.saturation import set_executor_id
from backend.util.logging import TruncatedLogger, configure_logging
-from backend.util.process import AppProcess, set_service_name
+from backend.util.process import AppProcess, freeze_startup_heap, set_service_name
from backend.util.retry import (
continuous_retry,
func_retry,
@@ -1675,6 +1675,7 @@ class ExecutionManager(AppProcess):
f"[{self.service_name}] Loaded {block_count} blocks in "
f"{time.monotonic() - load_started:.1f}s"
)
+ freeze_startup_heap()
self.cancel_thread.start()
self.run_thread.start()
diff --git a/autogpt_platform/backend/backend/executor/manager_block_warmup_test.py b/autogpt_platform/backend/backend/executor/manager_block_warmup_test.py
index e233cf079f..3e4b8371ae 100644
--- a/autogpt_platform/backend/backend/executor/manager_block_warmup_test.py
+++ b/autogpt_platform/backend/backend/executor/manager_block_warmup_test.py
@@ -31,6 +31,10 @@ def test_run_loads_blocks_before_taking_runs() -> None:
with (
patch("backend.blocks.load_all_blocks", side_effect=load_blocks),
+ patch(
+ "backend.executor.manager.freeze_startup_heap",
+ side_effect=lambda: order.append("freeze_heap"),
+ ),
patch("backend.executor.manager.start_http_server"),
patch.object(ExecutionManager, "_update_prompt_metrics"),
patch("backend.executor.manager.time.sleep", side_effect=_StopRunLoop),
@@ -38,4 +42,4 @@ def test_run_loads_blocks_before_taking_runs() -> None:
):
manager.run()
- assert order == ["load_blocks", "cancel_thread", "run_thread"]
+ assert order == ["load_blocks", "freeze_heap", "cancel_thread", "run_thread"]
diff --git a/autogpt_platform/backend/backend/executor/scheduler.py b/autogpt_platform/backend/backend/executor/scheduler.py
index b3d34a9c4d..0323f53dbe 100644
--- a/autogpt_platform/backend/backend/executor/scheduler.py
+++ b/autogpt_platform/backend/backend/executor/scheduler.py
@@ -42,6 +42,7 @@ from backend.api.features.onboarding_dump.retention import (
purge_expired_recordings,
)
from backend.api.features.onboarding_dump.storage import RECORDING_PURGE_INTERVAL
+from backend.blocks import get_blocks
from backend.copilot.active_turns import ConcurrentTurnLimitError
from backend.copilot.at_reset import (
AT_RESET_JOB_NAMES,
@@ -2832,6 +2833,15 @@ class Scheduler(AppService):
def run_service(self):
load_dotenv()
+ # Load the block registry before serving. Otherwise the first add-schedule
+ # loads it inside graph validation, and the scheduler freezes meanwhile.
+ load_started = time.monotonic()
+ block_count = len(get_blocks())
+ logger.info(
+ f"[{self.service_name}] Loaded {block_count} blocks in "
+ f"{time.monotonic() - load_started:.1f}s"
+ )
+
# Initialize the event loop for async jobs
global _event_loop
_event_loop = asyncio.new_event_loop()
diff --git a/autogpt_platform/backend/backend/util/process.py b/autogpt_platform/backend/backend/util/process.py
index ba15818c94..ae45bb0167 100644
--- a/autogpt_platform/backend/backend/util/process.py
+++ b/autogpt_platform/backend/backend/util/process.py
@@ -1,7 +1,9 @@
+import gc
import logging
import os
import signal
import sys
+import time
from abc import ABC, abstractmethod
from multiprocessing import Process, get_all_start_methods, set_start_method
from typing import ClassVar, Optional
@@ -11,7 +13,12 @@ from backend.util.logging import configure_logging
from backend.util.metrics import sentry_init
from backend.util.retry import stop_retry_loops
from backend.util.secrets_guard import check_secrets
-from backend.util.settings import AppEnvironment, Config, set_service_name
+from backend.util.settings import (
+ AppEnvironment,
+ Config,
+ get_service_name,
+ set_service_name,
+)
logger = logging.getLogger(__name__)
@@ -191,3 +198,20 @@ class AppProcess(ABC):
logger.info(f"[{self.service_name}] with PID {pid} stopped")
self.process = None
+
+
+def freeze_startup_heap() -> None:
+ """Exempt every object alive now from later full garbage collections.
+
+ Call once startup is done. A full collection walks every tracked object
+ with the GIL held, and the ~2M the block registry leaves stopped all
+ threads for ~0.5 s each time, and for seconds on a swapping CI runner.
+ """
+ started = time.monotonic()
+ # Collect first: garbage still in the heap would otherwise be frozen in place.
+ gc.collect()
+ gc.freeze()
+ logger.info(
+ f"[{get_service_name()}] Froze {gc.get_freeze_count()} startup objects "
+ f"out of full garbage collections in {time.monotonic() - started:.1f}s"
+ )
diff --git a/autogpt_platform/backend/backend/util/process_test.py b/autogpt_platform/backend/backend/util/process_test.py
index c8959a7d3e..7cd800b34a 100644
--- a/autogpt_platform/backend/backend/util/process_test.py
+++ b/autogpt_platform/backend/backend/util/process_test.py
@@ -1,9 +1,11 @@
+import gc
import importlib
import logging
import multiprocessing
import signal
import threading
import time
+import weakref
import pytest
@@ -171,6 +173,40 @@ def test_local_starts_no_flags(mocker):
assert order == NO_FLAGS
+def unfrozen_heap():
+ gc.unfreeze()
+ yield
+ gc.unfreeze()
+
+
+def test_freezing_exempts_the_live_heap_from_full_collections(unfrozen_heap):
+ assert gc.get_freeze_count() == 0
+
+ process_module.freeze_startup_heap()
+
+ assert gc.get_freeze_count() > 0
+
+
+def test_garbage_left_by_startup_is_collected_not_frozen(unfrozen_heap):
+ class Node:
+ cycle: object
+
+ # Only the helper's own collection may free the cycle, not an automatic one.
+ gc.disable()
+ try:
+ node = Node()
+ node.cycle = node
+ alive = weakref.ref(node)
+ del node
+
+ process_module.freeze_startup_heap()
+ finally:
+ gc.enable()
+
+ assert alive() is None
+
+
def _record_lifecycle(mocker, instance: AppProcess) -> list[str]:
order: list[str] = []
diff --git a/autogpt_platform/backend/backend/util/service.py b/autogpt_platform/backend/backend/util/service.py
index 134f905edd..c9c622c45c 100644
--- a/autogpt_platform/backend/backend/util/service.py
+++ b/autogpt_platform/backend/backend/util/service.py
@@ -41,7 +41,7 @@ from backend.monitoring.instrumentation import instrument_fastapi
from backend.util import tracing
from backend.util.json import to_dict
from backend.util.metrics import sentry_init
-from backend.util.process import AppProcess
+from backend.util.process import AppProcess, freeze_startup_heap
from backend.util.retry import conn_retry, create_retry_decorator, stop_retry_loops
from backend.util.settings import Config, get_service_name
@@ -55,6 +55,10 @@ api_comm_retry = config.pyro_client_comm_retry
api_comm_timeout = config.pyro_client_comm_timeout
api_call_timeout = config.rpc_client_call_timeout
api_comm_max_wait = config.pyro_client_max_wait
+# A client retires an idle pooled connection long before the server closes it: a
+# call written into a connection as the server closes it fails with httpx.ReadError.
+rpc_server_keepalive_seconds = 60
+rpc_client_keepalive_expiry_seconds = rpc_server_keepalive_seconds / 2
def _validate_no_prisma_objects(obj: Any, path: str = "result") -> None:
@@ -421,6 +425,7 @@ class AppService(BaseAppService, ABC):
self.fastapi_app,
host=api_host,
port=self.get_port(),
+ timeout_keep_alive=rpc_server_keepalive_seconds,
log_config=None, # Explicitly None to avoid uvicorn replacing the logger.
log_level=self.log_level,
)
@@ -525,7 +530,7 @@ class AppService(BaseAppService, ABC):
def build_fastapi_app(self) -> FastAPI:
"""The service's HTTP app: one POST route per exposed method, the
health checks and metrics, and nothing else."""
- app = FastAPI(lifespan=self.lifespan)
+ app = FastAPI(lifespan=self._serving_lifespan)
# Add Prometheus instrumentation to all services
try:
@@ -561,6 +566,13 @@ class AppService(BaseAppService, ABC):
self._register_exception_handlers(app)
return app
+ @asynccontextmanager
+ async def _serving_lifespan(self, app: FastAPI):
+ async with self.lifespan(app):
+ # After every subclass's startup, so its long-lived state is frozen too.
+ freeze_startup_heap()
+ yield
+
# --------------------------------------------------
# HTTP Client utilities for dynamic service client abstraction
@@ -705,7 +717,7 @@ def get_service_client(
limits=httpx.Limits(
max_keepalive_connections=200, # 10x default for async concurrent calls
max_connections=500, # High limit for burst handling
- keepalive_expiry=30.0, # Keep connections alive longer
+ keepalive_expiry=rpc_client_keepalive_expiry_seconds,
),
event_hooks={"request": [_send_trace_headers]},
)
@@ -717,7 +729,7 @@ def get_service_client(
limits=httpx.Limits(
max_keepalive_connections=200, # 10x default for async concurrent calls
max_connections=500, # High limit for burst handling
- keepalive_expiry=30.0, # Keep connections alive longer
+ keepalive_expiry=rpc_client_keepalive_expiry_seconds,
),
event_hooks={"request": [_send_trace_headers_async]},
)
diff --git a/autogpt_platform/backend/backend/util/service_test.py b/autogpt_platform/backend/backend/util/service_test.py
index e49b2630d4..eb29cf35e8 100644
--- a/autogpt_platform/backend/backend/util/service_test.py
+++ b/autogpt_platform/backend/backend/util/service_test.py
@@ -2,11 +2,13 @@ import asyncio
import contextlib
import inspect
import logging
+import sys
+import threading
import time
from datetime import datetime, timezone
from functools import cached_property
from typing import Annotated, Any, Protocol, cast
-from unittest.mock import Mock
+from unittest.mock import AsyncMock, Mock
import httpx
import orjson
@@ -1002,6 +1004,74 @@ async def test_health_check_during_shutdown(test_service):
# ============================================================================
+async def test_a_pooled_call_survives_a_server_freeze_past_its_idle_time(
+ keep_alive_service,
+):
+ """A call written into a pooled connection while the server is frozen past
+ that connection's idle time is answered, not reset (httpx.ReadError)."""
+ client = get_service_client(KeepAliveServiceClient)
+ await asyncio.gather(*(client.ping() for _ in range(3)))
+ # The service freezes from 4 s to 7 s of idle, across uvicorn's default 5 s
+ # keep-alive, which it must outlive; the calls arrive mid-freeze.
+ await get_service_client(KeepAliveServiceClient).hold_gil(after=4.0, seconds=3.0)
+ await asyncio.sleep(5.5)
+
+ assert await asyncio.gather(*(client.ping() for _ in range(3))) == [1, 1, 1]
+
+
+async def keep_alive_service():
+ service = KeepAliveService()
+ service.start(background=True)
+ try:
+ await wait_until_service_ready(f"http://localhost:{service.get_port()}")
+ yield service
+ finally:
+ service.stop()
+
+
+class KeepAliveService(AppService):
+ @classmethod
+ def get_port(cls) -> int:
+ return 18998
+
+ @expose
+ def ping(self) -> int:
+ return 1
+
+ @expose
+ def hold_gil(self, after: float, seconds: float) -> int:
+ """Freeze every other thread for *seconds*, starting *after* seconds from
+ now, as a full gen2 GC does: the event loop is then idle in select()."""
+ timer = threading.Timer(after, _spin_holding_gil, args=(seconds,))
+ timer.daemon = True
+ timer.start()
+ return 1
+
+
+class KeepAliveServiceClient(AppServiceClient):
+ @classmethod
+ def get_service_type(cls):
+ return KeepAliveService
+
+ ping = endpoint_to_async(KeepAliveService.ping)
+ hold_gil = endpoint_to_async(KeepAliveService.hold_gil)
+
+
+def _spin_holding_gil(seconds: float) -> None:
+ # A spinning thread keeps the GIL until another has waited a whole switch
+ # interval for it, so an interval this long hands it over only at the end.
+ previous = sys.getswitchinterval()
+ sys.setswitchinterval(seconds)
+ try:
+ deadline = time.perf_counter() + seconds
+ while time.perf_counter() < deadline:
+ pass
+ finally:
+ sys.setswitchinterval(previous)
+
+
class TestGetReturn:
"""Direct unit tests for DynamicClient._get_return typed-return contract."""
@@ -1239,3 +1309,34 @@ def test_an_untraced_rpc_carries_no_trace(sentry_transactions):
[request] = sent
assert "sentry-trace" not in request.headers
assert "baggage" not in request.headers
+
+
+async def test_an_app_service_freezes_its_heap_after_its_own_startup(mocker):
+ order: list[str] = []
+ mocker.patch("backend.util.service.redis_client.get_redis_async", AsyncMock())
+ mocker.patch("backend.util.service.redis_client.disconnect_async", AsyncMock())
+ mocker.patch(
+ "backend.util.service.freeze_startup_heap", lambda: order.append("freeze")
+ )
+ app = _StartupRecordingService(order).build_fastapi_app()
+
+ async with app.router.lifespan_context(app):
+ pass
+
+ assert order == ["subclass startup", "freeze"]
+
+
+class _StartupRecordingService(AppService):
+ def __init__(self, order: list[str]):
+ super().__init__()
+ self.order = order
+
+ @classmethod
+ def get_port(cls) -> int:
+ return 0
+
+ @contextlib.asynccontextmanager
+ async def lifespan(self, app: FastAPI):
+ async with super().lifespan(app):
+ self.order.append("subclass startup")
+ yield
diff --git a/autogpt_platform/docker-compose.platform.yml b/autogpt_platform/docker-compose.platform.yml
index 6e55c8fecb..58623fbbef 100644
--- a/autogpt_platform/docker-compose.platform.yml
+++ b/autogpt_platform/docker-compose.platform.yml
@@ -138,8 +138,11 @@ services:
<<: *redis-node
depends_on: [redis-0, redis-1, redis-2]
restart: "no"
+ # A started shard can take a second to accept connections, and this runs once: wait for every PONG.
command: >-
- sh -c "redis-cli -h redis-0 -p 17000 cluster info 2>/dev/null | grep -q cluster_state:ok ||
+ sh -c "for node in redis-0:17000 redis-1:17001 redis-2:17002; do
+ i=0; until redis-cli -h $${node%:*} -p $${node#*:} ping 2>/dev/null | grep -q PONG || [ $$i -ge 60 ]; do i=$$((i + 1)); sleep 0.5; done; done;
+ redis-cli -h redis-0 -p 17000 cluster info 2>/dev/null | grep -q cluster_state:ok ||
redis-cli --cluster create redis-0:17000 redis-1:17001 redis-2:17002 --cluster-replicas 0 --cluster-yes"
falkordb:
image: falkordb/falkordb:latest
@@ -536,6 +539,9 @@ services:
# directly; tables live in the platform schema (Prisma migrations).
DATABASE_URL: postgresql://postgres:your-super-secret-and-long-postgres-password@db:5432/postgres
AUTH_DB_SCHEMA: platform
+ # Node closes an idle keep-alive socket after 5 s (+1 s buffer); a client reusing one right then
+ # gets "socket hang up". Keep idle sockets longer than clients and proxies leave them unused.
+ KEEP_ALIVE_TIMEOUT: "65000"
volumes:
workspace-data:
store-media-data:
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/codex-session-route.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/codex-session-route.test.tsx
index 14b92e2446..d623d5b390 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/codex-session-route.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/codex-session-route.test.tsx
@@ -13,6 +13,8 @@ import { useChatSession } from "../useChatSession";
const testState = vi.hoisted(() => ({
transports: [] as ChatTransportResponse[] | null,
+ // What the inventory request still in flight answers with.
+ arrivingTransports: null as ChatTransportResponse[] | null,
transportError: false,
queryOptions: vi.fn(),
toast: vi.fn(),
@@ -35,6 +37,15 @@ vi.mock(
? undefined
: { status: 200, data: { transports: testState.transports } },
isError: testState.transportError,
+ refetch: async () => ({
+ data:
+ testState.arrivingTransports === null
+ ? undefined
+ : {
+ status: 200,
+ data: { transports: testState.arrivingTransports },
+ },
+ }),
};
},
};
@@ -115,6 +126,7 @@ function captureCreateRequest() {
afterEach(() => {
server.resetHandlers();
testState.transports = [];
+ testState.arrivingTransports = null;
testState.transportError = false;
testState.queryOptions.mockClear();
testState.toast.mockClear();
@@ -228,7 +240,19 @@ describe("useChatSession transport route", () => {
expect(getRequestBody()).toBeUndefined();
});
- it("blocks while the transport inventory is loading", async () => {
+ it("waits for a transport inventory still loading, then creates the session", async () => {
+ testState.transports = null;
+ testState.arrivingTransports = [hostedPlatform];
+ const getRequestBody = captureCreateRequest();
+ render(<SessionHarness />);
+
+ fireEvent.click(screen.getByRole("button", { name: "Create session" }));
+
+ await waitFor(() => expect(getRequestBody()).toBeDefined());
+ expect(testState.toast).not.toHaveBeenCalled();
+ });
+
+ it("blocks when the transport inventory never arrives", async () => {
testState.transports = null;
const getRequestBody = captureCreateRequest();
render(<SessionHarness />);
@@ -237,9 +261,7 @@ describe("useChatSession transport route", () => {
await waitFor(() => {
expect(testState.toast).toHaveBeenCalledWith(
- expect.objectContaining({
- title: "AI connections are still loading",
- }),
+ expect.objectContaining({ title: "Could not check AI connections" }),
);
});
expect(getRequestBody()).toBeUndefined();
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/paywall-send.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/paywall-send.test.tsx
index ad3c30bce2..3dcf20b808 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/paywall-send.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/paywall-send.test.tsx
@@ -61,6 +61,8 @@ vi.mock(
},
},
isError: false,
+ // A list still loading never arrives in these tests.
+ refetch: async () => ({ data: undefined }),
}),
}),
);
@@ -171,13 +173,13 @@ describe("a refused first send", () => {
expect(textarea.value).toBe("hello");
});
- it("says once that AI connections are still loading", async () => {
+ it("says once that AI connections could not be checked", async () => {
transports.loaded = false;
const textarea = await send("too quick");
expect(toast).toHaveBeenCalledOnce();
expect(toast).toHaveBeenCalledWith(
- expect.objectContaining({ title: "AI connections are still loading" }),
+ expect.objectContaining({ title: "Could not check AI connections" }),
);
expect(textarea.value).toBe("too quick");
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts
index ce02d8fe30..ddece1bbdc 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts
@@ -276,12 +276,15 @@ export function useChatSession({
// has asked for a new thread, auto-navigating them into an old one is
// never the right recovery.
sendStartedRef.current = true;
+ const transports =
+ chatTransports ??
+ (transportQuery.isError ? undefined : await loadChatTransports());
const resolvedLLMAuth = resolveCopilotLLMAuthSelection(
- chatTransports,
+ transports,
copilotLlmAuth,
);
- const availableTransports = getAvailableLLMTransports(chatTransports);
- if (transportQuery.isError && chatTransports === undefined) {
+ const availableTransports = getAvailableLLMTransports(transports);
+ if (transports === undefined) {
toast({
variant: "destructive",
title: "Could not check AI connections",
@@ -289,7 +292,7 @@ export function useChatSession({
});
throw new ReportedSendError("Could not load AI connections");
}
- if (chatTransports !== undefined && availableTransports.length === 0) {
+ if (availableTransports.length === 0) {
// NoAIConnectionNotice above the composer says how to fix this and
// stays put; the toast only marks that this send went nowhere.
toast({
@@ -301,21 +304,13 @@ export function useChatSession({
throw new ReportedSendError("No AI connection is set up");
}
if (!resolvedLLMAuth) {
- const connectionsAreLoading = chatTransports === undefined;
toast({
variant: "destructive",
- title: connectionsAreLoading
- ? "AI connections are still loading"
- : "Choose an AI connection",
- description: connectionsAreLoading
- ? "Wait a moment and try again."
- : "Select the connection your expert should use before starting a new task.",
+ title: "Choose an AI connection",
+ description:
+ "Select the connection your expert should use before starting a new task.",
});
- throw new ReportedSendError(
- connectionsAreLoading
- ? "AI connections are still loading"
- : "AI connection selection required",
- );
+ throw new ReportedSendError("AI connection selection required");
}
if (
copilotLlmAuth !== null &&
@@ -399,6 +394,13 @@ export function useChatSession({
}
}
+ // A send typed before the connection list arrives waits for it instead of
+ // being refused; `cancelRefetch: false` joins the request already in flight.
+ async function loadChatTransports() {
+ const { data } = await transportQuery.refetch({ cancelRefetch: false });
+ return data?.status === 200 ? data.data.transports : undefined;
+ }
+
// Raw messages from the initial page — exposed for cross-page
// tool output matching by useLoadMoreMessages.
const rawSessionMessages =
diff --git a/codecov.yml b/codecov.yml
index a0973b5717..fd97412e56 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -40,10 +40,14 @@ flags:
paths:
- autogpt_platform/backend/
carryforward: true
+ # One upload per backend test shard (3 Pythons x 4 shards); a verdict from fewer is partial.
+ after_n_builds: 12
platform-frontend:
paths:
- autogpt_platform/frontend/src/
carryforward: true
+ # One upload per frontend integration test shard.
+ after_n_builds: 4
platform-frontend-e2e:
paths:
- autogpt_platform/frontend/src/