Skip to content

fix(agent-core-v2): close idle MCP OAuth callback connections - #4431

Merged
7Sageer merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/mcp-oauth-callback-close
Oct 26, 2026
Merged

7Sageer merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/mcp-oauth-callback-close

Conversation

@pvzheroes125

Copy link
Copy Markdown
Contributor

Requirement or Bug

MCP 浏览器授权已完成后,客户端仍可能等待本地回调监听器关闭,迟迟不能结束授权流程。

Bug Reproduction Steps

  1. 启动 OAuth 回调监听器,额外建立一条不发送 HTTP 请求的 TCP 连接,模拟浏览器预连接。
  2. 通过另一条连接向 /callback?code=example&state=example 发起请求。
  3. 回调结果已返回,但等待监听器关闭仍不结束;关闭额外 TCP 连接后立即结束。普通 keep-alive 回调连接也可能延迟收尾。

Root Cause

授权完成流程会等待回调监听器关闭。server.close() 不会主动销毁尚未形成 HTTP 请求的预连接;关闭开始时仍在发送响应的 keep-alive 连接也可能延迟退出。本次在一次性监听器自身修复连接清理,保留授权结果 HTML 的正常发送。

Code Changes

 回调监听器
+ 记录尚未形成 HTTP 请求的 TCP 连接
+ 请求到达后从该集合移除
 GET /callback 的终止响应
+ Connection: close,完整发送 HTML 后关闭连接
 关闭监听器
   server.close()
+ 销毁尚未使用的 TCP 连接

Behavior Changes and Affected Users

行为 修改前 修改后 受影响人群 退路
回调监听器结束时的预连接 可能拖住授权完成、取消或超时清理 关闭监听后立即清理未形成 HTTP 请求的连接 使用 Core MCP 浏览器 OAuth 的 CLI、desktop/web 和 SDK 调用方 无新增开关;监听器结束后这些连接已无用途
GET /callback 的成功及错误响应 可保持 keep-alive 完整发送 HTML 后关闭该连接 同上 一次性回调不再保留 keep-alive;响应内容及状态码不变

404 路径、OAuth state 校验、凭证持久化和公开接口保持不变。已形成请求的其他活动连接仍使用原有 drain 行为,本次不增加强制终止机制。

验证:

  • OAuth 相关三份测试文件:63/63 通过;覆盖空闲 TCP 下成功/错误页面完整返回、显式关闭、取消及超时。
  • Core typecheck、改动文件 type-aware lint、comment-free 检查及 git diff --check 通过。
  • Electron Node 24.21.0 中用真实空闲 TCP + 默认 fetch 复测,关闭约 12ms,成功 HTML 完整返回。未进行跨平台浏览器端到端验收。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve). 无关联 issue,复现步骤见上。
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-26T11:01:53.777012Z
We couldn’t complete this review. Comment @codex review to try again.
0e43a79 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0e43a79

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

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code 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 Oct 26, 2026

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

commit: 0e43a79

@pvzheroes125

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@pvzheroes125

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@pvzheroes125

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@7Sageer
7Sageer merged commit 98c1cfb into MoonshotAI:main Oct 26, 2026
17 checks passed
This was referenced Oct 27, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
MoonshotAI#4410 MoonshotAI#4413 MoonshotAI#4431 MoonshotAI#4450 MoonshotAI#4451 MoonshotAI#4485 MoonshotAI#4524 were each implemented earlier —
the compaction prefix suite, the media-recovery case, the OAuth callback
socket drain, the split delivering-work section, the compaction wording,
the reasoning-key order and the 10-step todo reminder are all in the tree
and pinned by their own tests. Each row now carries that probe.

Only MoonshotAI#4410 needed care: upstream patched paths that this fork renamed
(`human/llm/builtin/protocol` versus `human/llm/requester/bases`), so the
matching was done on the behaviour — stripDynamicToolContext is gone and
extractEventUsage already reads usage only on terminal response events.

Ledger: closed 22 -> 28, remaining 71.
unsupportedpastels pushed a commit to NousResearch/hermes-agent that referenced this pull request Nov 13, 2026
…le browser preconnect

Widen the callback-handler read timeout from the CLI MCP waiter to the two
sibling single-threaded loopback listeners with the same shape: the shared
provider-login listener (Codex browser login, OpenRouter, PKCE plugins) and
the Desktop/dashboard connector receiver. An idle speculative socket accepted
ahead of the redirect parked each serve loop until the browser dropped it.

Port from MoonshotAI/kimi-code#4431 (close idle MCP OAuth callback connections).
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.

2 participants