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): release bundle — block-execute billing + copilot stability (#13023)

Zamil Majdyfa88c27d6ad1
diff --git a/autogpt_platform/backend/backend/api/external/v1/routes.py b/autogpt_platform/backend/backend/api/external/v1/routes.py
index c17a006c3e..25f18eb7df 100644
--- a/autogpt_platform/backend/backend/api/external/v1/routes.py
+++ b/autogpt_platform/backend/backend/api/external/v1/routes.py
@@ -18,8 +18,10 @@ from backend.data import graph as graph_db
from backend.data import user as user_db
from backend.data.auth.base import APIAuthorizationInfo
from backend.data.block import BlockInput, CompletedBlockOutput
-from backend.data.credit import UsageTransactionMetadata, get_user_credit_model
-from backend.executor.utils import add_graph_execution, block_usage_cost
+from backend.executor.utils import (
+ add_graph_execution,
+ charge_for_direct_block_execution,
+)
from backend.integrations.webhooks.graph_lifecycle_hooks import on_graph_activate
from backend.util.exceptions import InsufficientBalanceError
from backend.util.settings import Settings
@@ -93,24 +95,14 @@ async def execute_graph_block(
if obj.disabled:
raise HTTPException(status_code=403, detail=f"Block #{block_id} is disabled.")
- cost, cost_filter = block_usage_cost(obj, data)
- if cost > 0:
- credit_model = await get_user_credit_model(auth.user_id)
- try:
- await credit_model.spend_credits(
- user_id=auth.user_id,
- cost=cost,
- metadata=UsageTransactionMetadata(
- block_id=block_id,
- block=obj.name,
- input=cost_filter,
- reason=f"Direct external API execution of block {obj.name}",
- ),
- )
- except InsufficientBalanceError as e:
- raise HTTPException(
- status_code=status.HTTP_402_PAYMENT_REQUIRED, detail=str(e)
- ) from e
+ try:
+ await charge_for_direct_block_execution(
+ user_id=auth.user_id, block=obj, input_data=data, source="external"
+ )
+ except InsufficientBalanceError as e:
+ raise HTTPException(
+ status_code=status.HTTP_402_PAYMENT_REQUIRED, detail=str(e)
+ ) from e
output = defaultdict(list)
async for name, data in obj.execute(data):
diff --git a/autogpt_platform/backend/backend/api/external/v1/routes_test.py b/autogpt_platform/backend/backend/api/external/v1/routes_test.py
index b0bace7aee..39e82b2ea5 100644
--- a/autogpt_platform/backend/backend/api/external/v1/routes_test.py
+++ b/autogpt_platform/backend/backend/api/external/v1/routes_test.py
@@ -6,7 +6,6 @@ import fastapi.testclient
import pytest
from prisma.enums import APIKeyPermission
-import backend.api.external.v1.routes as routes_mod
from backend.api.external.middleware import require_auth
from backend.api.external.v1.routes import v1_router
from backend.data.auth.base import APIAuthorizationInfo
@@ -61,7 +60,9 @@ def test_zero_balance_returns_402_on_paid_block(monkeypatch: pytest.MonkeyPatch)
"""Zero-credit user calling a paid block must be rejected before execution."""
block = _stub_block(name="PaidBlock")
monkeypatch.setattr("backend.blocks.get_block", lambda _: block)
- monkeypatch.setattr(routes_mod, "block_usage_cost", lambda *_a, **_k: (5, {}))
+ monkeypatch.setattr(
+ "backend.executor.utils.block_usage_cost", lambda *_a, **_k: (5, {})
+ )
spend_mock = AsyncMock(
side_effect=InsufficientBalanceError(
user_id="test-user-id",
@@ -71,8 +72,7 @@ def test_zero_balance_returns_402_on_paid_block(monkeypatch: pytest.MonkeyPatch)
)
)
monkeypatch.setattr(
- routes_mod,
- "get_user_credit_model",
+ "backend.executor.utils.get_user_credit_model",
AsyncMock(return_value=MagicMock(spend_credits=spend_mock)),
)
@@ -89,12 +89,12 @@ def test_paid_block_charges_then_runs(
block = _stub_block(name="PaidBlock")
monkeypatch.setattr("backend.blocks.get_block", lambda _: block)
monkeypatch.setattr(
- routes_mod, "block_usage_cost", lambda *_a, **_k: (3, {"matched": True})
+ "backend.executor.utils.block_usage_cost",
+ lambda *_a, **_k: (3, {"matched": True}),
)
spend_mock = AsyncMock(return_value=97)
monkeypatch.setattr(
- routes_mod,
- "get_user_credit_model",
+ "backend.executor.utils.get_user_credit_model",
AsyncMock(return_value=MagicMock(spend_credits=spend_mock)),
)
@@ -109,17 +109,19 @@ def test_paid_block_charges_then_runs(
assert kwargs["metadata"].block_id == block.id
assert kwargs["metadata"].block == "PaidBlock"
assert kwargs["metadata"].input == {"matched": True}
+ assert kwargs["metadata"].reason == "Direct external block execution of PaidBlock"
def test_free_block_runs_without_charging(monkeypatch: pytest.MonkeyPatch):
"""A block with cost == 0 should execute and never call spend_credits."""
block = _stub_block(name="FreeBlock")
monkeypatch.setattr("backend.blocks.get_block", lambda _: block)
- monkeypatch.setattr(routes_mod, "block_usage_cost", lambda *_a, **_k: (0, {}))
+ monkeypatch.setattr(
+ "backend.executor.utils.block_usage_cost", lambda *_a, **_k: (0, {})
+ )
spend_mock = AsyncMock()
monkeypatch.setattr(
- routes_mod,
- "get_user_credit_model",
+ "backend.executor.utils.get_user_credit_model",
AsyncMock(return_value=MagicMock(spend_credits=spend_mock)),
)
diff --git a/autogpt_platform/backend/backend/api/features/v1.py b/autogpt_platform/backend/backend/api/features/v1.py
index f8ad87fa22..4f3bd283bf 100644
--- a/autogpt_platform/backend/backend/api/features/v1.py
+++ b/autogpt_platform/backend/backend/api/features/v1.py
@@ -27,7 +27,11 @@ from fastapi import (
from fastapi.concurrency import run_in_threadpool
from prisma.enums import SubscriptionTier
from pydantic import BaseModel, Field
-from starlette.status import HTTP_204_NO_CONTENT, HTTP_404_NOT_FOUND
+from starlette.status import (
+ HTTP_204_NO_CONTENT,
+ HTTP_402_PAYMENT_REQUIRED,
+ HTTP_404_NOT_FOUND,
+)
from typing_extensions import Optional, TypedDict
from backend.api.features.workspace.routes import create_file_download_response
@@ -116,7 +120,11 @@ from backend.monitoring.instrumentation import (
from backend.util.cache import cached
from backend.util.clients import get_scheduler_client
from backend.util.cloud_storage import get_cloud_storage_handler
-from backend.util.exceptions import GraphValidationError, NotFoundError
+from backend.util.exceptions import (
+ GraphValidationError,
+ InsufficientBalanceError,
+ NotFoundError,
+)
from backend.util.feature_flag import Flag, is_feature_enabled
from backend.util.json import dumps
from backend.util.settings import Settings
@@ -469,6 +477,13 @@ async def execute_graph_block(
if not user:
raise HTTPException(status_code=404, detail="User not found.")
+ try:
+ await execution_utils.charge_for_direct_block_execution(
+ user_id=user_id, block=obj, input_data=data, source="internal"
+ )
+ except InsufficientBalanceError as e:
+ raise HTTPException(status_code=HTTP_402_PAYMENT_REQUIRED, detail=str(e)) from e
+
start_time = time.time()
try:
output = defaultdict(list)
diff --git a/autogpt_platform/backend/backend/api/features/v1_test.py b/autogpt_platform/backend/backend/api/features/v1_test.py
index eabec6e978..140cf3fab4 100644
--- a/autogpt_platform/backend/backend/api/features/v1_test.py
+++ b/autogpt_platform/backend/backend/api/features/v1_test.py
@@ -13,6 +13,7 @@ from pytest_snapshot.plugin import Snapshot
from backend.data.credit import AutoTopUpConfig
from backend.data.graph import GraphModel
+from backend.util.exceptions import InsufficientBalanceError
from .v1 import upload_file, v1_router
@@ -140,6 +141,7 @@ def test_execute_graph_block(
# Mock block
mock_block = Mock()
mock_block.disabled = False
+ mock_block.name = "TestBlock"
async def mock_execute(*args, **kwargs):
yield "output1", {"data": "result1"}
@@ -161,6 +163,17 @@ def test_execute_graph_block(
return_value=mock_user,
)
+ # Default to free block: cost = 0, no charge call.
+ cost_mock = mocker.patch(
+ "backend.api.features.v1.execution_utils.block_usage_cost",
+ return_value=(0, {}),
+ )
+ mock_credit_model = mocker.AsyncMock()
+ mocker.patch(
+ "backend.api.features.v1.get_user_credit_model",
+ return_value=mock_credit_model,
+ )
+
request_data = {
"input_name": "test_input",
"input_value": "test_value",
@@ -171,6 +184,10 @@ def test_execute_graph_block(
assert response.status_code == 200
response_data = response.json()
+ # Cost = 0 path: no spend_credits call.
+ cost_mock.assert_called_once()
+ mock_credit_model.spend_credits.assert_not_awaited()
+
snapshot.snapshot_dir = "snapshots"
snapshot.assert_match(
json.dumps(response_data, indent=2, sort_keys=True),
@@ -178,6 +195,103 @@ def test_execute_graph_block(
)
+def test_execute_graph_block_charges_when_cost_positive(
+ mocker: pytest_mock.MockFixture,
+) -> None:
+ """Paid blocks must charge credits before executing."""
+ mock_block = Mock()
+ mock_block.disabled = False
+ mock_block.id = "paid-block"
+ mock_block.name = "PaidBlock"
+
+ async def mock_execute(*args, **kwargs):
+ yield "output", {"data": "ok"}
+
+ mock_block.execute = mock_execute
+
+ mocker.patch(
+ "backend.api.features.v1.get_block",
+ return_value=mock_block,
+ )
+ mock_user = Mock()
+ mock_user.timezone = "UTC"
+ mocker.patch(
+ "backend.api.features.v1.get_user_by_id",
+ return_value=mock_user,
+ )
+
+ cost_filter = {"model": "gpt-4"}
+ mocker.patch(
+ "backend.executor.utils.block_usage_cost",
+ return_value=(42, cost_filter),
+ )
+ mock_credit_model = mocker.AsyncMock()
+ mocker.patch(
+ "backend.executor.utils.get_user_credit_model",
+ return_value=mock_credit_model,
+ )
+
+ response = client.post(
+ "/blocks/paid-block/execute", json={"input_name": "x", "input_value": "y"}
+ )
+
+ assert response.status_code == 200
+ mock_credit_model.spend_credits.assert_awaited_once()
+ call_kwargs = mock_credit_model.spend_credits.await_args.kwargs
+ assert call_kwargs["cost"] == 42
+ metadata = call_kwargs["metadata"]
+ assert metadata.block_id == "paid-block"
+ assert metadata.block == "PaidBlock"
+ assert metadata.input == cost_filter
+ assert metadata.reason == "Direct internal block execution of PaidBlock"
+
+
+def test_execute_graph_block_returns_402_on_insufficient_balance(
+ mocker: pytest_mock.MockFixture,
+ test_user_id: str,
+) -> None:
+ """If spend_credits raises InsufficientBalanceError, endpoint returns 402."""
+ mock_block = Mock()
+ mock_block.disabled = False
+ mock_block.id = "paid-block"
+ mock_block.name = "PaidBlock"
+ mock_block.execute = AsyncMock()
+
+ mocker.patch(
+ "backend.api.features.v1.get_block",
+ return_value=mock_block,
+ )
+ mock_user = Mock()
+ mock_user.timezone = "UTC"
+ mocker.patch(
+ "backend.api.features.v1.get_user_by_id",
+ return_value=mock_user,
+ )
+ mocker.patch(
+ "backend.executor.utils.block_usage_cost",
+ return_value=(99, {}),
+ )
+
+ mock_credit_model = mocker.AsyncMock()
+ mock_credit_model.spend_credits.side_effect = InsufficientBalanceError(
+ message="Insufficient balance",
+ user_id=test_user_id,
+ balance=10,
+ amount=99,
+ )
+ mocker.patch(
+ "backend.executor.utils.get_user_credit_model",
+ return_value=mock_credit_model,
+ )
+
+ response = client.post(
+ "/blocks/paid-block/execute", json={"input_name": "x", "input_value": "y"}
+ )
+
+ assert response.status_code == 402
+ mock_block.execute.assert_not_called()
+
+
def test_execute_graph_block_not_found(
mocker: pytest_mock.MockFixture,
) -> None:
@@ -574,10 +688,12 @@ async def test_upload_file_success(test_user_id: str):
)
# Mock dependencies
- with patch("backend.api.features.v1.scan_content_safe") as mock_scan, patch(
- "backend.api.features.v1.get_cloud_storage_handler"
- ) as mock_handler_getter:
-
+ with (
+ patch("backend.api.features.v1.scan_content_safe") as mock_scan,
+ patch(
+ "backend.api.features.v1.get_cloud_storage_handler"
+ ) as mock_handler_getter,
+ ):
mock_scan.return_value = None
mock_handler = AsyncMock()
mock_handler.store_file.return_value = "gcs://test-bucket/uploads/123/test.txt"
@@ -624,10 +740,12 @@ async def test_upload_file_no_filename(test_user_id: str):
),
)
- with patch("backend.api.features.v1.scan_content_safe") as mock_scan, patch(
- "backend.api.features.v1.get_cloud_storage_handler"
- ) as mock_handler_getter:
-
+ with (
+ patch("backend.api.features.v1.scan_content_safe") as mock_scan,
+ patch(
+ "backend.api.features.v1.get_cloud_storage_handler"
+ ) as mock_handler_getter,
+ ):
mock_scan.return_value = None
mock_handler = AsyncMock()
mock_handler.store_file.return_value = (
@@ -705,10 +823,12 @@ async def test_upload_file_cloud_storage_failure(test_user_id: str):
headers=starlette.datastructures.Headers({"content-type": "text/plain"}),
)
- with patch("backend.api.features.v1.scan_content_safe") as mock_scan, patch(
- "backend.api.features.v1.get_cloud_storage_handler"
- ) as mock_handler_getter:
-
+ with (
+ patch("backend.api.features.v1.scan_content_safe") as mock_scan,
+ patch(
+ "backend.api.features.v1.get_cloud_storage_handler"
+ ) as mock_handler_getter,
+ ):
mock_scan.return_value = None
mock_handler = AsyncMock()
mock_handler.store_file.side_effect = RuntimeError("Storage error!")
@@ -752,10 +872,12 @@ async def test_upload_file_gcs_not_configured_fallback(test_user_id: str):
headers=starlette.datastructures.Headers({"content-type": "text/plain"}),
)
- with patch("backend.api.features.v1.scan_content_safe") as mock_scan, patch(
- "backend.api.features.v1.get_cloud_storage_handler"
- ) as mock_handler_getter:
-
+ with (
+ patch("backend.api.features.v1.scan_content_safe") as mock_scan,
+ patch(
+ "backend.api.features.v1.get_cloud_storage_handler"
+ ) as mock_handler_getter,
+ ):
mock_scan.return_value = None
mock_handler = AsyncMock()
mock_handler.config.gcs_bucket_name = "" # Simulate no GCS bucket configured
diff --git a/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py b/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py
index c5fd114d40..99a66dbff7 100644
--- a/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py
+++ b/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py
@@ -55,10 +55,16 @@ class ReplicateModelBlock(Block):
placeholder="stability-ai/stable-diffusion",
advanced=False,
)
- model_inputs: dict[str, str | int] = SchemaField(
+ model_inputs: dict[str, str | int | float | bool] = SchemaField(
default={},
- description="Dictionary of inputs to pass to the model",
- placeholder='{"prompt": "a beautiful landscape", "num_outputs": 1}',
+ description=(
+ "Dictionary of inputs to pass to the model. Values may be "
+ "strings, integers, floats, or booleans — Replicate model "
+ "schemas commonly require booleans (e.g. ``generate_audio``, "
+ "``safety_checker``) and floats (e.g. ``temperature``, "
+ "``guidance_scale``)."
+ ),
+ placeholder='{"prompt": "a beautiful landscape", "num_outputs": 1, "generate_audio": false}',
advanced=False,
)
version: Optional[str] = SchemaField(
@@ -83,7 +89,12 @@ class ReplicateModelBlock(Block):
test_input={
"credentials": TEST_CREDENTIALS_INPUT,
"model_name": "meta/llama-2-7b-chat",
- "model_inputs": {"prompt": "Hello, world!", "max_new_tokens": 50},
+ "model_inputs": {
+ "prompt": "Hello, world!",
+ "max_new_tokens": 50,
+ "temperature": 0.7,
+ "stream": False,
+ },
},
test_credentials=TEST_CREDENTIALS,
test_output=[
diff --git a/autogpt_platform/backend/backend/copilot/constants.py b/autogpt_platform/backend/backend/copilot/constants.py
index 986a641c7e..20b0eff09e 100644
--- a/autogpt_platform/backend/backend/copilot/constants.py
+++ b/autogpt_platform/backend/backend/copilot/constants.py
@@ -14,6 +14,12 @@ COPILOT_SYSTEM_PREFIX = "[__COPILOT_SYSTEM_e3b0__]" # Renders as system info me
# at turn start so the next turn's --resume transcript doesn't carry it.
STOPPED_BY_USER_MARKER = f"{COPILOT_SYSTEM_PREFIX} Execution stopped by user"
+# User-facing notice surfaced when the SDK CLI ends without a ResultMessage —
+# almost always a CLI-side kill (per-query budget exhausted, max_turns hit,
+# OOM, or crash). Not a user cancel: the cancel path raises
+# ``asyncio.CancelledError`` and never reaches this branch.
+STREAM_INCOMPLETE_MARKER = f"{COPILOT_SYSTEM_PREFIX} Reached the per-query spend limit or the assistant ended without a final response. Send a follow-up message to continue from here."
+
# Prefix for all synthetic IDs generated by CoPilot block execution.
# Used to distinguish CoPilot-generated records from real graph execution records
# in PendingHumanReview and other tables.
@@ -49,6 +55,11 @@ MAX_TOOL_WAIT_SECONDS = 5 * 60 # 5 minutes
# "no tool blocks >= idle_timeout" holds by construction.
STREAM_IDLE_TIMEOUT_SECONDS = MAX_TOOL_WAIT_SECONDS * 2 # 10 minutes
+# Redis key prefix for the SDK-stream-level lock that ensures only one
+# active SDK stream per session. Released by the SDK turn's finally block
+# and force-released by mark_session_completed on cancel/error.
+STREAM_LOCK_PREFIX = "copilot:stream:lock:"
+
def is_copilot_synthetic_id(id_value: str) -> bool:
"""Check if an ID is a CoPilot synthetic ID (not from a real graph execution)."""
diff --git a/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py b/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py
index 4b8d9b89d2..35bba66573 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/response_adapter.py
@@ -420,9 +420,9 @@ class SDKResponseAdapter:
)
# Pair with StreamFinish so ``acc.stream_completed`` flips True
# in ``_dispatch_response`` — without it the service-layer
- # post-stream branch mis-classifies the turn as "stopped by
- # user" and appends a STOPPED_BY_USER_MARKER on top of the
- # error marker.
+ # post-stream branch falls into the CLI-side-kill path and
+ # appends a STREAM_INCOMPLETE_MARKER on top of the error
+ # marker.
responses.append(StreamFinish())
logger.warning(
"[SDK] [%s] Empty-success ResultMessage detected — "
diff --git a/autogpt_platform/backend/backend/copilot/sdk/response_adapter_test.py b/autogpt_platform/backend/backend/copilot/sdk/response_adapter_test.py
index 268e8c76d4..3281b388e4 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/response_adapter_test.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/response_adapter_test.py
@@ -761,7 +761,7 @@ def test_result_empty_success_emits_error_and_finish():
no produced content, and ``output_tokens == 0`` is the SDK's ghost-finish
bug. The adapter surfaces it as a ``StreamError`` *paired with*
``StreamFinish`` so the service-layer post-stream flow flips
- ``acc.stream_completed`` and skips the ``STOPPED_BY_USER_MARKER``
+ ``acc.stream_completed`` and skips the ``STREAM_INCOMPLETE_MARKER``
branch. ``SystemMessage(subtype="init")`` opened a step, so the
empty-completion branch must close it before emitting the error."""
adapter = _adapter()
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service.py b/autogpt_platform/backend/backend/copilot/sdk/service.py
index 29d14aa35e..90c136af10 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service.py
@@ -51,7 +51,8 @@ from ..constants import (
COPILOT_ERROR_PREFIX,
COPILOT_RETRYABLE_ERROR_PREFIX,
FRIENDLY_TRANSIENT_MSG,
- STOPPED_BY_USER_MARKER,
+ STREAM_INCOMPLETE_MARKER,
+ STREAM_LOCK_PREFIX,
is_transient_api_error,
)
from ..session_cleanup import prune_orphan_tool_calls
@@ -101,6 +102,7 @@ from ..response_model import (
StreamStatus,
StreamTextDelta,
StreamTextEnd,
+ StreamTextStart,
StreamToolInputAvailable,
StreamToolInputStart,
StreamToolOutputAvailable,
@@ -1574,9 +1576,6 @@ _SWEEP_INTERVAL_SECONDS = 300 # 5 minutes
_HEARTBEAT_INTERVAL = 10.0 # seconds
-STREAM_LOCK_PREFIX = "copilot:stream:lock:"
-
-
async def _safe_close_sdk_client(
sdk_client: ClaudeSDKClient,
log_prefix: str,
@@ -3172,7 +3171,8 @@ async def _run_stream_attempt(
Opens a `ClaudeSDKClient`, sends the query, iterates SDK messages with
heartbeat timeouts, dispatches adapter responses, and performs post-stream
- cleanup (safety-net flush, stopped-by-user handling).
+ cleanup (safety-net flush, CLI-side end-of-stream notice when the
+ iterator drains without a ``ResultMessage``).
Yields stream events. On stream error the exception propagates to the
caller so the retry loop can rollback and retry.
@@ -3357,16 +3357,24 @@ async def _run_stream_attempt(
yield response
if not acc.stream_completed and not loop_state.ended_with_stream_error:
+ # User cancels raise ``asyncio.CancelledError`` upstream; reaching this
+ # branch means the CLI hung up — per-query budget exhausted, max_turns,
+ # OOM, or crash — without ever emitting a ResultMessage.
logger.info(
- "%s Stream ended without ResultMessage (stopped by user)",
+ "%s Stream ended without ResultMessage — likely CLI-side kill "
+ "(budget/turns/crash)",
ctx.log_prefix,
)
closing_responses: list[StreamBaseResponse] = []
state.adapter._end_text_if_open(closing_responses)
for r in closing_responses:
yield r
+ notice_block_id = str(uuid.uuid4())
+ yield StreamTextStart(id=notice_block_id)
+ yield StreamTextDelta(id=notice_block_id, delta=STREAM_INCOMPLETE_MARKER)
+ yield StreamTextEnd(id=notice_block_id)
ctx.session.messages.append(
- ChatMessage(role="assistant", content=STOPPED_BY_USER_MARKER)
+ ChatMessage(role="assistant", content=STREAM_INCOMPLETE_MARKER)
)
if (
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service_test.py b/autogpt_platform/backend/backend/copilot/sdk/service_test.py
index 5173323221..aaa1b790e4 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service_test.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service_test.py
@@ -1920,3 +1920,134 @@ class TestResolveDynamicMaxBudgetUsd:
):
result = await _resolve_dynamic_max_budget_usd("u-1")
assert result == 10.0
+
+
+class TestStreamEndedWithoutResultMessage:
+ """When the SDK CLI hangs up without a ResultMessage (per-query budget
+ exhausted, max_turns hit, OOM, crash) the post-stream branch must
+ surface a visible user-facing notice and append the notice as the
+ assistant ChatMessage — *not* the legacy ``STOPPED_BY_USER_MARKER``
+ which mis-classified the event as a user cancel."""
+
+ def _ctx(self, session_id="s1"):
+ from datetime import UTC, datetime
+
+ from backend.copilot.model import ChatSession
+ from backend.copilot.sdk.compaction import CompactionTracker
+ from backend.copilot.sdk.service import _StreamContext
+
+ now = datetime.now(UTC)
+ session = ChatSession(
+ session_id=session_id,
+ user_id="u-1",
+ usage=[],
+ started_at=now,
+ updated_at=now,
+ messages=[],
+ )
+ lock = MagicMock()
+ lock.refresh = AsyncMock()
+ attachments = MagicMock()
+ attachments.image_blocks = []
+ return _StreamContext(
+ session=session,
+ session_id=session_id,
+ log_prefix=f"[SDK] [{session_id[:8]}]",
+ sdk_cwd="/tmp/test",
+ current_message="hello",
+ file_ids=None,
+ message_id="m-1",
+ attachments=attachments,
+ compaction=CompactionTracker(),
+ lock=lock,
+ )
+
+ def _state(self, session_id="s1"):
+ from backend.copilot.sdk.response_adapter import SDKResponseAdapter
+ from backend.copilot.sdk.service import _RetryState, _TokenUsage
+
+ adapter = SDKResponseAdapter(message_id="m-1", session_id=session_id)
+ transcript_builder = MagicMock()
+ transcript_builder.append_user = MagicMock()
+ transcript_builder.append_assistant = MagicMock()
+ transcript_builder.append_tool_result = MagicMock()
+ return _RetryState(
+ options=MagicMock(),
+ query_message="hello",
+ was_compacted=False,
+ use_resume=False,
+ resume_file=None,
+ transcript_msg_count=0,
+ adapter=adapter,
+ transcript_builder=transcript_builder,
+ usage=_TokenUsage(),
+ )
+
+ @pytest.mark.asyncio
+ async def test_drain_without_resultmessage_surfaces_visible_notice(self):
+ """``_iter_sdk_messages`` exhausting without a ResultMessage is the
+ CLI-side-kill path. The branch must (a) yield visible
+ StreamTextStart/Delta/End carrying the notice text and (b) append
+ an assistant ChatMessage holding the notice — not the legacy
+ ``STOPPED_BY_USER_MARKER``."""
+ from backend.copilot.constants import (
+ STOPPED_BY_USER_MARKER,
+ STREAM_INCOMPLETE_MARKER,
+ )
+ from backend.copilot.response_model import (
+ StreamTextDelta,
+ StreamTextEnd,
+ StreamTextStart,
+ )
+ from backend.copilot.sdk.service import _run_stream_attempt
+
+ ctx = self._ctx()
+ state = self._state()
+
+ async def empty_iter(_client):
+ # Drain immediately — no ResultMessage ever arrives. Mirrors
+ # the CLI exiting on per-query ``max_budget_usd`` exhaustion
+ # mid-tool-call.
+ if False:
+ yield None # pragma: no cover (make this an async generator)
+
+ fake_client = MagicMock()
+ fake_client.query = AsyncMock()
+ fake_sdk_client = MagicMock()
+ fake_sdk_client.__aenter__ = AsyncMock(return_value=fake_client)
+ fake_sdk_client.__aexit__ = AsyncMock(return_value=False)
+
+ with (
+ patch(
+ "backend.copilot.sdk.service.ClaudeSDKClient",
+ return_value=fake_sdk_client,
+ ),
+ patch(
+ "backend.copilot.sdk.service._iter_sdk_messages",
+ new=empty_iter,
+ ),
+ ):
+ events = []
+ async for ev in _run_stream_attempt(ctx, state):
+ events.append(ev)
+
+ # (a) A visible Start/Delta/End trio carrying the notice text.
+ starts = [e for e in events if isinstance(e, StreamTextStart)]
+ deltas = [e for e in events if isinstance(e, StreamTextDelta)]
+ ends = [e for e in events if isinstance(e, StreamTextEnd)]
+ notice_deltas = [d for d in deltas if d.delta == STREAM_INCOMPLETE_MARKER]
+ assert notice_deltas, (
+ "post-stream branch must emit a StreamTextDelta carrying "
+ "STREAM_INCOMPLETE_MARKER so the user sees the notice"
+ )
+ notice_id = notice_deltas[0].id
+ assert any(s.id == notice_id for s in starts)
+ assert any(e.id == notice_id for e in ends)
+
+ # (b) Appended assistant ChatMessage carries the new notice — not
+ # the legacy stopped-by-user marker.
+ assistant_msgs = [m for m in ctx.session.messages if m.role == "assistant"]
+ assert assistant_msgs, "branch must append an assistant message"
+ contents = [m.content for m in assistant_msgs]
+ assert STREAM_INCOMPLETE_MARKER in contents
+ assert STOPPED_BY_USER_MARKER not in contents
diff --git a/autogpt_platform/backend/backend/copilot/sdk/session_persistence_test.py b/autogpt_platform/backend/backend/copilot/sdk/session_persistence_test.py
index d7cbc1d24e..e2bdea902d 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/session_persistence_test.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/session_persistence_test.py
@@ -19,7 +19,7 @@ from __future__ import annotations
from datetime import datetime, timezone
from unittest.mock import MagicMock
-from backend.copilot.constants import STOPPED_BY_USER_MARKER
+from backend.copilot.constants import STOPPED_BY_USER_MARKER, STREAM_INCOMPLETE_MARKER
from backend.copilot.model import ChatMessage, ChatSession
from backend.copilot.response_model import StreamStartStep, StreamTextDelta
from backend.copilot.sdk.service import _dispatch_response, _StreamAccumulator
@@ -271,6 +271,28 @@ class TestPruneOrphanToolCalls:
assert len(messages) == 1
assert messages[-1].role == "user"
+ def test_stop_strips_stream_incomplete_marker_and_orphan(self) -> None:
+ """When the SDK CLI ends without a ResultMessage (per-query budget
+ exhausted, max_turns hit, OOM, crash) the service appends a
+ ``STREAM_INCOMPLETE_MARKER`` notice; the next turn's prune must drop
+ both the orphan assistant tool_use and the trailing notice so the
+ ``--resume`` transcript stays clean."""
+ messages: list[ChatMessage] = [
+ ChatMessage(role="user", content="do something"),
+ ChatMessage(
+ role="assistant",
+ content="",
+ tool_calls=[self._tool_call("tc_abc")],
+ ),
+ ChatMessage(role="assistant", content=STREAM_INCOMPLETE_MARKER),
+ ]
+
+ removed = prune_orphan_tool_calls(messages)
+
+ assert removed == 2
+ assert len(messages) == 1
+ assert messages[-1].role == "user"
+
def test_completed_tool_call_is_preserved(self) -> None:
"""An assistant row whose tool_calls are all resolved is a healthy
trailing state and must not be popped."""
diff --git a/autogpt_platform/backend/backend/copilot/session_cleanup.py b/autogpt_platform/backend/backend/copilot/session_cleanup.py
index b23056ca68..dbc6ac6f3a 100644
--- a/autogpt_platform/backend/backend/copilot/session_cleanup.py
+++ b/autogpt_platform/backend/backend/copilot/session_cleanup.py
@@ -7,7 +7,7 @@ start every new turn from a well-formed message list.
import logging
-from backend.copilot.constants import STOPPED_BY_USER_MARKER
+from backend.copilot.constants import STOPPED_BY_USER_MARKER, STREAM_INCOMPLETE_MARKER
from backend.copilot.model import ChatMessage
logger = logging.getLogger(__name__)
@@ -26,8 +26,10 @@ def prune_orphan_tool_calls(
``tool_use`` with no paired ``tool_result`` and the SDK raises a
generic error.
- Also strips trailing ``STOPPED_BY_USER_MARKER`` assistant rows emitted
- by the same Stop path so the next turn's transcript starts clean.
+ Also strips trailing ``STOPPED_BY_USER_MARKER`` and
+ ``STREAM_INCOMPLETE_MARKER`` assistant rows so the next turn's
+ transcript starts clean — these synthetic notices must not leak into
+ the next ``--resume`` turn's history.
If *log_prefix* is given, emits an INFO log with the prefix whenever
something was actually popped so the turn-start cleanup is visible.
@@ -46,7 +48,10 @@ def prune_orphan_tool_calls(
resolved_ids.add(msg.tool_call_id)
continue
- if msg.role == "assistant" and msg.content == STOPPED_BY_USER_MARKER:
+ if msg.role == "assistant" and msg.content in (
+ STOPPED_BY_USER_MARKER,
+ STREAM_INCOMPLETE_MARKER,
+ ):
cut_index = i
continue
diff --git a/autogpt_platform/backend/backend/copilot/stream_registry.py b/autogpt_platform/backend/backend/copilot/stream_registry.py
index 99b263069b..97acbfb2b5 100644
--- a/autogpt_platform/backend/backend/copilot/stream_registry.py
+++ b/autogpt_platform/backend/backend/copilot/stream_registry.py
@@ -35,6 +35,7 @@ from backend.data.redis_client import get_redis_async
from backend.data.redis_helpers import hash_compare_and_set
from .config import ChatConfig
+from .constants import STREAM_LOCK_PREFIX
from .executor.utils import COPILOT_CONSUMER_TIMEOUT_SECONDS, get_session_lock_key
from .response_model import (
ResponseType,
@@ -874,6 +875,15 @@ async def mark_session_completed(
except RedisError as e:
logger.warning(f"Failed to release cluster lock for session {session_id}: {e}")
+ # Force-release the SDK-stream lock too. The SDK turn's finally block
+ # normally releases it, but on cancel/force-complete the next user turn
+ # can race ahead before that runs and hit stream_already_active. The
+ # delete is idempotent with the SDK's own release.
+ try:
+ await redis.delete(f"{STREAM_LOCK_PREFIX}{session_id}")
+ except RedisError as e:
+ logger.warning(f"Failed to release stream lock for session {session_id}: {e}")
+
if error_message and not skip_error_publish:
try:
await publish_chunk(turn_id, StreamError(errorText=error_message))
diff --git a/autogpt_platform/backend/backend/copilot/stream_registry_test.py b/autogpt_platform/backend/backend/copilot/stream_registry_test.py
index 702462b392..e45f96bfd7 100644
--- a/autogpt_platform/backend/backend/copilot/stream_registry_test.py
+++ b/autogpt_platform/backend/backend/copilot/stream_registry_test.py
@@ -7,6 +7,7 @@ import pytest
from redis.exceptions import RedisError
from backend.copilot import stream_registry
+from backend.copilot.constants import STREAM_LOCK_PREFIX
from backend.copilot.executor.utils import get_session_lock_key
@@ -283,6 +284,7 @@ async def test_mark_session_completed_releases_cluster_lock_on_success():
assert result is True
assert get_session_lock_key("sess-1") in fake_redis.deleted_keys
+ assert f"{STREAM_LOCK_PREFIX}sess-1" in fake_redis.deleted_keys
@pytest.mark.asyncio
@@ -306,6 +308,7 @@ async def test_mark_session_completed_skips_lock_release_when_already_completed(
assert result is False
assert get_session_lock_key("sess-1") not in fake_redis.deleted_keys
+ assert f"{STREAM_LOCK_PREFIX}sess-1" not in fake_redis.deleted_keys
assert not any(
isinstance(call.args[1], stream_registry.StreamFinish)
for call in publish_mock.call_args_list
@@ -345,6 +348,38 @@ async def test_mark_session_completed_survives_lock_release_redis_error():
), "StreamFinish must still be published even if lock DELETE raises"
+async def test_mark_session_completed_releases_stream_lock():
+ """Force-completing a session (cancel / error) must DELETE both the
+ cluster lock and the SDK stream lock. If the stream lock isn't released
+ here, the next user turn races ahead of the SDK turn's finally block and
+ fails with stream_already_active until the 120s TTL expires."""
+ fake_redis = _FakeRedis({"status": "running", "turn_id": "turn-1"})
+
+ with (
+ patch.object(
+ stream_registry, "get_redis_async", new=AsyncMock(return_value=fake_redis)
+ ),
+ patch.object(
+ stream_registry, "hash_compare_and_set", new=AsyncMock(return_value=True)
+ ),
+ patch.object(stream_registry, "publish_chunk", new=AsyncMock()),
+ patch.object(
+ stream_registry.chat_db(),
+ "set_turn_duration",
+ new=AsyncMock(),
+ create=True,
+ ),
+ ):
+ result = await stream_registry.mark_session_completed(
+ "sess-1", error_message="cancelled"
+ )
+
+ assert result is True
+ assert get_session_lock_key("sess-1") in fake_redis.deleted_keys
+ assert f"{STREAM_LOCK_PREFIX}sess-1" in fake_redis.deleted_keys
+
+
# ---------------------------------------------------------------------------
# Replays must contain protocol chunks only. Redis cursor data parts are not
# emitted because AI SDK resume needs the complete stream envelope from 0-0.
diff --git a/autogpt_platform/backend/backend/copilot/tools/run_block.py b/autogpt_platform/backend/backend/copilot/tools/run_block.py
index 63f860852d..715bdac2b2 100644
--- a/autogpt_platform/backend/backend/copilot/tools/run_block.py
+++ b/autogpt_platform/backend/backend/copilot/tools/run_block.py
@@ -200,6 +200,13 @@ class RunBlockTool(BaseTool):
missing = sorted(
prep.required_non_credential_keys - prep.provided_input_keys
)
+ # Hide credential fields from the schema sent to the LLM — the
+ # backend resolves them automatically from the user's connected
+ # integrations, and exposing the picker shape (id/provider/type)
+ # tempts the LLM to fabricate values it cannot construct.
+ llm_input_schema = _strip_credentials_from_schema(
+ prep.input_schema, prep.credentials_fields
+ )
if validate_only and not missing:
detail_msg = (
f"Block '{prep.block.name}' — all required inputs "
@@ -213,7 +220,9 @@ class RunBlockTool(BaseTool):
else:
detail_msg = (
f"Block '{prep.block.name}' details. Provide input_data "
- f"matching the inputs schema to execute the block."
+ f"matching the inputs schema to execute the block. "
+ f"Credentials are auto-resolved by the backend — do not "
+ f"include them in input_data."
)
return BlockDetailsResponse(
message=detail_msg,
@@ -222,7 +231,7 @@ class RunBlockTool(BaseTool):
id=block_id,
name=prep.block.name,
description=prep.block.description or "",
- inputs=prep.input_schema,
+ inputs=llm_input_schema,
outputs=output_schema,
credentials=credentials_meta,
),
@@ -244,3 +253,28 @@ class RunBlockTool(BaseTool):
matched_credentials=prep.matched_credentials,
dry_run=dry_run,
)
+
+
+def _strip_credentials_from_schema(
+ input_schema: dict[str, Any], credentials_fields: set[str]
+) -> dict[str, Any]:
+ """Return a copy of *input_schema* without credential properties.
+
+ Credential fields are auto-resolved from the user's connected integrations;
+ leaking the picker shape (``{provider, id, type, title}``) into the
+ LLM-facing schema makes the model think it has to construct one and bail
+ out when it can't (see the Replicate "Seed Dance 2.0" copilot session).
+ """
+ if not credentials_fields:
+ return input_schema
+ cleaned = dict(input_schema)
+ properties = dict(cleaned.get("properties", {}))
+ for field in credentials_fields:
+ properties.pop(field, None)
+ cleaned["properties"] = properties
+ required = [r for r in cleaned.get("required", []) if r not in credentials_fields]
+ if required:
+ cleaned["required"] = required
+ elif "required" in cleaned:
+ del cleaned["required"]
+ return cleaned
diff --git a/autogpt_platform/backend/backend/copilot/tools/run_block_test.py b/autogpt_platform/backend/backend/copilot/tools/run_block_test.py
index c902db6b55..9fc7a27961 100644
--- a/autogpt_platform/backend/backend/copilot/tools/run_block_test.py
+++ b/autogpt_platform/backend/backend/copilot/tools/run_block_test.py
@@ -1058,3 +1058,102 @@ class TestExecuteBlockTimeout:
f"spend_credits must be called exactly once, got {len(spend_calls)} "
"(double-charge — sentry r3105216985)"
)
+
+
+class TestRunBlockCredentialsHidden:
+ """The schema returned to the LLM must hide credential fields.
+
+ Credential fields are auto-resolved from the user's connected integrations;
+ leaking the picker shape (``{provider, id, type, title}``) into the
+ LLM-facing schema makes the model think it has to construct one and bail
+ out (Replicate "Seed Dance 2.0" copilot session, May 2026 release).
+ """
+
+ @pytest.mark.asyncio(loop_scope="session")
+ async def test_credentials_field_stripped_from_block_details(self):
+ session = make_session(user_id=_TEST_USER_ID)
+
+ mock_block = make_mock_block_with_schema(
+ block_id="replicate-block-id",
+ name="Replicate Model",
+ input_properties={
+ "credentials": {
+ "type": "object",
+ "credentials_provider": ["replicate"],
+ "credentials_types": ["api_key"],
+ },
+ "model_name": {"type": "string"},
+ "model_inputs": {"type": "object"},
+ },
+ required_fields=["credentials", "model_name"],
+ )
+ mock_block.input_schema.get_credentials_fields.return_value = {
+ "credentials": MagicMock()
+ }
+
+ with (
+ patch(
+ "backend.copilot.tools.helpers.get_block",
+ return_value=mock_block,
+ ),
+ patch(
+ "backend.copilot.tools.helpers.match_credentials_to_requirements",
+ return_value=({}, []),
+ ),
+ ):
+ tool = RunBlockTool()
+ response = await tool._execute(
+ user_id=_TEST_USER_ID,
+ session=session,
+ block_id="replicate-block-id",
+ input_data={},
+ dry_run=False,
+ validate_only=True,
+ )
+
+ assert isinstance(response, BlockDetailsResponse)
+ inputs = response.block.inputs
+ assert "credentials" not in inputs.get("properties", {}), (
+ "credentials picker shape leaked into LLM-facing schema — the LLM "
+ "will try to construct it and fail"
+ )
+ assert "credentials" not in inputs.get(
+ "required", []
+ ), "credentials must not be listed as required — backend resolves it"
+ assert "model_name" in inputs["properties"]
+ assert "model_name" in inputs["required"]
+
+ def test_strip_credentials_helper(self):
+ """Direct unit test for the schema-stripping helper."""
+ from backend.copilot.tools.run_block import _strip_credentials_from_schema
+
+ schema = {
+ "properties": {
+ "credentials": {"type": "object"},
+ "prompt": {"type": "string"},
+ },
+ "required": ["credentials", "prompt"],
+ }
+ cleaned = _strip_credentials_from_schema(schema, {"credentials"})
+ assert "credentials" not in cleaned["properties"]
+ assert cleaned["required"] == ["prompt"]
+ # Original must not be mutated.
+ assert "credentials" in schema["properties"]
+ assert schema["required"] == ["credentials", "prompt"]
+
+ def test_strip_credentials_helper_no_creds(self):
+ from backend.copilot.tools.run_block import _strip_credentials_from_schema
+
+ schema = {"properties": {"prompt": {"type": "string"}}, "required": ["prompt"]}
+ # Empty credentials_fields → return unchanged.
+ assert _strip_credentials_from_schema(schema, set()) is schema
+
+ def test_strip_credentials_helper_drops_empty_required(self):
+ from backend.copilot.tools.run_block import _strip_credentials_from_schema
+
+ schema = {
+ "properties": {"credentials": {"type": "object"}},
+ "required": ["credentials"],
+ }
+ cleaned = _strip_credentials_from_schema(schema, {"credentials"})
+ assert "required" not in cleaned
diff --git a/autogpt_platform/backend/backend/executor/utils.py b/autogpt_platform/backend/backend/executor/utils.py
index fb28bb4cfe..ea3821e308 100644
--- a/autogpt_platform/backend/backend/executor/utils.py
+++ b/autogpt_platform/backend/backend/executor/utils.py
@@ -21,6 +21,7 @@ from backend.data import workspace as workspace_db
# Import dynamic field utilities from centralized location
from backend.data.block import BlockInput, BlockOutputEntry
from backend.data.block_cost_config import BLOCK_COSTS, compute_token_credits
+from backend.data.credit import UsageTransactionMetadata, get_user_credit_model
from backend.data.db import prisma
from backend.data.dynamic_fields import merge_execution_input
from backend.data.execution import (
@@ -192,6 +193,44 @@ def block_usage_cost(
return 0, {}
+async def charge_for_direct_block_execution(
+ user_id: str,
+ block: Block,
+ input_data: BlockInput,
+ *,
+ source: Literal["internal", "external"],
+) -> None:
+ """Pre-flight charge for a direct block-execute API call.
+
+ Shared by both ``POST /api/blocks/{id}/execute`` (internal UI) and
+ ``POST /api/v1/blocks/{id}/execute`` (external API key) so the two
+ routes stay in lock-step on cost calculation, transaction metadata,
+ and 402 mapping. ``source`` is recorded in the credit-history
+ ``reason`` so transactions remain attributable to the originating
+ surface.
+
+ Dynamic-cost blocks (TOKENS / COST_USD / SECOND / ITEMS) return 0
+ from ``block_usage_cost`` pre-flight and are NOT charged on this
+ code path — the post-flight reconciliation only runs inside
+ ``executor/manager.py``, which the direct block-execute API
+ endpoints bypass entirely.
+ """
+ cost, cost_filter = block_usage_cost(block, input_data)
+ if cost <= 0:
+ return
+ credit_model = await get_user_credit_model(user_id)
+ await credit_model.spend_credits(
+ user_id=user_id,
+ cost=cost,
+ metadata=UsageTransactionMetadata(
+ block_id=block.id,
+ block=block.name,
+ input=cost_filter,
+ reason=f"Direct {source} block execution of {block.name}",
+ ),
+ )
+
+
def _coerce_seconds(run_time: float, stats: NodeExecutionStats | None) -> float:
if run_time > 0:
return run_time
diff --git a/docs/integrations/block-integrations/misc.md b/docs/integrations/block-integrations/misc.md
index 72ede9c537..64035959dc 100644
--- a/docs/integrations/block-integrations/misc.md
+++ b/docs/integrations/block-integrations/misc.md
@@ -58,7 +58,7 @@ Tool and block identifiers provided in `tools` and `blocks` are validated at run
| system_context | Optional additional context prepended to the prompt. Use this to constrain autopilot behavior, provide domain context, or set output format requirements. | str | No |
| session_id | Session ID to continue an existing autopilot conversation. Leave empty to start a new session. Use the session_id output from a previous run to continue. | str | No |
| max_recursion_depth | Maximum nesting depth when the autopilot calls this block recursively (sub-agent pattern). Prevents infinite loops. | int | No |
-| tools | Tool names to filter. Works with tools_exclude to form an allow-list or deny-list. Leave empty to apply no tool filter. | List["add_understanding" \| "bash_exec" \| "browser_act" \| "browser_navigate" \| "browser_screenshot" \| "connect_integration" \| "continue_run_block" \| "create_agent" \| "create_feature_request" \| "create_folder" \| "customize_agent" \| "delete_folder" \| "delete_workspace_file" \| "edit_agent" \| "find_agent" \| "find_block" \| "find_library_agent" \| "fix_agent_graph" \| "get_agent_building_guide" \| "get_doc_page" \| "get_mcp_guide" \| "get_sub_session_result" \| "list_folders" \| "list_workspace_files" \| "memory_forget_confirm" \| "memory_forget_search" \| "memory_search" \| "memory_store" \| "move_agents_to_folder" \| "move_folder" \| "read_workspace_file" \| "run_agent" \| "run_block" \| "run_mcp_tool" \| "run_sub_session" \| "search_docs" \| "search_feature_requests" \| "update_folder" \| "validate_agent_graph" \| "view_agent_output" \| "web_fetch" \| "web_search" \| "write_workspace_file" \| "Agent" \| "Edit" \| "Glob" \| "Grep" \| "Read" \| "Task" \| "TodoWrite" \| "WebSearch" \| "Write"] | No |
+| tools | Tool names to filter. Works with tools_exclude to form an allow-list or deny-list. Leave empty to apply no tool filter. | List["add_understanding" \| "bash_exec" \| "browser_act" \| "browser_navigate" \| "browser_screenshot" \| "connect_integration" \| "continue_run_block" \| "create_agent" \| "create_feature_request" \| "create_folder" \| "customize_agent" \| "delete_folder" \| "delete_schedule" \| "delete_workspace_file" \| "edit_agent" \| "find_agent" \| "find_block" \| "find_library_agent" \| "fix_agent_graph" \| "get_agent_building_guide" \| "get_doc_page" \| "get_mcp_guide" \| "get_platform_info" \| "get_sub_session_result" \| "list_agent_triggers" \| "list_folders" \| "list_schedules" \| "list_workspace_files" \| "memory_forget_confirm" \| "memory_forget_search" \| "memory_search" \| "memory_store" \| "move_agents_to_folder" \| "move_folder" \| "read_workspace_file" \| "run_agent" \| "run_block" \| "run_mcp_tool" \| "run_sub_session" \| "search_docs" \| "search_feature_requests" \| "update_folder" \| "validate_agent_graph" \| "view_agent_output" \| "web_fetch" \| "web_search" \| "write_workspace_file" \| "Agent" \| "Edit" \| "Glob" \| "Grep" \| "Read" \| "Task" \| "TodoWrite" \| "WebSearch" \| "Write"] | No |
| tools_exclude | Controls how the 'tools' list is interpreted. True (default): 'tools' is a deny-list — listed tools are blocked, all others are allowed. An empty 'tools' list means allow everything. False: 'tools' is an allow-list — only listed tools are permitted. | bool | No |
| blocks | Block identifiers to filter when the copilot uses run_block. Each entry can be: a block name (e.g. 'HTTP Request'), a full block UUID, or the first 8 hex characters of the UUID (e.g. 'c069dc6b'). Works with blocks_exclude. Leave empty to apply no block filter. | List[str] | No |
| blocks_exclude | Controls how the 'blocks' list is interpreted. True (default): 'blocks' is a deny-list — listed blocks are blocked, all others are allowed. An empty 'blocks' list means allow everything. False: 'blocks' is an allow-list — only listed blocks are permitted. | bool | No |
diff --git a/docs/integrations/block-integrations/replicate/replicate_block.md b/docs/integrations/block-integrations/replicate/replicate_block.md
index 16505741f2..be4ea759b8 100644
--- a/docs/integrations/block-integrations/replicate/replicate_block.md
+++ b/docs/integrations/block-integrations/replicate/replicate_block.md
@@ -20,7 +20,7 @@ The block waits for completion and returns the model output along with status in
| Input | Description | Type | Required |
|-------|-------------|------|----------|
| model_name | The Replicate model name (format: 'owner/model-name') | str | Yes |
-| model_inputs | Dictionary of inputs to pass to the model | Dict[str, str \| int] | No |
+| model_inputs | Dictionary of inputs to pass to the model. Values may be strings, integers, floats, or booleans — Replicate model schemas commonly require booleans (e.g. ``generate_audio``, ``safety_checker``) and floats (e.g. ``temperature``, ``guidance_scale``). | Dict[str, str \| int \| float \| bool] | No |
| version | Specific version hash of the model (optional) | str | No |
### Outputs