Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(dify-agent): treat a confirmed-missing Home Snapshot as a success on Enterprise delete (#44085)
D4191051b66669c2e2
diff --git a/dify-agent/src/dify_agent/runtime_backend/enterprise.py b/dify-agent/src/dify_agent/runtime_backend/enterprise.pyindex 6d038c4fe16..c503bb9302c 100644--- a/dify-agent/src/dify_agent/runtime_backend/enterprise.py+++ b/dify-agent/src/dify_agent/runtime_backend/enterprise.py@@ -140,7 +140,14 @@ class EnterpriseHomeSnapshotBackend:return snapshot_refasync def delete(self, snapshot_ref: str) -> None:- """Delete one snapshot's artifacts."""+ """Delete one snapshot's artifacts, treating a confirmed-missing snapshot as success.++ ``HomeSnapshotBackend.delete`` must be safe to retry and must treat an+ already absent snapshot as a successful outcome. The Gateway reports a+ snapshot it no longer holds with a ``snapshot_not_found`` style reason, so+ map that back to a no-op. An unrelated 4xx such as ``route_not_found`` is a+ gateway fault rather than proof of absence, so it still raises.+ """try:_ = await _gateway_request(endpoint=self.gateway_endpoint,@@ -149,7 +156,11 @@ class EnterpriseHomeSnapshotBackend:method="DELETE",path=f"/v1/home-snapshots/{quote(snapshot_ref, safe='/')}",)- except (_GatewayStatusError, httpx.TimeoutException, httpx.RequestError) as exc:+ except _GatewayStatusError as exc:+ if _is_missing_snapshot(exc):+ return+ raise BindingDestroyError(str(exc)) from exc+ except (httpx.TimeoutException, httpx.RequestError) as exc:raise BindingDestroyError(str(exc)) from exc@@ -357,6 +368,13 @@ def _is_missing_sandbox(exc: ShellProviderError) -> bool:}+def _is_missing_snapshot(exc: _GatewayStatusError) -> bool:+ return exc.status_code == HTTPStatus.NOT_FOUND and exc.reason.casefold() in {+ "not_found",+ "snapshot_not_found",+ }++async def _close_best_effort(data_plane: ShellctlRuntimeLease | None, *, binding_ref: str) -> None:if data_plane is None:returndiff --git a/dify-agent/tests/local/dify_agent/runtime_backend/test_enterprise_backend.py b/dify-agent/tests/local/dify_agent/runtime_backend/test_enterprise_backend.pyindex 41588488044..62f946fc1bc 100644--- a/dify-agent/tests/local/dify_agent/runtime_backend/test_enterprise_backend.py+++ b/dify-agent/tests/local/dify_agent/runtime_backend/test_enterprise_backend.py@@ -694,3 +694,23 @@ async def test_enterprise_snapshot_delete_propagates_gateway_failures(with pytest.raises(BindingDestroyError, match=reason):await snapshots.delete("tenant-1/agent-1/home-2")++[email protected]("reason", ["snapshot_not_found", "not_found"])+async def test_enterprise_snapshot_delete_treats_absent_snapshot_as_success(+ monkeypatch: pytest.MonkeyPatch,+ reason: str,+) -> None:+ requests: list[httpx.Request] = []++ def handler(request: httpx.Request) -> httpx.Response:+ requests.append(request)+ return httpx.Response(404, json={"code": 404, "reason": reason, "message": "home snapshot missing"})++ _ = _mock_http(monkeypatch, handler)+ snapshots = EnterpriseHomeSnapshotBackend(gateway_endpoint="http://gateway.example", auth_token="secret")++ await snapshots.delete("tenant-1/agent-1/home-2")++ assert [request.method for request in requests] == ["DELETE"]