From b17b0e89437c20933703258957743945c43fcf44 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 14:04:27 +0000 Subject: [PATCH 1/3] chore: eliminate sys.path.insert hacks in scripts Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com> --- router/__init__.py | 0 router/main.py | 2 +- scripts/benchmark_classifier.py | 3 +-- scripts/benchmark_tokens.py | 3 --- scripts/classify_direct.py | 3 +-- scripts/reclassify_all.py | 1 - scripts/retry_errors.py | 1 - scripts/verification/verification_helpers.py | 3 --- scripts/verification/verify_breaker.py | 4 ---- scripts/verification/verify_canonical_endpoints.py | 1 - scripts/verification/verify_ollama_routing.py | 1 - 11 files changed, 3 insertions(+), 19 deletions(-) create mode 100644 router/__init__.py diff --git a/router/__init__.py b/router/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/router/main.py b/router/main.py index 0c976f4f..02b63c75 100644 --- a/router/main.py +++ b/router/main.py @@ -19,7 +19,7 @@ from fastapi.staticfiles import StaticFiles from pathlib import Path from urllib.parse import urlparse -from circuit_breaker import get_breaker +from router.circuit_breaker import get_breaker from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator, RootModel from typing import Dict, Optional, Union diff --git a/scripts/benchmark_classifier.py b/scripts/benchmark_classifier.py index 2878c402..7c584657 100644 --- a/scripts/benchmark_classifier.py +++ b/scripts/benchmark_classifier.py @@ -1,13 +1,12 @@ """Benchmark gemma4-26a4b-routing classifier against labeled dataset.""" import os -import json, urllib.request, urllib.error, time, sys +import json, urllib.request, urllib.error, time import concurrent.futures import threading from collections import defaultdict, Counter from pathlib import Path # Shared chat response parser (used by verification scripts too) -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from scripts.chat_helpers import parse_chat_response # Load dataset diff --git a/scripts/benchmark_tokens.py b/scripts/benchmark_tokens.py index 34c9a2f0..56c79be1 100644 --- a/scripts/benchmark_tokens.py +++ b/scripts/benchmark_tokens.py @@ -5,9 +5,6 @@ # Set CONFIG_PATH and ROUTER_API_KEY for import os.environ["CONFIG_PATH"] = str(Path(__file__).resolve().parent.parent / "router" / "config.yaml") os.environ["ROUTER_API_KEY"] = "local-token" -# Add the parent directory and the router directory to the path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "router")) from router.main import estimate_prompt_tokens, METADATA_OVERHEAD diff --git a/scripts/classify_direct.py b/scripts/classify_direct.py index ee699daf..e25871f0 100644 --- a/scripts/classify_direct.py +++ b/scripts/classify_direct.py @@ -1,10 +1,9 @@ """Direct classification of Hermes prompts using gemma4-26a4b-routing.""" import os -import json, urllib.request, time, sys +import json, urllib.request, time from pathlib import Path # Shared chat response parser (used by verification scripts too) -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from scripts.chat_helpers import parse_chat_response PROMPT_TEMPLATE = """Classify the coding task complexity. Output ONLY the tier name. diff --git a/scripts/reclassify_all.py b/scripts/reclassify_all.py index 38675878..96a0e020 100644 --- a/scripts/reclassify_all.py +++ b/scripts/reclassify_all.py @@ -8,7 +8,6 @@ from collections import Counter # Shared chat response parser (used by verification scripts too) -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from scripts.chat_helpers import parse_chat_response TIERS = ['agent-simple-core','agent-medium-core','agent-complex-core','agent-reasoning-core','agent-advanced-core'] diff --git a/scripts/retry_errors.py b/scripts/retry_errors.py index ed273721..f60eb3ff 100644 --- a/scripts/retry_errors.py +++ b/scripts/retry_errors.py @@ -4,7 +4,6 @@ from collections import Counter # Shared chat response parser (used by verification scripts too) -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from scripts.chat_helpers import parse_chat_response PROMPT_TEMPLATE = """Classify the coding task complexity. Output ONLY the tier name. diff --git a/scripts/verification/verification_helpers.py b/scripts/verification/verification_helpers.py index e4500d61..5b781edb 100644 --- a/scripts/verification/verification_helpers.py +++ b/scripts/verification/verification_helpers.py @@ -1,7 +1,4 @@ # Shared verification helpers for cooldown and routing tests -import sys -from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent)) from scripts.chat_helpers import parse_chat_response import os import uuid diff --git a/scripts/verification/verify_breaker.py b/scripts/verification/verify_breaker.py index 6ed9e7c7..37307613 100644 --- a/scripts/verification/verify_breaker.py +++ b/scripts/verification/verify_breaker.py @@ -1,10 +1,6 @@ #!/usr/bin/env python3 """Verification test for the agy circuit breaker.""" -import sys -from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent)) - from router.circuit_breaker import get_breaker b = get_breaker() diff --git a/scripts/verification/verify_canonical_endpoints.py b/scripts/verification/verify_canonical_endpoints.py index 13c7d9b2..d710c7a9 100644 --- a/scripts/verification/verify_canonical_endpoints.py +++ b/scripts/verification/verify_canonical_endpoints.py @@ -19,7 +19,6 @@ WORKDIR = Path(__file__).resolve().parent.parent.parent # Import shared chat response parser (also used by classifier scripts) -sys.path.insert(0, str(WORKDIR)) from scripts.chat_helpers import parse_chat_response diff --git a/scripts/verification/verify_ollama_routing.py b/scripts/verification/verify_ollama_routing.py index c844e549..e254839c 100644 --- a/scripts/verification/verify_ollama_routing.py +++ b/scripts/verification/verify_ollama_routing.py @@ -5,7 +5,6 @@ from pathlib import Path WORKDIR = Path(__file__).resolve().parent.parent.parent -sys.path.insert(0, str(WORKDIR)) from scripts.chat_helpers import parse_chat_response URL = "http://localhost:5000/v1/chat/completions" From a1820f55cdced1affcf12becd889d99b6f5bc107 Mon Sep 17 00:00:00 2001 From: sheepdestroyer Date: Sun, 12 Jul 2026 17:03:37 +0200 Subject: [PATCH 2/3] Update router/main.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- router/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/main.py b/router/main.py index 02b63c75..f38e334b 100644 --- a/router/main.py +++ b/router/main.py @@ -19,7 +19,7 @@ from fastapi.staticfiles import StaticFiles from pathlib import Path from urllib.parse import urlparse -from router.circuit_breaker import get_breaker +from .circuit_breaker import get_breaker from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator, RootModel from typing import Dict, Optional, Union From 4c32637cc7a1c3c6016ccc4c35b47a3fb8052a43 Mon Sep 17 00:00:00 2001 From: boy Date: Sun, 12 Jul 2026 17:17:34 +0200 Subject: [PATCH 3/3] fix: revert Gemini's relative import change; add import fallbacks - Revert 'from .circuit_breaker' to 'from router.circuit_breaker' in main.py: relative imports break when main.py is imported directly as 'main' (tests use 'from main import ...' with PYTHONPATH=.:router) - Add try/except ImportError fallback to 'from scripts.chat_helpers' across all 7 scripts (4 in scripts/, 3 in verification/) so they remain runnable via both package import and direct execution --- router/main.py | 2 +- scripts/benchmark_classifier.py | 5 ++++- scripts/classify_direct.py | 5 ++++- scripts/reclassify_all.py | 5 ++++- scripts/retry_errors.py | 5 ++++- scripts/verification/verification_helpers.py | 5 ++++- scripts/verification/verify_canonical_endpoints.py | 5 ++++- scripts/verification/verify_ollama_routing.py | 5 ++++- 8 files changed, 29 insertions(+), 8 deletions(-) diff --git a/router/main.py b/router/main.py index f38e334b..02b63c75 100644 --- a/router/main.py +++ b/router/main.py @@ -19,7 +19,7 @@ from fastapi.staticfiles import StaticFiles from pathlib import Path from urllib.parse import urlparse -from .circuit_breaker import get_breaker +from router.circuit_breaker import get_breaker from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator, RootModel from typing import Dict, Optional, Union diff --git a/scripts/benchmark_classifier.py b/scripts/benchmark_classifier.py index 7c584657..b2b7f1a7 100644 --- a/scripts/benchmark_classifier.py +++ b/scripts/benchmark_classifier.py @@ -7,7 +7,10 @@ from pathlib import Path # Shared chat response parser (used by verification scripts too) -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from chat_helpers import parse_chat_response # Load dataset dataset_path = Path(__file__).resolve().parent.parent / "data" / "classified_dataset.json" diff --git a/scripts/classify_direct.py b/scripts/classify_direct.py index e25871f0..237609c7 100644 --- a/scripts/classify_direct.py +++ b/scripts/classify_direct.py @@ -4,7 +4,10 @@ from pathlib import Path # Shared chat response parser (used by verification scripts too) -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from chat_helpers import parse_chat_response PROMPT_TEMPLATE = """Classify the coding task complexity. Output ONLY the tier name. diff --git a/scripts/reclassify_all.py b/scripts/reclassify_all.py index 96a0e020..b74e5653 100644 --- a/scripts/reclassify_all.py +++ b/scripts/reclassify_all.py @@ -8,7 +8,10 @@ from collections import Counter # Shared chat response parser (used by verification scripts too) -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from chat_helpers import parse_chat_response TIERS = ['agent-simple-core','agent-medium-core','agent-complex-core','agent-reasoning-core','agent-advanced-core'] diff --git a/scripts/retry_errors.py b/scripts/retry_errors.py index f60eb3ff..c4a30754 100644 --- a/scripts/retry_errors.py +++ b/scripts/retry_errors.py @@ -4,7 +4,10 @@ from collections import Counter # Shared chat response parser (used by verification scripts too) -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from chat_helpers import parse_chat_response PROMPT_TEMPLATE = """Classify the coding task complexity. Output ONLY the tier name. diff --git a/scripts/verification/verification_helpers.py b/scripts/verification/verification_helpers.py index 5b781edb..fa9722d3 100644 --- a/scripts/verification/verification_helpers.py +++ b/scripts/verification/verification_helpers.py @@ -1,5 +1,8 @@ # Shared verification helpers for cooldown and routing tests -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from ..chat_helpers import parse_chat_response import os import uuid import time diff --git a/scripts/verification/verify_canonical_endpoints.py b/scripts/verification/verify_canonical_endpoints.py index d710c7a9..f79855c4 100644 --- a/scripts/verification/verify_canonical_endpoints.py +++ b/scripts/verification/verify_canonical_endpoints.py @@ -19,7 +19,10 @@ WORKDIR = Path(__file__).resolve().parent.parent.parent # Import shared chat response parser (also used by classifier scripts) -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from ..chat_helpers import parse_chat_response def load_env(dev: bool = False) -> dict: diff --git a/scripts/verification/verify_ollama_routing.py b/scripts/verification/verify_ollama_routing.py index e254839c..c379c6a7 100644 --- a/scripts/verification/verify_ollama_routing.py +++ b/scripts/verification/verify_ollama_routing.py @@ -5,7 +5,10 @@ from pathlib import Path WORKDIR = Path(__file__).resolve().parent.parent.parent -from scripts.chat_helpers import parse_chat_response +try: + from scripts.chat_helpers import parse_chat_response +except ImportError: + from ..chat_helpers import parse_chat_response URL = "http://localhost:5000/v1/chat/completions"