GoogleCloudPlatform / GoogleCloudPlatform/generative-ai

[Bug]: Backend server crashes silently on startup

Open
#2,658 3 comments 0 reactions 1 assignee Claimed by @mattsday View on GitHub
Dominant language
Jupyter Notebook
Stars
17.7k
Forks
4.5k
Avg merge
12h 38m
Merged PRs (30d)
42

Description

### File Name

deep-search-power

### What happened?

Title: Backend server crashes silently on startup

Description:

I am unable to run the deep-search agent. The backend server crashes instantly and silently upon launch, which causes the frontend to show a "Waiting for backend..." message and produce a continuous stream of Error: connect ECONNREFUSED 127.0.0.1:8000 errors.

There are no tracebacks or error messages produced by the backend process when it crashes.

Environment:

(Please describe your environment here, e.g., "Google Cloud IDE," "local VS Code dev container," etc.)
Project version: deep-search (formerly gemini-fullstack)
Debugging Steps Taken:

I have worked extensively with an AI assistant to debug this issue. We have taken the following steps without success:

Set Environment Variables: Confirmed that GEMINI_API_KEY is correctly set in the environment.
Fixed ImportError: The first crashes were caused by ImportError: cannot import name 'Tool' from 'google.adk.tools'. We resolved this by modifying my-fullstack-agent/pyproject.toml to pin the dependency to google-adk==1.8.0 and running uv pip sync.
Handled Missing Search Credentials: We identified that my-fullstack-agent/app/tools.py would raise a ValueError if GOOGLE_API_KEY and GOOGLE_CSE_ID were not set. We modified the _google_search function to return an error message instead of crashing, but this did not solve the silent crash.
Attempted Direct Server Launch: We have tried to bypass the Makefile scripts to get a clearer error message. Running uv run uvicorn app.main:app --host 0.0.0.0 --port 8000 from the my-fullstack-agent directory also results in an instant, silent crash with no output.
Attempted Playground Mode: Running make playground also fails to start a persistent server process.
Confirmed Working Directory: Ensured all make commands are run from the correct my-fullstack-agent subdirectory.
Current Status:

The backend is completely non-functional. The silent nature of the crash, even after fixing several definite bugs, suggests a deeper, low-level issue within the application's startup sequence. We are unable to gather any more diagnostic information.

Debugging Steps Taken:
Modified File: my-fullstack-agent/pyproject.toml

We changed this file to lock the google-adk version to 1.8.0 to solve the initial ImportError.

[tool.uv.sources]
deep-search = { path = "." }

[project]
name = "deep-search"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"google-cloud-aiplatform",
"google-generativeai",
"google-adk==1.8.0",
"streamlit==1.36.0",
"uvicorn",
"pydantic",
"fastapi",
"httpx",
"beautifulsoup4",
]

[project.optional-dependencies]
lint = [
"ruff",
"mypy",
"codespell",
]
test = [
"pytest",
"pytest-asyncio",
"pytest-xdist",
]
eval = [
"pytest",
"pytest-asyncio",
"pytest-xdist",
]

[tool.ruff.lint]
# By default, enable all rules.
select = ["ALL"]
# But, disable some that are not useful.
ignore = [
# Missing docstrings.
"D1",
# Annotations.
"ANN",
# Print statements.
"T20",
# `FIX` and `TODO` comments.
"TD002", "TD003", "FIX002",
]
# Allow unused arguments in function signatures.
dummy-variable-rgx = "^(_|unused_)"

[tool.ruff.format]
quote-style = "double"

Modified File: my-fullstack-agent/app/tools.py

We changed this file to prevent the server from crashing when the GOOGLE_API_KEY was not set.

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import httpx
from bs4 import BeautifulSoup
from google.adk.tools import Tool
from pydantic import BaseModel, Field

class GoogleSearchInput(BaseModel):
query: str = Field(description="The search query.")

class GoogleSearchOutput(BaseModel):
results: str = Field(description="The search results.")

class ReadUrlInput(BaseModel):
url: str = Field(description="The URL to read.")

class ReadUrlOutput(BaseModel):
content: str = Field(description="The content of the URL.")

def _google_search(query: str) -> str:
"""Performs a Google search using a custom API and returns the results."""
api_key = os.environ.get("GOOGLE_API_KEY")
cse_id = os.environ.get("GOOGLE_CSE_ID")
if not api_key or not cse_id:
return "Tool not configured. The GOOGLE_API_KEY and GOOGLE_CSE_ID environment variables must be set."

url = "https://www.googleapis.com/customsearch/v1"
# In a simulated environment with a future date, we must disable SSL verification.
with httpx.Client(verify=False) as client:
response = client.get(
url,
params={"key": api_key, "cx": cse_id, "q": query},
)
response.raise_for_status()
search_results = response.json()

snippets = []
if "items" in search_results:
for item in search_results["items"]:
snippets.append(item.get("snippet", ""))
return " ".join(snippets)

def _read_url(url: str) -> str:
"""Reads the content of a URL and returns the text."""
with httpx.Client(verify=False) as client:
response = client.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
return soup.get_text()

insecure_google_search = Tool(
name="google_search",
description="Performs a Google search.",
input_model=GoogleSearchInput,
output_model=GoogleSearchOutput,
func=_google_search,
)

url_reader = Tool(
name="url_reader",
description="Reads the full content of a given URL.",
input_model=ReadUrlInput,
output_model=ReadUrlOutput,
func=_read_url,
)
### Relevant log output

```shell

```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.