Skip to content

Reuse Pi credentials for Kimi usage collection - #16431

Open
Pillumz wants to merge 3 commits into
omacom:quattrofrom
Pillumz:herd/kimi-quota-f2f4f6f7
Open

Pillumz wants to merge 3 commits into
omacom:quattrofrom
Pillumz:herd/kimi-quota-f2f4f6f7

Conversation

@Pillumz

@Pillumz Pillumz commented Oct 23, 2026 •

Copy link
Copy Markdown

Problem

A Kimi subscription signed in through Pi's /login kimi-coding has working credentials, but Omarchy's Kimi collector only looks for an environment key or Kimi CLI login. The result is missing quotas in the existing agents panel.

This PR only adds the missing credential source. Kimi's five-hour and monthly quota parsing already exists; no panel redesign, plan-label override, window IDs, duration fields, or percentage-formatting changes are needed.

Change

  • Keep KIMI_API_KEY and the selected Kimi CLI token ahead of Pi. A rejected or expired higher-priority credential does not silently switch accounts. An explicit KIMI_CODE_HOME never borrows Pi's account.
  • Before invoking Pi, check for a stored kimi-coding entry in auth.json under PI_CODING_AGENT_DIR (default ~/.pi/agent). Missing, unrelated or malformed stores do not invoke Omarchy's lazy Pi launcher, so an unused provider's background refresh does not install Pi.
  • Ask pi auth check --provider kimi-coding --json --credentials to resolve the OAuth/API-key credential. Pi still owns refresh, locking and persistence; Omarchy does not copy or rewrite its credentials.
  • Bound lookup to 15 seconds, including API-key-command descendants holding stdout open. Discard diagnostics; keep the resolved credential in memory, never command arguments or usage records. Give Pi-specific login help after quota rejection. A local lookup timeout does not request a service retry.

Requires a Pi version supporting auth check (verified with Pi 1.4.0).

Relation to other work

  • Supersedes the Pi-credential portion of Improve Kimi plan quota reporting #16437. That broader proposal is being withdrawn in favor of this focused fix; its display/config additions are not prerequisites.
  • Add every coding agent and provider to the agents panel and the default agent #14040 remains the direction for collector consolidation. Its current head counts Pi's Kimi sessions but still lacks Pi credential resolution. This PR stays based on quattro, without importing the overhaul. A separate local port onto 8d957f37 was verified: include Pi in has_credential(), use the new missing/refused status contract, and carry Pi-specific help through the quota request. Its shared scanning, records and cache remain intact. The branches require adaptation, not a blind merge.
  • Find Kimi credentials for global (kimi.ai) sign-ins #15646 is complementary: it discovers global Kimi CLI credential slots. It must retain precedence when present. When composing the changes, the usage endpoint must follow the selected credential source: Pi must not automatically inherit a former CLI login's regional/custom endpoint from config.toml. The interaction with Find Kimi credentials for global (kimi.ai) sign-ins #15646 was reviewed; a combined branch has not been live-tested here.

Verification

On this PR, via herd-test:

  • agent-usage-kimi-test.sh
  • agent-usage-kimi-regression-test.sh
  • agent-usage-update-test.sh
  • agents-panel-test.sh
  • git diff --check

Safety coverage exercises the real collector/process/HTTP boundary: unsigned refresh with a lazy-launcher stand-in, explicit account isolation, default and overridden Pi directories, credential precedence and rejection, redaction, malformed CLI output, and timeout cleanup. The unsigned-refresh assertion fails against the previous PR head (e66a5d66), which starts Pi.

Live Pi OAuth collection returned fresh five-hour, monthly-total and monthly-code readings with the existing record shape. The stock panel was inspected in a disposable Omarchy VM using only the credential-free reading: Session and Monthly meters render, and the Monthly tooltip includes the code allowance. Its Panel.qml is byte-identical to this branch. The existing local Pi footer parser/formatter also accepts all three windows and suppresses stale data; no footer change was needed.

For the separate #14040 port, its Kimi regression/limits-contract and local-stats suites passed, including Pi-only sign-in before any local history and the shared stale/refused behavior. A live Pi-only run returned fresh quota alongside local usage. These are checks of an adapted port, not claims about unmodified #14040. The initial test invocation hit the host's untrusted mise configuration; the suites ran successfully with system tools on an isolated PATH, without changing that configuration.

No full shell-suite pass is claimed; this is confined to one collector. No runtime deployment was changed.

AI provenance

Initial implementation: OpenAI GPT-6.1 Sol. Current revision, upstream compatibility work and live/visual verification: OpenAI GPT-6 Astra. Independently reviewed by GPT-6.1 Sol for credential precedence/isolation, lazy-launcher behavior, secret handling, process cleanup, Pi's CLI contract and #14040/#15646 interactions. Its default-home precedence coverage gap was addressed. No blocking issue was found in the current fix; the cross-PR adaptation requirements above remain explicit.

@Pillumz

Pillumz commented Oct 23, 2026

Copy link
Copy Markdown
Author

Coordinator verification: GPT-6 Astra reviewed the credential fallback and secret-handling boundary, then ran the changed collector against the real Pi OAuth login. It returned ready=true with fresh 5-hour, monthly-total and monthly-code windows. Runtime deployment has not been changed. Pi remains responsible for credential refresh and locking.

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous non-blocking cleanup issue still open.

Findings

  1. P2 Cleanup can wait forever ▶

Summary

Adds Pi credentials as a fallback for Kimi usage collection.

  • Kimi usage collection can use Pi's kimi-coding sign-in as a fallback.

Reviews (2) · Last reviewed commit: "Only borrow an existing Pi Kimi sign-in" · Reviewed by Greptile

os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.communicate()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cleanup can wait forever

The second process.communicate() has no timeout. If a Pi API-key command starts a child in a separate process group while leaving stdout open, killpg cannot close that child's pipe. The collector and the usage update can then wait forever after the 15-second deadline. Bound the cleanup wait too, and close the captured pipe if it does not finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant