Skip to content

Commit 6ca504f

Browse files
justaddcoffeeclaude
andcommitted
Fix Gemini CLI evaluation issues and update notebook
- Fix LICENSE: Remove 'pytest-' prefix from project name - Fix Gemini CLI hanging: Patch metacoder to add --yolo flag - Fix Gemini CLI auth prompts: Copy OAuth credentials to workdirs - Update run_gemini_eval.sh: Add OPENAI_API_KEY and ANTHROPIC_API_KEY - Update experiment_1_run_evaluations.ipynb: Make cells executable - Document fixes in notes/GEMINI_CLI_YOLO_FIX.md The Gemini CLI was hanging indefinitely because it waited for user approval for tool calls even in non-interactive mode. Fixed by adding --yolo flag to auto-approve all actions. Additionally, each test workdir triggered OAuth re-authentication. Fixed by copying google_accounts.json and oauth_creds.json from ~/.gemini/ to each workdir. Both fixes are temporary patches to the installed metacoder package and should be contributed upstream. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3b5b441 commit 6ca504f

4 files changed

Lines changed: 108 additions & 34 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ modification, are permitted provided that the following conditions are met:
1111
this list of conditions and the following disclaimer in the documentation
1212
and/or other materials provided with the distribution.
1313

14-
* Neither the name of pytest-mcp_literature_eval nor the names of its
14+
* Neither the name of mcp_literature_eval nor the names of its
1515
contributors may be used to endorse or promote products derived from
1616
this software without specific prior written permission.
1717

notebook/experiment_1_run_evaluations.ipynb

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@
5555
"execution_count": null,
5656
"metadata": {},
5757
"outputs": [],
58-
"source": [
59-
"# Run Claude evaluation\n",
60-
"# Uncomment to run:\n",
61-
"# !./run_claude_eval.sh\n",
62-
"\n",
63-
"print(\"Claude evaluation script: ./run_claude_eval.sh\")\n",
64-
"print(\"Status: Already completed (results/compare_agents/claude_20251031.yaml)\")"
65-
]
58+
"source": "# Check if Claude evaluation already exists\nclaude_result = f\"results/compare_agents/claude_{datetime.now().strftime('%Y%m%d')}.yaml\"\nif os.path.exists(claude_result):\n print(f\"✓ Claude evaluation already completed: {claude_result}\")\nelse:\n print(\"Running Claude evaluation (this takes 2-3 hours)...\")\n result = subprocess.run([\"./run_claude_eval.sh\"], capture_output=True, text=True)\n if result.returncode == 0:\n print(\"✓ Claude evaluation complete!\")\n else:\n print(f\"✗ Error: {result.stderr}\")"
6659
},
6760
{
6861
"cell_type": "markdown",
@@ -82,14 +75,7 @@
8275
"execution_count": null,
8376
"metadata": {},
8477
"outputs": [],
85-
"source": [
86-
"# Run Goose evaluation\n",
87-
"# Uncomment to run:\n",
88-
"# !./run_goose_eval.sh\n",
89-
"\n",
90-
"print(\"Goose evaluation script: ./run_goose_eval.sh\")\n",
91-
"print(\"Status: Needs re-run with fixed MCP configs\")"
92-
]
78+
"source": "# Check if Goose evaluation already exists\ngoose_result = f\"results/compare_agents/goose_{datetime.now().strftime('%Y%m%d')}.yaml\"\nif os.path.exists(goose_result):\n print(f\"✓ Goose evaluation already completed: {goose_result}\")\nelse:\n print(\"Running Goose evaluation (this takes 2-3 hours)...\")\n result = subprocess.run([\"./run_goose_eval.sh\"], capture_output=True, text=True)\n if result.returncode == 0:\n print(\"✓ Goose evaluation complete!\")\n else:\n print(f\"✗ Error: {result.stderr}\")"
9379
},
9480
{
9581
"cell_type": "markdown",
@@ -109,14 +95,7 @@
10995
"execution_count": null,
11096
"metadata": {},
11197
"outputs": [],
112-
"source": [
113-
"# Run Gemini evaluation\n",
114-
"# Uncomment to run:\n",
115-
"# !./run_gemini_eval.sh\n",
116-
"\n",
117-
"print(\"Gemini evaluation script: ./run_gemini_eval.sh\")\n",
118-
"print(\"Status: Currently running in background\")"
119-
]
98+
"source": "# Check if Gemini evaluation already exists\ngemini_result = f\"results/compare_agents/gemini_{datetime.now().strftime('%Y%m%d')}.yaml\"\nif os.path.exists(gemini_result):\n print(f\"✓ Gemini evaluation already completed: {gemini_result}\")\nelse:\n print(\"Running Gemini evaluation (this takes 2-3 hours)...\")\n result = subprocess.run([\"./run_gemini_eval.sh\"], capture_output=True, text=True)\n if result.returncode == 0:\n print(\"✓ Gemini evaluation complete!\")\n else:\n print(f\"✗ Error: {result.stderr}\")"
12099
},
121100
{
122101
"cell_type": "markdown",
@@ -175,14 +154,7 @@
175154
"execution_count": null,
176155
"metadata": {},
177156
"outputs": [],
178-
"source": [
179-
"# Run cross-agent analysis notebook\n",
180-
"# Uncomment when all evaluations are complete:\n",
181-
"# !jupyter nbconvert --execute --to notebook --inplace experiment_1_cross_agent_analysis.ipynb\n",
182-
"\n",
183-
"print(\"Analysis notebook: experiment_1_cross_agent_analysis.ipynb\")\n",
184-
"print(\"Run after all three evaluations are complete\")"
185-
]
157+
"source": "# Check if all evaluations are complete, then run analysis\nresult_files = glob('results/compare_agents/*.yaml')\nagents_complete = {'claude': False, 'goose': False, 'gemini': False}\n\nfor f in result_files:\n agent = Path(f).stem.split('_')[0]\n if agent in agents_complete:\n agents_complete[agent] = True\n\nif all(agents_complete.values()):\n print(\"All evaluations complete! Running cross-agent analysis...\")\n result = subprocess.run([\n \"jupyter\", \"nbconvert\", \"--execute\", \"--to\", \"notebook\", \n \"--inplace\", \"experiment_1_cross_agent_analysis.ipynb\"\n ], capture_output=True, text=True)\n if result.returncode == 0:\n print(\"✓ Analysis complete!\")\n else:\n print(f\"✗ Error: {result.stderr}\")\nelse:\n missing = [k for k, v in agents_complete.items() if not v]\n print(f\"⏳ Waiting for evaluations to complete: {', '.join(missing)}\")\n print(\"Run this cell again after all evaluations finish.\")"
186158
},
187159
{
188160
"cell_type": "markdown",
@@ -250,4 +222,4 @@
250222
},
251223
"nbformat": 4,
252224
"nbformat_minor": 4
253-
}
225+
}

notes/GEMINI_CLI_YOLO_FIX.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Gemini CLI --yolo Flag Fix
2+
3+
## Issue
4+
5+
When running Gemini CLI evaluations through metacoder, the process was hanging indefinitely after sending the prompt. Investigation revealed:
6+
7+
1. Gemini CLI was invoked with `-p` (non-interactive prompt mode)
8+
2. The session log showed only the user message, no response
9+
3. Process remained stuck for 17+ minutes with no progress
10+
11+
## Root Cause
12+
13+
Gemini CLI's non-interactive mode (`-p/--prompt`) **still requires user approval for tool calls** by default. When the MCP tools (like ARTL) needed to be invoked, Gemini was waiting for user confirmation, causing the process to hang indefinitely.
14+
15+
From `gemini --help`:
16+
```
17+
--yolo Automatically accept all actions (aka YOLO mode)? [boolean] [default: false]
18+
--approval-mode Set the approval mode: default (prompt for approval), auto_edit (auto-approve edit tools), yolo (auto-approve all tools) [string] [choices: "default", "auto_edit", "yolo"]
19+
```
20+
21+
## Solution
22+
23+
Modified metacoder's `GeminiCoder` class with two fixes:
24+
25+
### Fix 1: Add --yolo flag for non-interactive mode
26+
27+
**File**: `.venv/lib/python3.10/site-packages/metacoder/coders/gemini.py`
28+
29+
**Line 154-156** (changed):
30+
```python
31+
# Build the command using non-interactive mode (-p flag)
32+
# Add --yolo flag to auto-approve all tool actions in non-interactive mode
33+
command = ["gemini", "-p", text, "--yolo"]
34+
```
35+
36+
Previously:
37+
```python
38+
# Build the command using non-interactive mode (-p flag)
39+
command = ["gemini", "-p", text]
40+
```
41+
42+
### Fix 2: Copy OAuth credentials to avoid re-authentication
43+
44+
Each test workdir gets a fresh `.gemini/` directory, causing Gemini CLI to re-authenticate (opening browser) for every test.
45+
46+
**File**: `.venv/lib/python3.10/site-packages/metacoder/coders/gemini.py`
47+
48+
**Line 116-133** (added after line 114):
49+
```python
50+
# Copy OAuth credentials from global config to avoid re-authentication
51+
# This copies google_accounts.json and oauth_creds.json
52+
global_gemini_dir = Path.home() / ".gemini"
53+
for auth_file in ["google_accounts.json", "oauth_creds.json"]:
54+
auth_path = global_gemini_dir / auth_file
55+
if auth_path.exists():
56+
try:
57+
with open(auth_path) as f:
58+
auth_content = json.load(f)
59+
config_objects.append(
60+
CoderConfigObject(
61+
file_type=FileType.JSON,
62+
relative_path=f".gemini/{auth_file}",
63+
content=auth_content,
64+
)
65+
)
66+
except Exception as e:
67+
logger.warning(f"Could not load {auth_file}: {e}")
68+
```
69+
70+
## Testing
71+
72+
Verified the fix with a single test case:
73+
74+
```bash
75+
# Before fix: Hung indefinitely (>17 minutes)
76+
# After fix: Completed in ~19-21 seconds ✓
77+
78+
$ timeout 120 uv run metacoder eval /tmp/gemini_test_one_case.yaml -o /tmp/gemini_test_result.yaml
79+
💎 Running command: gemini with prompt
80+
💎 Command took 19.11 seconds
81+
✓ Evaluation completed 🎉!
82+
```
83+
84+
## Impact
85+
86+
- **Before**: Gemini evaluations impossible due to infinite hang
87+
- **After**: Gemini evaluations complete successfully in reasonable time (~20-30 seconds per test)
88+
- **Note**: This is a temporary patch to the installed metacoder package. The fix should be contributed upstream to the metacoder project.
89+
90+
## Related Issues
91+
92+
- Gemini evaluations also require `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` environment variables for the evaluation metrics (CorrectnessMetric uses these models for scoring)
93+
- Updated `run_gemini_eval.sh` to export these keys
94+
95+
## Upstream Fix Needed
96+
97+
This fix should be submitted as a pull request to the metacoder repository:
98+
- Repository: https://github.com/ai4curation/metacoder
99+
- Suggested change: Add `--yolo` flag to the gemini command in `metacoder/coders/gemini.py`
100+
- Alternative: Make approval mode configurable via the coder config YAML

run_gemini_eval.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22
cd /Users/jtr4v/PythonProject/mcp_literature_eval
3+
export OPENAI_API_KEY=$(cat ~/openai.key)
4+
export ANTHROPIC_API_KEY=$(cat ~/anthropic.key)
35
export PUBMED_EMAIL=justinreese@lbl.gov
46
export PUBMED_API_KEY=01eec0a16472164c6d69163bd28368311808
57
rm -f results/compare_agents/gemini_$(date +%Y%m%d).yaml

0 commit comments

Comments
 (0)