fix(dify-agent): adjust local sandbox home paths (#41021)

This commit is contained in:
盐粒 Yanli
2026-08-20 10:00:01 +00:00
committed by GitHub
parent 43b6d8e32e
commit b034368b3b
3 changed files with 5 additions and 86 deletions

View File

@@ -45,7 +45,7 @@ logger = logging.getLogger(__name__)
class LocalHomeSnapshotBackend:
endpoint: str
auth_token: str
snapshot_root: str = "/home/dify/.dify-agent-home-snapshots"
snapshot_root: str = "/home/dify/.snapshots"
client_factory: ShellctlClientFactory | None = None
async def create_from_runtime(self, *, spec: HomeSnapshotCreateSpec, source: RuntimeLease) -> str:
@@ -111,9 +111,9 @@ class LocalHomeSnapshotBackend:
class LocalExecutionBindingBackend:
endpoint: str
auth_token: str
materialized_home_root: str = "/home/dify/.dify-agent-materialized-homes"
materialized_home_root: str = "/home/dify"
workspace_root: str = "/home/dify/.dify-agent-workspaces"
snapshot_root: str = "/home/dify/.dify-agent-home-snapshots"
snapshot_root: str = "/home/dify/.snapshots"
client_factory: ShellctlClientFactory | None = None
async def create_binding(self, spec: ExecutionBindingCreateSpec) -> ExecutionBindingAllocation:

View File

@@ -20,9 +20,9 @@ from dify_agent.runtime_backend.local import LocalExecutionBindingBackend, Local
from dify_agent.runtime_backend.protocols import RuntimeBackendProfile
DEFAULT_E2B_TEMPLATE = "difys-default-team/dify-agent-local-sandbox"
DEFAULT_LOCAL_MATERIALIZED_HOME_ROOT = "/home/dify/.dify-agent-materialized-homes"
DEFAULT_LOCAL_MATERIALIZED_HOME_ROOT = "/home/dify"
DEFAULT_LOCAL_WORKSPACE_ROOT = "/home/dify/.dify-agent-workspaces"
DEFAULT_LOCAL_HOME_SNAPSHOT_ROOT = "/home/dify/.dify-agent-home-snapshots"
DEFAULT_LOCAL_HOME_SNAPSHOT_ROOT = "/home/dify/.snapshots"
class RuntimeBackendSettings(BaseSettings):

View File

@@ -320,87 +320,6 @@ async def test_local_snapshot_delete_removes_snapshot_directory() -> None:
assert ("rm", "-rf", "--", "/snapshots/home-home-2") in factory.commands
@pytest.mark.anyio
async def test_local_backend_materializes_same_agent_twice_in_one_workspace() -> None:
factory = _Factory()
backend = LocalExecutionBindingBackend(
endpoint="http://shellctl",
auth_token="",
client_factory=factory, # pyright: ignore[reportArgumentType]
)
first = await backend.create_binding(
ExecutionBindingCreateSpec(
tenant_id="tenant-1",
agent_id="agent-1",
binding_id="binding-1",
workspace_id="workspace-1",
existing_workspace_ref=None,
home_snapshot_ref="home-home-1",
)
)
second = await backend.create_binding(
ExecutionBindingCreateSpec(
tenant_id="tenant-1",
agent_id="agent-1",
binding_id="binding-2",
workspace_id="workspace-1",
existing_workspace_ref=first.workspace_ref,
home_snapshot_ref="home-home-1",
)
)
assert first.binding_ref == "binding-1:workspace-1"
assert second.binding_ref == "binding-2:workspace-1"
assert first.workspace_ref == second.workspace_ref == "workspace-1"
first_lease = await backend.acquire(first.binding_ref)
second_lease = await backend.acquire(second.binding_ref)
assert first_lease.layout.home_dir != second_lease.layout.home_dir
assert first_lease.layout.workspace_dir == second_lease.layout.workspace_dir
await backend.release(first_lease)
await backend.release(second_lease)
await backend.destroy_binding(
ExecutionBindingDestroySpec(
binding_ref=first.binding_ref,
destroy_workspace=False,
)
)
surviving_lease = await backend.acquire(second.binding_ref)
assert surviving_lease.layout.home_dir == "/home/dify/.dify-agent-materialized-homes/binding-2"
assert surviving_lease.layout.workspace_dir == "/home/dify/.dify-agent-workspaces/workspace-1"
await backend.release(surviving_lease)
workspace_dir = "/home/dify/.dify-agent-workspaces/workspace-1"
assert ("test", "-d", workspace_dir) in factory.commands
assert factory.commands.count(("mkdir", "-p", workspace_dir)) == 1
assert (
"rm",
"-rf",
"--",
"/home/dify/.dify-agent-materialized-homes/binding-1",
) in factory.commands
assert (
"rm",
"-rf",
"--",
"/home/dify/.dify-agent-materialized-homes/binding-1",
workspace_dir,
) not in factory.commands
assert (
"cp",
"-a",
"/home/dify/.dify-agent-home-snapshots/home-home-1/.",
"/home/dify/.dify-agent-materialized-homes/binding-1/",
) in factory.commands
assert (
"cp",
"-a",
"/home/dify/.dify-agent-home-snapshots/home-home-1/.",
"/home/dify/.dify-agent-materialized-homes/binding-2/",
) in factory.commands
@pytest.mark.anyio
async def test_local_snapshot_delete_preserves_shellctl_error_when_close_fails() -> None:
factory = _FailingFactory()