-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Background Agent hangs indefinitely during authentication in headless environments #20854
Copy link
Copy link
Closed
Copy link
Labels
area/non-interactiveIssues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automationIssues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automationstatus/need-triageIssues that need to be triaged by the triage automation.Issues that need to be triaged by the triage automation.workstream-rollupLabel used to tag epics and features that are associated with one of the three primary workstreamsLabel used to tag epics and features that are associated with one of the three primary workstreams🔒 maintainer only⛔ Do not contribute. Internal roadmap item.⛔ Do not contribute. Internal roadmap item.
Metadata
Metadata
Assignees
Labels
area/non-interactiveIssues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automationIssues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automationstatus/need-triageIssues that need to be triaged by the triage automation.Issues that need to be triaged by the triage automation.workstream-rollupLabel used to tag epics and features that are associated with one of the three primary workstreamsLabel used to tag epics and features that are associated with one of the three primary workstreams🔒 maintainer only⛔ Do not contribute. Internal roadmap item.⛔ Do not contribute. Internal roadmap item.
Type
Fields
Give feedbackNo fields configured for Bug.
Projects
StatusShow more project fields
Closed
Summary
The CLI auth logic has a dependency on interactive stdin when a browser cannot be launched. When the agent is run as a background process (specifically for GCA) in headless environments like Cloud Shell or Cloud Workstations, it encounters a "silent hang," preventing the server from ever successfully starting.
Root Cause
packages/core/src/code_assist/oauth2.ts, if the library detects that a browser cannot be opened (isBrowserLaunchSuppressed()), it automatically falls back toauthWithUserCode.authWithUserCodecreates areadlineinterface and executesrl.question('Enter the authorization code: ', ... ).a2a-server) is a background process. Itsstdinis a pipe, not a TTY. It waits indefinitely for user input that can never be provided, causing the process to hang before it can log its port or start serving requests.Proposed Solution
We need to make the below 3 changes.
1. Prevent the Hang (
packages/core)Modify the OAuth client initialization to respect the interactivity of the session:
oauth2.ts, before callingauthWithUserCode, checkconfig.isInteractive().FatalAuthenticationErrorimmediately. This turns a silent hang into a catchable exception.2. Dynamic Interactivity (
packages/a2a-server)Update the A2A server configuration to detect its environment:
src/config/config.ts, set the interactive flag dynamically using!isHeadlessMode().3. Implement Automated Fallback (
packages/a2a-server)Align the Agent's authentication behavior with the GCA Language Server:
refreshAuthenticationlogic, wrap theLOGIN_WITH_GOOGLEattempt in a try-catch block.FatalAuthenticationError(indicating a headless environment with no saved credentials) and the environment is detected as Cloud Shell or Cloud Workstations, automatically fall back toAuthType.COMPUTE_ADC.