|
| 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 |
0 commit comments