Repository navigation
Description
What version of Kimi Code is running?
Kimi Code CLI 2.6.3, native source commit b0de2fb.
Which open platform/subscription were you using?
No real account or subscription. A local synthetic OAuth server implements refresh-token rotation and delays its response to expose the persistence interval. Native executable bytes and response handling are unchanged.
Which model were you using?
None. Web workspace/skill discovery and account usage only; no model prompt or paid request.
What platform is your computer?
Linux 6.12.93 x86_64, Node.js 24.19.0.
What issue are you seeing?
The default background model-catalog refresh can refresh expired OAuth credentials while an unrelated short-lived Web read runs. If Web exits after the OAuth server accepts and rotates the refresh token but before the response reaches local storage, disk retains the old refresh token. On the next normal usage read, native Kimi sends that old token, receives rejection, and writes its revoked tombstone with both access and refresh credentials empty. Logging in again is then required.
Three sequential controlled runs reproduced the entire chain, without concurrent readers:
- Native skills discovery triggers background refresh; the synthetic service accepts generation 0 and advances to generation 1.
- Skills discovery finishes; the host terminates the native Web process while the refresh response is delayed. Disk still contains generation 0.
- A subsequent ordinary account-usage read submits generation 0 when the service requires 1.
- The service rejects it; native Kimi clears both credential fields.
This is a process-lifetime problem, not evidence that the OAuth cross-process lock failed. It ends in the same revoked tombstone as #3186 (concurrent Windows refresh), but needs no concurrency. A preseeded local server.token excludes the separate first-Web-token race. No credential values or banners are included in the evidence.
What steps can reproduce the bug?
Reproduction, report and all selected outcomes:
https://github.com/botiverse/oar/tree/6d3410cc97a32c0118119964507075c96a832b41/experiments/kimi-readonly-refresh
From that checkout, install its dependencies and run:
pnpm tsx experiments/kimi-readonly-refresh/probe.ts /absolute/path/to/kimi /tmp/kimi-refresh.jsonThe unprotected path directly drives native kimi web, reads/registers a workspace, reads its skill catalog, unregisters the temporary workspace, and uses the former immediate process cleanup. The local OAuth fixture accepts only its current refresh generation, rotates on acceptance and delays the response by 600 ms. The test then reads native account usage and records credential-state booleans. Three rounds of each control are retained.
The protected path uses the actual OAR adapter with the two native background-refresh environment switches disabled. Sequential and concurrent controls each pass 3/3, with one explicit usage refresh and the current generation persisted. The native skill query must make zero provider requests, and user config bytes stay unchanged.
The terminal Ctrl+C path has not been separately measured. The observed trigger is host termination of the native Web process; the same persistence interval warrants checking ordinary native exit paths too. Controlled 3/3 results are not a production failure-rate estimate.
What is the expected behavior?
An unrelated read followed by normal process shutdown should not leave disk holding a refresh token that the server has already invalidated. In-flight background OAuth work needs an explicit shutdown lifetime, with enough opportunity to persist an accepted replacement or a documented remaining boundary. Clearing credentials after a stale-token rejection does not recover a replacement lost by the previous process.
Additional information
The model-catalog scheduler starts an un-awaited refresh by default and schedules a six-hour interval. Its dispose() clears the interval without joining an in-flight refresh:
https://github.com/MoonshotAI/kimi-code/blob/b0de2fbd2de04d87689225aafd3912e5d193b62d/packages/kap-server/src/services/modelCatalog/modelCatalogRefreshScheduler.ts
The OAuth manager saves the replacement after refresh returns. After 401/403 it waits 100 ms and re-reads storage for a peer's replacement; without one, it writes a revoked tombstone. Its comments explicitly account for refresh-token rotation:
https://github.com/MoonshotAI/kimi-code/blob/b0de2fbd2de04d87689225aafd3912e5d193b62d/packages/oauth/src/oauth-manager.ts
Our narrow workaround sets these only on read-only usage/skills child processes:
KIMI_CODE_MODEL_CATALOG_REFRESH_ON_START=0
KIMI_CODE_MODEL_CATALOG_REFRESH_INTERVAL_MS=0Caller environment and user configuration remain unchanged. Explicit /api/v1/oauth/usage refresh stays enabled, so this workaround does not protect an explicit refresh interrupted by a deadline, crash or termination. Session processes and native Web processes launched elsewhere are unaffected.
Additional controls with KIMI_DISABLE_OAUTH_LOCK=1 show no usage-side refresh or credential rewrite, but return access_token_expired; they cannot repair a token lost by an earlier unprotected skills read. This is not a recovery mechanism.
A separate measured follow-up requests authenticated native /api/v1/shutdown with a fresh signal and waits for real exit, while returning the caller's timeout punctually. With a 600 ms synthetic refresh response, three cancellation controls preserved the replacement. With a four-second response, a two-second shutdown grace still expired and the replacement was lost. Exit code 0 alone did not establish persistence. A bounded host grace is therefore a mitigation, not a guarantee; the real service's token reuse/grace policy and a dedicated real test account remain unmeasured.
This AI-assisted report is based on inspected source and measured native traffic.
Contribution
No upstream pull request is being opened with this report.
Agent Cindy wrote this for @xxchan through Stamp (grant cgr_ac42b22a2ac64436db46020f9fd977e8)
Activity
xxchan commentedon Nov 18, 2026
Follow-up against the real Kimi service, using a dedicated account on Kimi Code CLI 2.6.3, Linux. No model requests were made, and no credential values were recorded.
We ran the unprotected path from the report three times: one skills read on an expired token, then one usage read straight after. None of the three rounds lost the login.
Rounds 2 and 3 can mean either of two things:
We cannot tell which from the client side. If the server has such a grace period, the synthetic reproduction above is stricter than production, and the loss there is a timing edge case rather than a likely failure. If it does not, the original chain still applies whenever the server accepts the first request.
Could you confirm whether the server accepts reuse of a just-rotated refresh token, and for how long? The process-lifetime gap in the scheduler (
dispose()not waiting for an in-flight refresh) is still there either way.Agent Cindy wrote this for @xxchan through Stamp (grant
cgr_ac42b22a2ac64436db46020f9fd977e8)chore: release v0.117.0 (#925)