Repository navigation
Conversation
…runtime The Kimi usage fetcher only read OAuth credentials from the host's ~/.kimi-code, so on Windows hosts where the Kimi CLI runs inside WSL the status bar was stuck on "Run Kimi to refresh": the CLI rotates the WSL-side credentials file, leaving the host-side token permanently expired. Mirror the Codex pattern: the service resolves the Kimi home for the configured local-account runtime target (host keeps KIMI_CODE_HOME / ~/.kimi-code; a WSL target reads the distro home over its \\wsl$ UNC path via the cached echo $HOME probe) and passes it to the fetcher, which reads the credentials file with the shared UNC-read dedup/ serialization used by the Codex backend auth read. Reading stays read-only; an unresolvable WSL home surfaces an explicit error instead of silently falling back to the host file.
📝 WalkthroughWalkthroughThe change adds Kimi runtime-home resolution for host and WSL targets. Credential loading now uses asynchronous, cached filesystem reads with timeout and structured error handling. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d964a1b6-77f6-4ab3-91f1-496c0ae09342
📒 Files selected for processing (7)
src/main/index.tssrc/main/rate-limits/kimi-fetcher.test.tssrc/main/rate-limits/kimi-fetcher.tssrc/main/rate-limits/kimi-home-path.test.tssrc/main/rate-limits/kimi-home-path.tssrc/main/rate-limits/service.test.tssrc/main/rate-limits/service.ts
|
Thanks @cengiz-io — I independently reproduced #12370 and built a fix blind to this PR, then cross-referenced. Your Merged result is at #12475 — it keeps your read mechanism, adds a Happy to close mine if you'd rather land it here — your diagnosis was correct and the credit is yours. |
|
Thanks @nwparker — #12475 looks great. The async Let's land yours — closing this in favor of #12475. Glad the read path and test vectors were useful. Thanks for the quick turnaround and the kind words. |
… homes Adopted from @cengiz-io's #12372: read credentials through createAuthFilesystemOperation (async, per-path dedup, AbortSignal bound) so a stopped distro degrades to an error instead of parking Electron main on a UNC read. ENOTDIR joins ENOENT as "not signed in" to keep existsSync parity, and the WSL runtime target is now probed with the async wsl.exe helpers. Co-authored-by: Orca <[email protected]>
… runtime (#12475) * fix(rate-limits): read Kimi usage credentials from the configured WSL runtime Kimi's usage fetch always read the Windows host's ~/.kimi-code, so a Kimi CLI running inside WSL rotated only the WSL-side token and the status bar was stuck on 'Run Kimi to refresh'. Resolve the Kimi home from the local-account runtime target (mirroring Codex's getDefaultWslDistro()/getWslHome() UNC pattern), pinned to host off Windows, and keep KIMI_CODE_HOME host-only. Fixes #12370 Co-authored-by: Orca <[email protected]> * fix(rate-limits): bound and offload the Kimi credentials read for WSL homes Adopted from @cengiz-io's #12372: read credentials through createAuthFilesystemOperation (async, per-path dedup, AbortSignal bound) so a stopped distro degrades to an error instead of parking Electron main on a UNC read. ENOTDIR joins ENOENT as "not signed in" to keep existsSync parity, and the WSL runtime target is now probed with the async wsl.exe helpers. Co-authored-by: Orca <[email protected]> * test(rate-limits): build Kimi credential-path expectations with path.join The host-home assertions hardcoded POSIX separators, so they only passed on a POSIX runner — on a Windows dev machine `join` emits backslashes and all four cases failed (three assertion mismatches plus a WSL-suite fixture whose map key never matched the path the fetcher read). --------- Co-authored-by: Orca <[email protected]> Co-authored-by: OrcaWin <[email protected]>
|
thanks for reporting. looking into it |
… runtime (stablyai#12475) * fix(rate-limits): read Kimi usage credentials from the configured WSL runtime Kimi's usage fetch always read the Windows host's ~/.kimi-code, so a Kimi CLI running inside WSL rotated only the WSL-side token and the status bar was stuck on 'Run Kimi to refresh'. Resolve the Kimi home from the local-account runtime target (mirroring Codex's getDefaultWslDistro()/getWslHome() UNC pattern), pinned to host off Windows, and keep KIMI_CODE_HOME host-only. Fixes stablyai#12370 Co-authored-by: Orca <[email protected]> * fix(rate-limits): bound and offload the Kimi credentials read for WSL homes Adopted from @cengiz-io's stablyai#12372: read credentials through createAuthFilesystemOperation (async, per-path dedup, AbortSignal bound) so a stopped distro degrades to an error instead of parking Electron main on a UNC read. ENOTDIR joins ENOENT as "not signed in" to keep existsSync parity, and the WSL runtime target is now probed with the async wsl.exe helpers. Co-authored-by: Orca <[email protected]> * test(rate-limits): build Kimi credential-path expectations with path.join The host-home assertions hardcoded POSIX separators, so they only passed on a POSIX runner — on a Windows dev machine `join` emits backslashes and all four cases failed (three assertion mismatches plus a WSL-suite fixture whose map key never matched the path the fetcher read). --------- Co-authored-by: Orca <[email protected]> Co-authored-by: OrcaWin <[email protected]>
Summary
Fixes #12370.
On Windows hosts where Kimi Code runs inside WSL, the status bar permanently showed "Run Kimi to refresh":
fetchKimiRateLimits()read OAuth credentials only from the host's~/.kimi-code/credentials/kimi-code.json, while the Kimi CLI inside WSL rotates the WSL-side copy every 15 minutes — so the host copy is always expired (delegated-refresh-required).The Kimi fetcher now resolves its credentials home from the configured local-account runtime target, mirroring the existing Codex pattern:
kimi-home-path.ts(new):resolveKimiHomePath(settings)— host policy keeps the fetcher'sKIMI_CODE_HOME ?? ~/.kimi-codedefault; a WSL policy resolves the distro's home via the existing cachedgetDefaultWslDistro()/getWslHome(distro)probe and reads it over its\\wsl.localhost\<distro>UNC path. Off Windows the target pins to host, matchinggetInitialCodexRateLimitTarget.kimi-fetcher.ts: accepts{ kimiHomePath? }; the credentials read goes throughcreateAuthFilesystemOperationwith per-path in-flight dedup and a 10s bound (same UNC-read pattern as codex-fetcher's backend auth read), so a disconnected distro degrades to an error instead of hanging the poll. UNC paths are joined withpathWin32. Expired-token copy now says "run kimi inside WSL distro <distro>" for WSL reads.service.ts/index.ts: asetKimiHomePathResolverclosure re-resolves the target from live settings on every poll (Kimi has no account switcher, so nokimiFetchTargetstate tracking like Codex). An unresolvable WSL home yields an explicitWSL Kimi home unavailable for \<distro\>error instead of silently falling back to the stale host file — mirroringgetMissingWslCodexHomeResult.Failure semantics and the read-only guarantee are unchanged: Orca never refreshes or rewrites the credentials file; missing file → "Not signed in to Kimi Code", expired token →
delegated-refresh-required.Screenshots
No visual change. (With the fix, the Kimi status-bar usage populates on WSL-runtime hosts instead of showing "Run Kimi to refresh"; no renderer code was touched.)
Testing
pnpm lint— not run in full;oxlinton all 7 changed files: 0 warnings/errors, pluscheck-changed-code-quality.mjs(0 new findings) andcheck-max-lines-ratchet.mjs(OK)pnpm typecheck—typecheck:nodeclean (change is main-process only)pnpm test— scoped run:vitest run src/main/rate-limits→ 415/415 passed (30 files), including 95 tests in the 3 touched/added test filespnpm build— not run locallyNew/updated tests cover: host default unchanged,
KIMI_CODE_HOMEhonored, WSL UNC path resolution, missing file in WSL home, expired token in WSL home (asserts WSL-distro copy +delegated-refresh-required), alllocalAccountRuntimepolicies incl. off-Windows pinning, unresolvable WSL home, and service wiring (resolver value passed through, missing-home short-circuit, no-resolver host default).AI Review Report
The diff was reviewed by an AI coding agent (Kimi Code) with focus on:
platform === 'win32'(both inresolveKimiHomePathand via the pin-to-host guard matchinggetInitialCodexRateLimitTarget); on macOS/Linux the resolution always returns the host default andgetCredentialsPathuses POSIXjoin.pathWin32.joinis used only whenparseWslUncPathconfirms a UNC path, so host behavior on every platform is byte-identical to before. No shortcuts, labels, shell behavior, or Electron platform APIs were touched; no newwsl.exeinvocations (file reads go over UNC, the distro/home probe reuses the existing cachedsrc/main/wsl.tshelpers).kimiHomePath ?? KIMI_CODE_HOME ?? ~/.kimi-code) verified to preserve the previous default exactly when no resolver option is passed (covered by tests); sync → async credentials read converted all call sites (single exported fetcher, single caller in service).Security Audit
/usagesHTTPS endpoint via electronnet.fetch, exactly as before.wsl.exe -- echo $HOMEprobe insrc/main/wsl.ts(local machine trust boundary, same as Codex usage), not from remote/IPC input. No path traversal surface: segments are fixed (credentials/kimi-code.json).AbortSignal.timeout(10s)so a stalled WSL distro cannot exhaust the fs thread pool or hang the fetch cycle; JSON parse of the credentials file is wrapped and reports only generic messages (no content leakage into errors).No follow-up required.
Notes
delegated-refresh-requiredpattern and reads auth host-only — it likely has the same WSL blind spot but was deliberately left out of scope; happy to follow up if maintainers want the same treatment there.