Skip to content

Linux: agy-cli-manager cannot import/login accounts — agy 1.2.x stores the OAuth token in the Secret Service, not a file #7

Closed

Description

@WindWang2

Summary

On Linux, agy-cli-manager cannot import, log in, or switch accounts when paired with a recent Antigravity CLI (agy). Like the macOS Keychain problem in #2 and the Windows Credential Manager problem in #1/#5, agy stores its OAuth token in the OS credential store instead of the antigravity-cli/antigravity-oauth-token file that this project expects — but no Linux report exists yet, so the credential-store rework is currently Linux-unaware.

The good news: on Linux the stored value is plain JSON, not an opaque blob, so the fix is considerably smaller than the macOS one. See Why Linux is easier below.

Environment

  • agy-cli-manager: v0.2.2 (latest release wheel)
  • agy (Antigravity CLI): 1.2.14
  • OS: Linux (CachyOS, KDE Plasma)
  • Credential store: Secret Service via KWallet (kwalletd6 / libsecret)
  • Python: 3.14

Steps to reproduce

agy itself works and is authenticated:

$ agy

      ▄▀▀▄        Antigravity CLI 1.2.14
     ▀▀▀▀▀▀       user@example.com (Google AI Pro)

But every profile-import path fails:

$ agy-cli-manager import-current main ~/.gemini
error: Profile source is missing required auth files: /home/<user>/.gemini

$ agy-cli-manager import-current main ~/.gemini/
error: Profile source is missing required auth files: /home/<user>/.gemini

agy-cli-manager login fails the same way — the interactive agy login completes successfully, then:

error: agy login did not produce a usable auth profile.

This matches #2 exactly, so the current upstream diagnosis ("credential store need rework with different logic on different OS") applies here as well.

Root cause

agy 1.2.x migrated the token to the Secret Service. The account is present, but not as a file:

$ secret-tool search service gemini
[/org/freedesktop/secrets/collection/login/…]
label = Password for 'antigravity' on 'gemini'
attribute.service = gemini
attribute.username = antigravity

Nothing is ever written to ~/.gemini/antigravity-cli/.

Evidence

1. The agy logs report keyring-backed auth:

keyring.go:64]       keyringAuth: loaded token, expiry=2026-10-01 00:54:46 +0800 expired=false
auth.go:157]         ChainedAuth: authenticated via keyring (effective: keyring)
server_oauth.go:198] applyAuthResult: email=<redacted>, authMethod=consumer
server_oauth.go:203] OAuth: authenticated successfully

2. The agy binary never references the legacy token path:

$ strings ~/.local/bin/agy | grep antigravity-oauth-token
# (no output)

3. The agy binary does embed a Secret Service client — it vendors zalando/go_keyring plus its own detectors:

third_party/golang/github_com/zalando/go_keyring/v/v0/keyring.go
third_party/golang/github_com/zalando/go_keyring/v/v0/keyring_unix.go
third_party/golang/github_com/zalando/go_keyring/v/v0/keyring_fallback.go
third_party/golang/github_com/zalando/go_keyring/v/v0/secret_service/secret_service.go
third_party/jetski/cli/backend/auth/keyring.go
third_party/jetski/language_server/code_assist_client/keyring_detector.go
third_party/jetski/language_server/code_assist_client/keyring_detector_dbus.go

with log messages such as Using file-based token storage because %s detected, Keyring SaveToken timed out after %v, falling back to file storage, and Failed to load token from keyring, falling back to file: %v.

4. agy exposes no profile/home override (agy --help has no --profile, GEMINI_HOME, or equivalent), so per-account home directories cannot be used to isolate credentials.

Because the token lives in a single global Secret Service slot (service=gemini, username=antigravity) and never in a file, profile_has_login_artifacts() returns false and every import/switch path aborts.

Why the Linux fix is smaller than macOS

In #2 the macOS Keychain value is a 686-byte opaque blob, so the proposed workaround cannot reuse the existing quota/identity code. On Linux the value is plain JSON, and its schema is byte-compatible with what manager._load_antigravity_token_state() already parses:

{
  "token": {
    "access_token": "<redacted>",
    "token_type": "Bearer",
    "refresh_token": "<redacted>",
    "expiry": "2026-10-01T01:00:18.126701991+08:00"
  },
  "auth_method": "consumer",
  "id_token": "<redacted JWT; carries the account email claim>"
}

Concretely, manager.py already reads data["token"]["access_token"], data["token"]["refresh_token"], data["token"]["expiry"], and data["id_token"] — all of which exist here. So a bridge that copies the document between the Secret Service and the expected file path makes all existing code work unmodified, including:

  • _extract_access_token() / _has_refresh_token() / _token_expiry_due()
  • refresh-usage (real Cloud Code quota calls)
  • _identity_from_antigravity_token() via the id_token email claim
  • whoami via google_userinfo

Minimal implementation sketch

secret-tool is already a standard dependency on KDE/GNOME systems and is enough — no D-Bus library needed:

# Secret Service -> file
secret-tool lookup service gemini username antigravity
#   > ~/.gemini/antigravity-cli/antigravity-oauth-token

# file -> Secret Service (on switch)
secret-tool store --label="Password for 'antigravity' on 'gemini'" \
  service gemini username antigravity < profile-token-file

Round-tripping the document verbatim is byte-exact, so a switch does not reformat the stored credential. Hooks needed (four, all one-liners):

Location Direction
save_account_profile() export, before the profile_has_login_artifacts() check
_sync_runtime_to_live_dir() import, after _copy_account_profile()
login_account() export, after the agy subprocess exits
new keyring-sync command re-capture the active profile after agy rotates its token

A guard is needed on the export side: only export when the target really is a live agy home (e.g. it contains antigravity-cli/log) and has no token file yet. Otherwise adding a saved profile directory would overwrite that account's stored credential with whatever is currently live.

I have a working local implementation of exactly this (~150 lines, plus 3 hooks) and can provide a diff or a PR if that is useful.

Caveats a Linux implementation must handle

These are the same constraints #5 lists for Windows, restated for Secret Service:

  1. Single global slot. Switching overwrites the live entry. There is one credential, not N.
  2. Restart required. agy caches the token in memory, so a switch only takes effect after restarting the agy process. Same as the existing file-based model.
  3. Refresh-token rotation. agy refreshes on its own and rewrites the entry, so a profile saved earlier goes stale. A keyring-sync-style command (export live → active saved profile) is needed to keep stored copies usable, and a stale refresh token may eventually be revoked by Google.
  4. Plaintext token files are a new exposure. The file-based model materialises a 0600 credential file that did not previously exist on Linux. Worth documenting.
  5. Secret Service availability. secret-tool may block on a locked collection or prompt for a password in some setups; failures should degrade gracefully rather than abort a switch.

Related

Happy to test any approach, including a --credential-store abstraction that covers all three platforms.

Activity

  1. Dandroid-D commented on Oct 2, 2026

    @Dandroid-D

    Draft comment for zcop/agy-cli-manager issue #7 — NOT POSTED (awaits user approval)

    Linux workaround that works in production (4 Pro accounts, agy 1.2.14)

    Thanks for the excellent diagnosis in this issue — we hit exactly this on
    CachyOS/KDE (Plasma, gnome-keyring via org.freedesktop.secrets) and confirmed
    every part of it live, plus a few extra behaviors that may help other Linux users:

    Additional findings

    1. agy reads the OS keyring BEFORE the token file, even when a (valid or corrupt)
      token file is present — a fresh $HOME with the keyring reachable silently
      authenticates the keyring's account (this is why login/import "auto-login"
      to the existing account).
    2. agy also WRITES refreshed tokens back to the keyring when it loaded them from
      the file — so after any manual token-file switch, the stale keyring entry
      keeps winning until it is cleared.
    3. Single-attribute secret-tool search service gemini can MISS the entry on some
      setups; the reliable emptiness check is the two-attribute
      org.freedesktop.Secret.Service.SearchItems call with both
      {'service': 'gemini', 'username': 'antigravity'}.

    Working procedure (since agy 1.2.13 dual-writes, token files still exist)

    • Switching = swap the token file + clear the keyring entry; the next agy run
      loads the new account from the file and re-seeds the keyring correctly
      (self-healing). We enforce this with a systemd user path unit watching the live
      token file AND the manager's state.json (the manager copies auth files before
      publishing state, so watching state.json alone misses crash windows).
    • Quota refresh must run with DBUS_SESSION_BUS_ADDRESS pointed at a dead socket,
      otherwise agy writes refreshed tokens to the keyring and the manager keeps
      reading stale files (PermissionError loop).
    • Account recovery without re-login: if an OAuth completed keyring-only, the token
      can be captured with secret-tool lookup service gemini username antigravity,
      its account identified by decoding the id_token JWT sub/email, and
      imported with agy-cli-manager add <name> <dir-with-.gemini>.

    Happy to contribute the guard units or a patch sketch if useful.

  2. self-assigned this
    on Oct 3, 2026
  3. zcop commented on Oct 3, 2026

    @zcop
    Owner

    Fixed in 043f204 and pushed to main.

    Implemented Linux Secret Service support with:

    • auto, file, and secret-service credential backends
    • keyring-only account import
    • atomic keyring/file/runtime activation with rollback
    • refusal to switch or capture while agy is running
    • isolated login and named-profile probe handling
    • stable CLI, JSON, and Python interfaces

    Validation completed against a real Debian 13 GNOME/KVM desktop session:

    • Secret Service auto-detection succeeded
    • synthetic credential store/read succeeded using the exact service=gemini, username=antigravity attributes
    • keyring-only import produced a mode 0600 saved credential
    • two-account switching kept Secret Service, live, and runtime credentials synchronized in both directions
    • simulated running agy correctly blocked switching and preserved the active keyring credential

    CI passed on Python 3.10 and 3.13, distribution build/install passed, and Pages deployment succeeded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions