Repository navigation
Conversation
A global-region (or other custom-environment) Kimi Code 2.x login keeps its sign-in under a scoped oauth key recorded in config.toml, landed as credentials/kimi-code-env-<hash>.json; the default kimi-code.json slot is only written for a mainland-China login. The collector looked at the default slot alone, so such machines showed "Waiting for auth" and the panel hid the Kimi section despite valid credentials on disk. The default slot stays the fast path; when it is missing, the collector now reads the provider oauth key from config.toml and takes the file it names, falling back to a lone credentials/kimi-code-env-*.json when no key is recorded. A refreshed token is written back to the same scoped file the CLI reads. Fixes omacom#19225
[Medium impact] The PR affects the Kimi usage collector’s sign-in and quota workflow. Fix the fallback before merging so a missing configured credential cannot select another account. FindingsSummaryAdds scoped Kimi Code credential lookup while keeping the default file first.
AnPod explicitly describes default-file precedence as intentional.
|
| env_files = sorted(CREDENTIALS_DIR.glob("kimi-code-env-*.json")) | ||
| if len(env_files) == 1: | ||
| return env_files[0] |
There was a problem hiding this comment.
Another account's quota appears
If the OAuth key recorded in config.toml points to a missing file while another environment's scoped credential remains, credentials_path() selects that remaining file. The panel then probes the other account instead of waiting for the configured sign-in. Only use the lone-file fallback when no key is recorded, as the PR description promises.
| (cred / "kimi-code.json").unlink() | ||
| expect("with the default gone, the key recorded in config.toml disambiguates", | ||
| load_collector("kimi").credentials_path().name, "kimi-code-env-aaa111.json") |
There was a problem hiding this comment.
The configured-key tests each create only one scoped file. After kimi-code.json is removed, scoped_precedence() therefore passes through the lone-file fallback even if all config parsing is deleted. Add a second scoped credential with a different token and check that the recorded key selects the right one. This would catch broken config lookup when several scoped credentials exist.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Reviewed The source also confirms the two gaps Greptile identified: a configured key whose file is missing can fall through to another scoped credential, and the configured-key fixtures contain only one scoped file, so they do not distinguish config lookup from the lone-file fallback. These were checked by reading, not reproduced here. Codex High reviewed this item, with a second opinion from Opus 5.5 High and muse-wonder via pi, thinking high. Both favored continuing with the older #15646; that agrees with my comparison, and independence is not guaranteed. No worker tests ran for this head because the competing-fix comparison comes before verification. Nothing was pushed. This PR additionally handles a lone scoped file when no key is recorded. I have handed that case and the ambiguity coverage to #15646's queue session for verification there, including the reviewers' concern that a missing configured credential must not select another account and that a file alone does not identify its regional endpoints. Any incorporated code must credit @AnPod. Leaving this open for the maintainer to choose between the competing fixes. The |
Adapt the credential-selection cases from omacom#19241 without inferring an active account or regional endpoints from orphaned files. The configured slot must win over leftover sign-ins; a missing slot or absent configuration must not borrow another scoped credential. Co-Authored-By: AnPod <drejc83@gmail.com> Co-Authored-By: GPT-6 (Codex) <noreply@openai.com> Co-Authored-By: Opus 5.5 High <noreply@anthropic.com> Co-Authored-By: muse-wonder High <noreply@meta.com>
Problem
On a machine signed in to Kimi Code 2.x through the global region (oauth host
auth.kimi.ai), the agents panel shows no Kimi section andomarchy-agent-usage-kimireports "Waiting for auth" despite valid credentials on disk (#19225).Kimi Code 2.x persists a global-region (or other custom-environment) login under a scoped oauth key —
credentials/kimi-code-env-<hash>.json, with the active key recorded in~/.kimi-code/config.toml:The collector resolved only the default slot
credentials/kimi-code.json, which is written for a mainland-China login, so it found no sign-in,providerHasSubscription()inMain.qmlhid the section, and the quota was never probed.Fix
bin/omarchy-agent-usage-kimikeeps the default slot as the fast path, and when it is missing:config.toml(the managedkimi-codeprovider first) and usescredentials/<rest-of-key>.jsonfor akey = "oauth/..."value,credentials/kimi-code-env-*.jsonwhen exactly one exists and no key is recorded,A token refresh is written back to the same file the CLI reads (scoped file when that is the resolved sign-in), and the limits cache stays keyed by the resolved path, so another sign-in or service never shows this account's quota. No network surface, trust check, or panel logic changes.
Test
Four new cases in
test/shell.d/agent-usage-kimi-regression-test.sh, run against the real TLS stand-in for Kimi's services:config.tomlis read (red-before failed with exactly the issue's symptom:usageStatusText: "Waiting for auth", zero requests),config.toml,Full file passes (72 assertions);
agent-usage-kimi-stats-test.sh,kimi-agent-test.sh,agent-usage-kimchi-test.shandagent-usage-partition-test.shpass unchanged.Fixes #19225