Skip to content

Commit b2277c1

Browse files
authored
fix: remove obsolete SDK version check in register-gemini-enterprise (#897)
The SDK compatibility check for the Agent Engine "Session not found" bug (#495) triggered for any google-cloud-aiplatform version <= 1.128.0, including versions that predated the bug entirely. Since the fix has been available on PyPI since 1.128.0 (current latest is 1.142.0), the check is no longer needed and was causing false warnings for users.
1 parent c6d8682 commit b2277c1

1 file changed

Lines changed: 0 additions & 167 deletions

File tree

agent_starter_pack/cli/commands/register_gemini_enterprise.py

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
import json
1919
import os
2020
import subprocess
21-
import sys
2221
from pathlib import Path
2322

2423
import click
2524
import requests
2625
import vertexai
2726
from google.auth import default
2827
from google.auth.transport.requests import Request as GoogleAuthRequest
29-
from packaging import version
3028
from rich.console import Console
3129

3230
from agent_starter_pack.cli.utils.command import run_gcloud_command
@@ -36,12 +34,6 @@
3634
)
3735
from agent_starter_pack.cli.utils.logging import display_welcome_banner
3836

39-
# TOML parser - use standard library for Python 3.11+, fallback to tomli
40-
if sys.version_info >= (3, 11):
41-
import tomllib
42-
else:
43-
import tomli as tomllib
44-
4537
console = Console(highlight=False)
4638
console_err = Console(stderr=True, highlight=False)
4739

@@ -53,158 +45,6 @@ def _strip_callback(
5345
return value.strip() if value else value
5446

5547

56-
# SDK version that contains the fix for Gemini Enterprise session bug
57-
# See: https://github.com/GoogleCloudPlatform/agent-starter-pack/issues/495
58-
SDK_MIN_VERSION_FOR_GEMINI_ENTERPRISE = "1.128.0"
59-
60-
# SDK upgrade command constants
61-
_SDK_UPGRADE_PACKAGE = (
62-
"google-cloud-aiplatform[adk,agent_engines] "
63-
"@ git+https://github.com/googleapis/python-aiplatform.git"
64-
)
65-
_SDK_UPGRADE_COMMAND = f'uv add "{_SDK_UPGRADE_PACKAGE}"'
66-
67-
68-
def get_sdk_version_from_lock_file() -> tuple[str | None, bool]:
69-
"""Get google-cloud-aiplatform version and source from uv.lock file.
70-
71-
Returns:
72-
Tuple of (version string or None, is_from_git boolean).
73-
If from git, the fix is assumed to be applied regardless of version.
74-
"""
75-
lock_path = Path("uv.lock")
76-
if not lock_path.exists():
77-
return None, False
78-
79-
try:
80-
with open(lock_path, "rb") as f:
81-
lock_data = tomllib.load(f)
82-
83-
for package in lock_data.get("package", []):
84-
if package.get("name") == "google-cloud-aiplatform":
85-
found_version = package.get("version")
86-
source = package.get("source")
87-
is_from_git = isinstance(source, dict) and "git" in source
88-
return found_version, is_from_git
89-
90-
return None, False
91-
except (tomllib.TOMLDecodeError, OSError):
92-
return None, False
93-
94-
95-
def _is_sdk_version_affected(current_version: str) -> bool:
96-
"""Check if the SDK version is affected by the Gemini Enterprise bug."""
97-
return version.parse(current_version) <= version.parse(
98-
SDK_MIN_VERSION_FOR_GEMINI_ENTERPRISE
99-
)
100-
101-
102-
def _print_sdk_compatibility_warning(current_version: str) -> None:
103-
"""Print warning message about SDK compatibility issue."""
104-
console.print("\n" + "=" * 70)
105-
console.print("[yellow]⚠️ Agent Engine SDK Compatibility Issue Detected[/yellow]")
106-
console.print("=" * 70)
107-
console.print(
108-
f"\nYour current google-cloud-aiplatform version ({current_version}) has a known"
109-
)
110-
console.print("issue with Agent Engine that causes 'Session not found' errors when")
111-
console.print("registering to Gemini Enterprise.")
112-
console.print(
113-
"\nSee: https://github.com/GoogleCloudPlatform/agent-starter-pack/issues/495"
114-
)
115-
console.print(
116-
"\n[bold]The fix is available in the SDK git repository "
117-
"(will be in PyPI >1.128.0).[/bold]"
118-
)
119-
120-
121-
def _run_sdk_upgrade() -> bool:
122-
"""Execute the SDK upgrade command.
123-
124-
Returns:
125-
True if upgrade succeeded, False otherwise.
126-
"""
127-
console.print("\n[blue]Upgrading SDK from git (this may take a minute)...[/blue]")
128-
try:
129-
result = subprocess.run(
130-
["uv", "add", _SDK_UPGRADE_PACKAGE],
131-
capture_output=True,
132-
text=True,
133-
timeout=300, # 5 minute timeout
134-
)
135-
136-
if result.returncode == 0:
137-
console.print("\n[green]✅ SDK upgraded successfully![/green]")
138-
console.print("\n[bold]Next steps:[/bold]")
139-
console.print(
140-
" 1. Redeploy your agent to pick up the fix: [cyan]make deploy[/cyan]"
141-
)
142-
console.print(" 2. Re-run this command to register with Gemini Enterprise")
143-
return True
144-
145-
console_err.print(f"\n[red]❌ Failed to upgrade SDK:[/red]\n{result.stderr}")
146-
console.print(f"\nYou can manually run:\n {_SDK_UPGRADE_COMMAND}")
147-
return False
148-
149-
except FileNotFoundError:
150-
console_err.print(
151-
"\n[yellow]⚠️ 'uv' command not found. Please run manually:[/yellow]"
152-
)
153-
console.print(f" {_SDK_UPGRADE_COMMAND}")
154-
return False
155-
except subprocess.TimeoutExpired:
156-
console_err.print("\n[red]❌ Upgrade timed out.[/red]")
157-
return False
158-
159-
160-
def check_and_upgrade_sdk_for_agent_engine() -> bool:
161-
"""Check if SDK version is compatible with Gemini Enterprise and offer to upgrade.
162-
163-
For Agent Engine deployments, there's a known issue with SDK versions <= 1.128.0
164-
that causes 'Session not found' errors. The fix is available in the git repo.
165-
166-
Returns:
167-
True if SDK is compatible or user upgraded, False if user chose to abort.
168-
"""
169-
try:
170-
current_version, is_from_git = get_sdk_version_from_lock_file()
171-
172-
if not current_version:
173-
# No lock file or couldn't parse - skip check
174-
return True
175-
176-
if is_from_git:
177-
# Installed from git - assume fix is applied
178-
return True
179-
180-
if not _is_sdk_version_affected(current_version):
181-
return True # Version is OK
182-
183-
# Version is affected - warn user and offer upgrade
184-
_print_sdk_compatibility_warning(current_version)
185-
186-
if click.confirm(
187-
"\nWould you like to upgrade to the fixed version from git now?",
188-
default=True,
189-
):
190-
if _run_sdk_upgrade():
191-
return False # User needs to redeploy and restart
192-
return click.confirm(
193-
"\nContinue anyway (may encounter errors)?", default=False
194-
)
195-
196-
# User declined upgrade
197-
console.print(
198-
f"\nYou can manually upgrade later by running:\n {_SDK_UPGRADE_COMMAND}"
199-
)
200-
return click.confirm("\nContinue anyway (may encounter errors)?", default=False)
201-
202-
except Exception as e:
203-
# If we can't check the version, just continue
204-
console_err.print(f"[dim]Warning: Could not check SDK version: {e}[/dim]")
205-
return True
206-
207-
20848
def get_discovery_engine_endpoint(location: str) -> str:
20949
"""Get the appropriate Discovery Engine API endpoint for the given location.
21050
@@ -1551,13 +1391,6 @@ def register_gemini_enterprise(
15511391

15521392
# ADK
15531393
else:
1554-
# Check SDK version compatibility for Agent Engine deployments
1555-
# See: https://github.com/GoogleCloudPlatform/agent-starter-pack/issues/495
1556-
# Skip interactive prompts in --yes mode
1557-
if not yes and not check_and_upgrade_sdk_for_agent_engine():
1558-
console.print("\n[yellow]Registration aborted.[/yellow]")
1559-
return
1560-
15611394
# Step 1: Get Agent Engine ID
15621395
resolved_agent_engine_id = agent_engine_id
15631396

0 commit comments

Comments
 (0)