[Bug] Antigravity CLI 1.3.6: a running turn fails with 401 UNAUTHENTICATED right after the hourly token refresh

Version: agy 1.3.6 on macOS 27.2 (Apple Silicon), Google AI Pro sign-in. The 1.4.0 changelog does not mention this, so it may still apply.

What happens
An agent turn that is already running fails with:
UNAUTHENTICATED (code 401): Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.
It happens 0 to 3 minutes after the CLI’s hourly token refresh. The refresh itself succeeds, and the next message works without signing in again. The turn that was running is lost.

Evidence (one session, ~/.gemini/antigravity-cli/log/cli-*.log, times in UTC+3)

  • token refreshed, new expiry=... every hour at HH:35:32 (18:35 to 01:35), each with an expiry one hour later.
  • agent executor error: generating and executing: UNAUTHENTICATED (code 401) at 01:36:53, 19:36:22, 20:35:50 and 22:36:18 on 16 Oct, and 01:38:17 on 17 Oct. Every one comes 0 to 3 minutes after a refresh.
  • Example: the previous token’s expiry was 01:35:31; the refresh ran at 01:35:32, one second after that expiry. A turn that started at 01:34:26 failed at 01:38:17. Error ID 11271020-936f-4a3c-953c-51cce2a5c2d1-287.

Likely cause
The refresh fires at the old token’s expiry rather than before it, and a turn that started earlier keeps using the old access token.

Expected
Refresh a few minutes before expiry, and let an in-flight request that gets a 401 retry once with the new token.

Repro
Keep a long, tool-using agent turn running across HH:35, for example one started a minute before the hourly refresh.

Workaround today
Sending a new message continues fine, but the interrupted turn’s work has to be redone.

Hi @Etka_Ahmet_Bulut,

Could you please upgrade to the latest Antigravity CLI version v1.4.9. Let me know is the issue resolves or the issue still persists?

@Ambati_Rajendra

Still reproducing on antigravity-cli v1.5.3 on Linux.

Just encountered this during a long autonomous tool-execution turn (chaining git diff, edits, and ninja builds). The agent suddenly halted with:

:warning: UNAUTHENTICATED (code 401): Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.

Error ID: 49ba0cc7-553e-439e-82b8-e77b503f1a2f-18465

Looking into ~/.gemini/antigravity-cli/log/, the race condition is very clear:

1. Initial token was loaded with ~15 mins remaining:

I1109 18:29:14.408866 keyring.go:64] keyringAuth: loaded token, expiry=2026-11-09 18:44:14 …

2. The background refresh successfully triggered at 18:44:15:

I1109 18:44:15.066742 browser.go:265] token refreshed, new expiry=2026-11-09 19:44:14 …

3. Concurrently, a parallel session logged:

E1109 19:44:32.958910 client.go:95] Clearcut responded with HTTP code: 401 (auth retries left: 2)

The running agent turn was using a stale in-flight token or caught in the token handoff window. When the 401 error occurred, the CLI immediately aborted the turn instead of attempting a transparent retry with the newly refreshed token.

Once I simply typed a dummy message to prompt it (continue), input_loop.go initiated a new user turn and resumed seamlessly without needing to re-login, confirming the credentials were valid.

Request:

Could the CLI transport layer (http_helpers.go / client.go) be updated to:

1. Always fetch the latest valid token dynamically before dispatching streamGenerateContent during continuous tool loops;

2. Implement transparent retry on 401 UNAUTHENTICATED when a valid refresh token exists, so long-running unattended agent workflows don’t get interrupted?