Skip to content

fix(agent-core-v2): make managed OAuth login env-aware - #1634

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix/v2-login-env-aware-auth
Jul 13, 2026
Merged

fix(agent-core-v2): make managed OAuth login env-aware#1634
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix/v2-login-env-aware-auth

Conversation

@sailist

@sailist sailist commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

The v2 managed OAuth login ignored KIMI_CODE_BASE_URL / KIMI_CODE_OAUTH_HOST. Login always targeted the default environment's credential slot while the runtime read tokens env-aware (resolveKimiCodeRuntimeAuth). Against a non-default environment the token was written to one slot and read from another — "login succeeds but every call 401s".

What changed

  • startLogin now resolves the login environment via resolveKimiCodeLoginAuth (v1 managedAuth.login parity), so KIMI_CODE_BASE_URL / KIMI_CODE_OAUTH_HOST steer the credential slot the token is written to the same way they steer runtime token reads.
  • The provisioned provider entry records the login environment (baseUrl) and the resolved credential slot (oauth ref) explicitly instead of trusting a stale configured ref; the configured ref is reused only when it matches the login environment.
  • logout deletes the token from the runtime (env-aware) slot, so an env-scoped login's token is actually removed.
  • Tests cover env-override login, configured-ref match/mismatch, and runtime-slot consistency after an env-scoped login (the original 401 scenario).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Resolve the login environment via resolveKimiCodeLoginAuth so
KIMI_CODE_BASE_URL / KIMI_CODE_OAUTH_HOST steer the credential slot
login writes to the same way they steer runtime token reads — fixes
"login succeeds but every call 401s" against non-default environments.
The provisioned provider entry now records the login environment and
credential slot explicitly, and logout deletes from the runtime
(env-aware) slot.
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 112334d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/agent-core-v2 Patch
@moonshot-ai/kap-server Patch
@moonshot-ai/klient Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@112334d
npx https://pkg.pr.new/@moonshot-ai/kimi-code@112334d

commit: 112334d

@sailist
sailist merged commit 96b8328 into MoonshotAI:main Jul 13, 2026
15 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 112334d961

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

readonly provider: string;
readonly controller: AbortController;
readonly oauthRef: OAuthRef | undefined;
/** Base URL of the environment the login targeted (env-aware); drives the provisioned provider entry. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move auth comments to the header

packages/agent-core-v2/AGENTS.md requires comments in this package to live only in the top-of-file /** */ block and never beside fields, methods, or statements. This new field comment starts a set of added inline explanatory comments in authService.ts; please fold any necessary rationale into the module header or make the code self-explanatory so the file stays within the local convention.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
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