Repository navigation
Description
What version of Kimi Code is running?
Kimi Code CLI 2.6.3. Also reproduced with 2.4.1; the inspected loadOrCreateServerToken and createTokenStore implementations are identical.
Which open platform/subscription were you using?
None. Isolated Kimi homes and a local synthetic OAuth/usage fixture; no real account, login, model request or paid provider.
Which model were you using?
None. Only kimi web and authenticated local Web reads.
What platform is your computer?
Linux x86_64, Node.js 24.19.0.
What issue are you seeing?
When two Web processes start against one Kimi home without a usable server.token, both can observe the missing file and generate different tokens. Atomic rename prevents a partial write but the second rename replaces the first token. The first process follows that file change, then rejects the bearer it printed in its own startup banner with HTTP 401.
A controlled 2.6.3 reproduction produced three HTTP 401 responses across three pairs (3/6 reads). Serializing only startup until readiness produced 0/6 failures. Both processes remained alive until their requests settled.
What steps can reproduce the bug?
The complete reproduction and selected results are available at:
https://github.com/botiverse/oar/tree/6d3410cc97a32c0118119964507075c96a832b41/experiments/kimi-web-startup
From that checkout, install its dependencies and run:
node --import tsx experiments/kimi-web-startup/probe.ts /absolute/path/to/kimi /tmp/kimi-startup.jsonThe first three pairs launch the native executable twice in the same isolated home. The checked-in schedule.ts Node preload holds the two missing-file observations until both are observed, delays the second rename until the first banner, and delivers the first usage read after replacement. It only changes filesystem/request timing; it does not change native source or replace tokens or responses. Each wait is bounded at 1.5 seconds. Following pairs repeat the schedule with startup coordination, then exercise ordinary cold and preseeded homes and the adapter.
This intentionally forces an interleaving; 3/6 is not an estimate of production frequency. Token values and private banners are omitted from the selected report.
What is the expected behavior?
Concurrent creation should select one persistent token, and each ready process's printed bearer should remain usable when another process merely starts against the same home.
Additional information
Native source inspected:
https://github.com/MoonshotAI/kimi-code/blob/b0de2fbd2de04d87689225aafd3912e5d193b62d/packages/kap-server/src/services/auth/persistentToken.ts
Creation reads/trims the file, generates a token if missing or empty, and atomically replaces it without cross-process coordination. The token store then follows file changes. This is independent of OAuth refresh-token locking.
The host workaround serializes missing-token startup within one process per resolved Kimi home, releases at readiness/exit/failure, and bypasses the gate for an existing nonempty token. It cannot coordinate independent hosts or arbitrary native launches. A native cross-process first-creation fix would remove this limitation.
Ordinary cold controls passed 12/12 reads with a median 1.877-second process-start separation; preseeded controls passed 12/12 with 4.5 ms separation. These timings include startup. The earlier macOS CI failure lacks token history and HTTP status, so this report does not claim to identify its exact cause. Windows/macOS race measurement remains outstanding.
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