agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

bug(kimi): OAuth-managed auth is reported unknown or unauthorized

Open neversettle17-101 opened this issue 3 months ago • 3 comments

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

  1. Authenticate Kimi via its normal OAuth/login flow so the CLI can operate.
  2. Ensure Kimi's config uses managed OAuth storage with empty api_key values and no non-empty access_token/refresh_token in credentials/kimi-code.json.
  3. Start AO and refresh the agent catalog.
  4. Inspect Kimi in ao agent ls --refresh or 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 in config.toml
  • non-empty access_token or refresh_token in credentials/kimi-code.json
  • generic CLI auth/status commands via authprobe.CLIStatus

Relevant files:

  • backend/internal/adapters/agent/kimi/auth.go
    • kimiLocalAuthStatus checks env/config/credentials, then falls back to generic CLI probes.
    • kimiConfigAuthStatus treats empty api_key entries as unauthorized.
    • kimiCredentialsAuthStatus treats empty token JSON as unauthorized.
  • backend/internal/adapters/agent/kimi/kimi.go
    • AO worker sessions use isolated KIMI_CODE_HOME=~/.ao/data/kimi.
  • backend/internal/adapters/agent/kimi/hooks.go
    • seedKimiCredentials only copies credentials when kimiCredentialsAuthStatus reports 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 unknown rather than unauthorized if validity cannot be verified, so UI messaging is less misleading.
  • Ensure AO-managed KIMI_CODE_HOME can 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.

neversettle17-101 avatar Aug 15 '26 06:08 neversettle17-101

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.

codebanditssss avatar Sep 15 '26 15:09 codebanditssss

@nikhilachale please look into this

Rishet11 avatar Nov 03 '26 23:11 Rishet11

already fixed and merged

nikhilachale avatar Nov 22 '26 06:11 nikhilachale