fix(agent): align Binding file upload timeouts (#41027)

This commit is contained in:
Ingram Z authored and GitHub committed 2026-08-20 18:59:44 +00:00
1 parent 785ca4b915
commit 0ca99312c1
20 files changed
+154 -21

No files matched your search

@@ -31,6 +31,7 @@ def test_create_agent_backend_client_forwards_authentication(
client_cls.assert_called_once_with(
base_url="http://agent-backend",
stream_timeout=30,
binding_file_download_timeout=240,
headers=headers,
)
@@ -51,23 +52,33 @@ def test_create_agent_backend_run_client_forwards_stream_read_timeout(create_cli
@pytest.mark.parametrize(
("factory", "module"),
("factory", "module", "extra_kwargs"),
[
(home_snapshot_service.AgentHomeSnapshotService._client, home_snapshot_service),
(workspace_service.AgentWorkspaceService._client, workspace_service),
(agent_app_sandbox_service._default_client_factory, agent_app_sandbox_service),
(home_snapshot_service.AgentHomeSnapshotService._client, home_snapshot_service, {}),
(workspace_service.AgentWorkspaceService._client, workspace_service, {}),
(
agent_app_sandbox_service._default_client_factory,
agent_app_sandbox_service,
{"binding_file_download_timeout": 123.5},
),
],
)
def test_default_agent_backend_clients_forward_authentication(
monkeypatch: pytest.MonkeyPatch,
factory: Callable[[], Client],
module: ModuleType,
extra_kwargs: dict[str, float],
) -> None:
monkeypatch.setattr(dify_config, "AGENT_BACKEND_BASE_URL", "http://agent-backend")
monkeypatch.setattr(dify_config, "AGENT_BACKEND_API_TOKEN", "secret-token")
monkeypatch.setattr(dify_config, "AGENT_BACKEND_BINDING_FILE_DOWNLOAD_TIMEOUT_SECONDS", 123.5)
create_client = MagicMock()
monkeypatch.setattr(module, "create_agent_backend_client", create_client)
factory()
create_client.assert_called_once_with(base_url="http://agent-backend", api_token="secret-token")
create_client.assert_called_once_with(
base_url="http://agent-backend",
api_token="secret-token",
**extra_kwargs,
)
@@ -0,0 +1,41 @@
from __future__ import annotations
from pathlib import Path
import pytest
from pydantic import ValidationError
from configs.extra.agent_backend_config import AgentBackendConfig
_REPOSITORY_ROOT = Path(__file__).resolve().parents[4]
_API_TIMEOUT_ENV = "AGENT_BACKEND_BINDING_FILE_DOWNLOAD_TIMEOUT_SECONDS"
_AGENT_TIMEOUT_ENV = "DIFY_AGENT_BINDING_FILE_DOWNLOAD_COMMAND_TIMEOUT_SECONDS"
def test_binding_file_download_timeout_defaults_to_240_seconds(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv(_API_TIMEOUT_ENV, raising=False)
assert AgentBackendConfig().AGENT_BACKEND_BINDING_FILE_DOWNLOAD_TIMEOUT_SECONDS == 240.0
def test_binding_file_download_timeout_rejects_non_positive_values() -> None:
with pytest.raises(ValidationError):
AgentBackendConfig(AGENT_BACKEND_BINDING_FILE_DOWNLOAD_TIMEOUT_SECONDS=0)
def test_binding_file_timeout_docker_settings_use_their_service_env_files() -> None:
root_env_example = (_REPOSITORY_ROOT / "docker/.env.example").read_text(encoding="utf-8")
api_env_example = (_REPOSITORY_ROOT / "docker/envs/core-services/api.env.example").read_text(encoding="utf-8")
agent_env_example = (_REPOSITORY_ROOT / "docker/envs/core-services/dify-agent.env.example").read_text(
encoding="utf-8"
)
compose_template = (_REPOSITORY_ROOT / "docker/docker-compose-template.yaml").read_text(encoding="utf-8")
assert f"{_API_TIMEOUT_ENV}=" not in root_env_example
assert f"{_AGENT_TIMEOUT_ENV}=" not in root_env_example
assert f"{_API_TIMEOUT_ENV}=" in api_env_example
assert f"{_AGENT_TIMEOUT_ENV}=" not in api_env_example
assert f"{_API_TIMEOUT_ENV}=" not in agent_env_example
assert f"{_AGENT_TIMEOUT_ENV}=" in agent_env_example
assert f"{_API_TIMEOUT_ENV}:" not in compose_template
assert f"{_AGENT_TIMEOUT_ENV}:" not in compose_template