googleapis / googleapis/python-aiplatform
Agent Engine Sandbox creation fails with 404 NOT_FOUND (likely timing issue in sandboxes.create implementation)
- Langage dominant
- Python
- Étoiles
- 905
- Forks
- 465
- Merge moyen
- 1 j 13 h
- PR mergées (30 j)
- 44
Description
**Describe the bug**
When following the [Vertex AI Code Execution quickstart guide](https://cloud.google.com/vertex-ai/generative-ai/docs/agent-engine/code-execution/quickstart), sandbox creation fails with a 404 `NOT_FOUND` error. It seems the SDK attempts to access the sandbox before it has finished provisioning.
**To Reproduce**
```python
import pprint
import vertexai
from vertexai import types
client = vertexai.Client(project="[project-name]", location="us-central1")
agent_engine = client.agent_engines.create()
agent_engine_name = agent_engine.api_resource.name
operation = client.agent_engines.sandboxes.create(
spec={"code_execution_environment": {}},
name=agent_engine_name,
config=types.CreateAgentEngineSandboxConfig(display_name="test")
)
sandbox_name = operation.response.name
```
**Observed behavior**
```
% uv run temp_vertex_ai_code.py
/path/to/project/src/temp_vertex_ai_code.py:12: ExperimentalWarning: The Vertex SDK GenAI agent_engines.sandboxes module is experimental, and may change in future versions.
operation = client.agent_engines.sandboxes.create(
Traceback (most recent call last):
File "/path/to/project/src/temp_vertex_ai_code.py", line 12, in
operation = client.agent_engines.sandboxes.create(
File "/path/to/project/.venv/lib/python3.10/site-packages/vertexai/_genai/sandboxes.py", line 572, in create
operation.response = self.get(name=operation.response.name)
File "/path/to/project/.venv/lib/python3.10/site-packages/vertexai/_genai/sandboxes.py", line 653, in get
return self._get(name=name, config=config)
File "/path/to/project/.venv/lib/python3.10/site-packages/vertexai/_genai/sandboxes.py", line 404, in _get
response = self._api_client.request("get", path, request_dict, http_options)
File "/path/to/project/.venv/lib/python3.10/site-packages/google/genai/_api_client.py", line 1292, in request
response = self._request(http_request, http_options, stream=False)
File "/path/to/project/.venv/lib/python3.10/site-packages/google/genai/_api_client.py", line 1128, in _request
return self._retry(self._request_once, http_request, stream)
File "/path/to/project/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
File "/path/to/project/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
File "/path/to/project/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 418, in exc_check
raise retry_exc.reraise()
File "/path/to/project/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 185, in reraise
raise self.last_attempt.result()
File "/path/to/python/lib/python3.10/concurrent/futures/_base.py", line 451, in result
return self.__get_result()
File "/path/to/python/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/path/to/project/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
File "/path/to/project/.venv/lib/python3.10/site-packages/google/genai/_api_client.py", line 1105, in _request_once
errors.APIError.raise_for_response(response)
File "/path/to/project/.venv/lib/python3.10/site-packages/google/genai/errors.py", line 108, in raise_for_response
raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 404 NOT_FOUND. {'error': {'code': 404, 'message': 'Sandbox Environment (projectNumber: 1234567890, reasoningEngineId: 1111111111111111111, sandboxEnvironmentId: 2222222222222222222) is not found.', 'status': 'NOT_FOUND'}}
```
**Additional context**
Adding a `time.sleep(10)` delay before accessing the sandbox (around [line 572 of `sandboxes.py`](https://github.com/googleapis/python-aiplatform/blob/b91b63c6f66e6350e753bc8b21d65e9f31d3b8f8/vertexai/_genai/sandboxes.py#L572)) resolves the issue consistently, which supports the hypothesis of a race condition.
**Environment**
* Python 3.10.12
* `google-cloud-aiplatform` 1.120.0
* OS: macOS
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.