-
Notifications
You must be signed in to change notification settings - Fork 322
fix: Gemini CLI exits 41 in AWF sandbox — missing API key and ~/.gemini dir #23695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/fix-gemini-cli-api-keys-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−3
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
31dd6e7
Initial plan
Copilot ea5887f
fix: set placeholder GEMINI_API_KEY and create ~/.gemini/ in AWF cont…
Copilot a483c87
refactor: extract geminiAPIKeyPlaceholder as a named constant
Copilot 0d8e41b
Merge branch 'main' into copilot/fix-gemini-cli-api-keys-issue
pelikhan d652c5e
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/89750aef-5aa…
Copilot 6eff27e
Merge branch 'main' into copilot/fix-gemini-cli-api-keys-issue
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,12 @@ import ( | |
|
|
||
| var geminiLog = logger.New("workflow:gemini_engine") | ||
|
|
||
| // geminiAPIKeyPlaceholder is the placeholder value set for GEMINI_API_KEY inside the AWF | ||
| // container. The real key is excluded from the container (held by AWF's api-proxy sidecar), | ||
| // but Gemini CLI v0.65.0+ requires some auth method configured before starting. The sidecar | ||
| // intercepts all LLM API calls and handles authentication transparently. | ||
| const geminiAPIKeyPlaceholder = "gemini-api-key-placeholder" | ||
|
|
||
| // GeminiEngine represents the Google Gemini CLI agentic engine | ||
| type GeminiEngine struct { | ||
| BaseEngine | ||
|
|
@@ -248,7 +254,19 @@ func (e *GeminiEngine) GetExecutionSteps(workflowData *WorkflowData, logFile str | |
| } | ||
|
|
||
| npmPathSetup := GetNpmBinPathSetup() | ||
| geminiCommandWithPath := fmt.Sprintf("%s && %s", npmPathSetup, geminiCommand) | ||
|
|
||
| // Inside the AWF container, GEMINI_API_KEY is excluded from the environment (via | ||
| // --exclude-env) so the agent cannot exfiltrate the real secret via bash tools. | ||
| // However, Gemini CLI v0.65.0+ performs a startup auth check and exits with code 41 | ||
| // if no auth method is configured when GEMINI_API_BASE_URL (the api-proxy) is set. | ||
| // To satisfy this check, set a placeholder value for GEMINI_API_KEY inside the | ||
| // container — the real key is held by AWF's api-proxy sidecar which intercepts all | ||
| // LLM API calls and handles authentication transparently. | ||
| // | ||
| // Also create $HOME/.gemini/ so Gemini CLI can save its project registry without | ||
| // failing with ENOENT (the directory may not exist in the container filesystem). | ||
| awfContainerSetup := fmt.Sprintf(`mkdir -p "$HOME/.gemini" && export GEMINI_API_KEY="${GEMINI_API_KEY:-%s}"`, geminiAPIKeyPlaceholder) | ||
| geminiCommandWithPath := fmt.Sprintf("%s && %s && %s", awfContainerSetup, npmPathSetup, geminiCommand) | ||
|
|
||
| command = BuildAWFCommand(AWFCommandConfig{ | ||
| EngineName: "gemini", | ||
|
|
@@ -266,8 +284,11 @@ func (e *GeminiEngine) GetExecutionSteps(workflowData *WorkflowData, logFile str | |
| ExcludeEnvVarNames: ComputeAWFExcludeEnvVarNames(workflowData, []string{"GEMINI_API_KEY"}), | ||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to add |
||
| } else { | ||
| // Create $HOME/.gemini/ to prevent ENOENT when Gemini CLI saves its project | ||
| // registry (the directory may not exist on a fresh runner instance). | ||
| command = fmt.Sprintf(`set -o pipefail | ||
| touch %s | ||
| mkdir -p "$HOME/.gemini" | ||
| %s 2>&1 | tee -a %s`, AgentStepSummaryPath, geminiCommand, logFile) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
awfContainerSetupapproach is clean — using\$\{GEMINI_API_KEY:-gemini-api-key-placeholder}ensures the placeholder only applies when the real key isn't already set, which is exactly the right behavior for the AWF sidecar pattern.