bug(kimi): OAuth-managed auth is reported unknown or unauthorized
Bug
AO reports Kimi worker auth as unknown/unauthorized even when the user's Kimi CLI is authenticated through Kimi's normal OAuth-managed configuration.
Source: user report in AO worker session 2026-08-15
Analyzed against: 0f43574f20aab7d8f7a7c61142f94f9c87a214eb
Confidence: Medium-high
Observed locally
A fresh AO agent probe reports Kimi as installed but not authorized:
ao agent ls --refresh --json
...
{"id":"kimi","label":"Kimi","authStatus":"unauthorized"}
The Kimi binary resolves correctly:
/Users/chauhan/.kimi-code/bin/kimi
The user's Kimi config exists in both homes:
~/.kimi-code/config.toml~/.ao/data/kimi/config.toml
Both configs contain managed OAuth configuration (oauth.storage / oauth.key) but the api_key fields are empty. The user's ~/.kimi-code/credentials/kimi-code.json exists, but access_token and refresh_token are empty. The AO-managed Kimi home does not have ~/.ao/data/kimi/credentials/kimi-code.json.
Kimi also does not support AO's generic auth probe commands:
kimi auth status -> unknown command
kimi login status -> unknown command
kimi providers list -> unknown command
Reproduction
- Authenticate Kimi via its normal OAuth/login flow so the CLI can operate.
- Ensure Kimi's config uses managed OAuth storage with empty
api_keyvalues and no non-emptyaccess_token/refresh_tokenincredentials/kimi-code.json. - Start AO and refresh the agent catalog.
- Inspect Kimi in
ao agent ls --refreshor the worker/reviewer agent picker.
Expected
AO should not report Kimi auth as unknown/unauthorized when Kimi's own OAuth-backed configuration can successfully authenticate the CLI.
Actual
AO reports Kimi as auth unknown/unauthorized because the local detector only recognizes env/API key fields, non-empty JSON token fields, or generic CLI auth/status output.
Root Cause
Kimi auth detection currently checks only these sources:
- env vars:
KIMI_API_KEY,KIMI_CODE_API_KEY,MOONSHOT_API_KEY - non-empty
api_key = ...values inconfig.toml - non-empty
access_tokenorrefresh_tokenincredentials/kimi-code.json - generic CLI auth/status commands via
authprobe.CLIStatus
Relevant files:
backend/internal/adapters/agent/kimi/auth.gokimiLocalAuthStatuschecks env/config/credentials, then falls back to generic CLI probes.kimiConfigAuthStatustreats emptyapi_keyentries as unauthorized.kimiCredentialsAuthStatustreats empty token JSON as unauthorized.
backend/internal/adapters/agent/kimi/kimi.go- AO worker sessions use isolated
KIMI_CODE_HOME=~/.ao/data/kimi.
- AO worker sessions use isolated
backend/internal/adapters/agent/kimi/hooks.goseedKimiCredentialsonly copies credentials whenkimiCredentialsAuthStatusreports authorized, so OAuth-managed/empty-token credentials are skipped.
This misses Kimi installations that authenticate via managed OAuth storage referenced by config.toml, likely through an external credential store/keychain.
Suggested Fix Direction
Investigate Kimi's current OAuth storage format and add an auth probe path that can recognize a valid OAuth-managed Kimi login without requiring plaintext API keys or non-empty token JSON. Possible options:
- Use a Kimi-supported non-interactive status/config command if one exists.
- Inspect the referenced OAuth storage/keychain entry in a safe, local-only way.
- Treat known managed OAuth config as
unknownrather thanunauthorizedif validity cannot be verified, so UI messaging is less misleading. - Ensure AO-managed
KIMI_CODE_HOMEcan see/copy whatever credential material Kimi requires, without exposing secrets.
Impact
- Kimi appears unauthenticated in AO agent status/pickers despite working outside AO.
- Worker/reviewer preflight warnings can be misleading.
- AO-managed Kimi homes may not receive required OAuth credential material during hook setup.
i checked this against current main and found a real but narrower gap than the original report. file-backed oauth detection and oauth config seeding are already present, but external or legacy keyring references are still not recognized or seeded. pr #5251 partially addresses that path, but it is still open with requested changes and its keyring detection does not yet feed the config-seeding path.
the original repro also needs one detail verified: it shows an existing empty credentials file but does not state storage = keyring; kimi treats an existing empty file as authoritative, so unknown may be correct for that exact state. please confirm the kimi version and oauth storage before treating this as fully actionable. if keyring-only auth is confirmed, finish #5251 rather than opening a duplicate pr.
@nikhilachale please look into this
already fixed and merged