Skip to content

Commit ac6d4d5

Browse files
sjarmakclaude
andcommitted
fix: runtime fixes for ContextBench calibration (imports, auth, repo URL)
- Change `from scripts.context_retrieval_agent` to `from context_retrieval_agent` (fixes ModuleNotFoundError when PYTHONPATH is set) - Add CLAUDE_CODE_OAUTH_TOKEN fallback before ANTHROPIC_API_KEY - Fix repo URL construction: prefer repo_url field, construct from repo slug as fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8f46d49 commit ac6d4d5

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

scripts/validate_on_contextbench.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def run_retrieval_agent_on_cb_task(
418418
419419
Returns the agent's oracle output.
420420
"""
421-
from scripts.context_retrieval_agent import (
421+
from context_retrieval_agent import (
422422
run_agent, SourcegraphClient,
423423
)
424424

@@ -798,17 +798,24 @@ def main() -> int:
798798
log.error("pip install anthropic")
799799
return 1
800800

801-
api_key = os.environ.get("ANTHROPIC_API_KEY", "")
801+
# OAuth token preferred (subscription billing), API key fallback
802+
api_key = os.environ.get("CLAUDE_CODE_OAUTH_TOKEN", "")
803+
if api_key:
804+
log.info("Using OAuth token (CLAUDE_CODE_OAUTH_TOKEN)")
805+
else:
806+
api_key = os.environ.get("ANTHROPIC_API_KEY", "")
807+
if api_key:
808+
log.info("Using API key (ANTHROPIC_API_KEY)")
802809
if not api_key:
803-
log.error("ANTHROPIC_API_KEY not set")
810+
log.error("Set CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY")
804811
return 1
805812

806813
client = anthropic.Anthropic(api_key=api_key)
807814

808815
# Set up SG client if needed
809816
sg = None
810817
if args.backend in ("deepsearch", "hybrid"):
811-
from scripts.context_retrieval_agent import SourcegraphClient
818+
from context_retrieval_agent import SourcegraphClient
812819
sg = SourcegraphClient()
813820

814821
total_cost = 0.0
@@ -821,7 +828,12 @@ def main() -> int:
821828
break
822829

823830
instance_id = task.get("instance_id", f"task_{i}")
824-
repo_url = task.get("repo", task.get("repo_url", ""))
831+
repo_url = task.get("repo_url", "")
832+
if not repo_url:
833+
# Construct from repo field (org/repo -> full URL)
834+
repo_slug = task.get("repo", "")
835+
if repo_slug and "/" in repo_slug:
836+
repo_url = f"https://github.com/{repo_slug}"
825837
commit = task.get("base_commit", task.get("commit", "HEAD"))
826838

827839
log.info("[%d/%d] %s", i + 1, len(tasks), instance_id)

0 commit comments

Comments
 (0)