Skip to content

fix(cli): report foreground web shutdown failures - #5434

Merged
RealKai42 merged 1 commit into
mainfrom
codex/issue-002-web-shutdown
Nov 25, 2026
Merged

RealKai42 merged 1 commit into
mainfrom
codex/issue-002-web-shutdown

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Screenshots / Recordings

实际前台子进程的关闭结果
场景 修复前 修复后
正常关闭 退出码 0,stderr 为空 退出码 0,stderr 为空
KAP 清理实例注册失败 退出码 0,stderr 为空 退出码 1,stderr 包含 Kimi web: server shutdown failed: 及系统错误
关闭钩子抛错 退出码 0,stderr 为空 退出码 1,stderr 包含 Kimi web: foreground shutdown hook failed: 及错误原因

Requirement or Bug

前台 kimi web 的服务关闭或关闭钩子抛错时,默认日志级别会隐藏错误,命令仍返回成功。调用方需要用退出码区分正常关闭和清理失败。回归记录 002。

Bug Reproduction Steps

  1. 使用隔离的数据目录启动 kimi web --port 0 --no-open,等待前台横幅打印监听地址。
  2. 在隔离目录内把服务实例注册文件替换成同名目录,令真正的注册清理无法删除它。
  3. 给子进程发送 SIGINT。基线退出码为 0,stderr 为空。

Root Cause

前台关闭路径捕获钩子和服务错误后写服务日志,并固定调用 process.exit(0)。默认级别为 silent。服务关闭与遥测刷新还在同一个 try 中,服务关闭抛错会跳过刷新。

Code Changes

flowchart LR
    Signal[前台关闭请求] --> Hook[关闭钩子]
    Hook --> Close[KAP 服务关闭]
    Close --> Telemetry[尽力刷新遥测]
    Telemetry --> Result{清理结果}
    Result -->|全部成功| OK[退出 0]
    Result -->|钩子或服务抛错| Error[写入并刷新 stderr]
    Error --> Failed[退出 1]
Loading

在 startServerForeground 已有的关闭流程里,按原有顺序执行关闭钩子和 KAP 服务关闭,每个阶段独立记录错误。随后调用现有遥测关闭逻辑。有清理错误时,用 CLI 已有的标准流刷新工具把失败阶段和原因送出,再退出。

Behavior Changes and Affected Users

行为 改动前 改动后 受影响人群
关闭钩子或 KAP 服务关闭抛错 默认日志静默,退出码始终为 0 stderr 报告失败,退出码为 1 前台 kimi web 与 --remote-control 用户,读取 --json 输出并检查退出码的调用方,TUI /web 和 /remote-control 启动的前台服务
服务关闭抛错后刷新遥测 跳过这一步 继续尝试刷新,再结束进程 启用遥测且遇到服务关闭异常的前台用户

Verification

本地验证在以 e105ef0d2 为基线的 macOS 工作树中进行,用系统信号驱动真实前台子进程。基线的服务清理和钩子失败用例都返回 0,stderr 为空。修复后覆盖正常关闭、服务清理失败、钩子失败后继续删除服务注册,以及诊断与标准输出分离。

  • 用正式 CLI 构建产物跑 8 轮双子进程测试,共 16 次。每轮同时运行正常与失败场景,交替发送 SIGINT 和 SIGTERM,全部通过。
  • Web CLI、TUI Web 命令和标准流刷新相关的 5 个测试文件共 101 项通过。CLI 类型检查、pnpm lint、CLI 构建与包产物 smoke、双语文档构建通过。
  • 本地系统信号核对使用 macOS。Windows 回归夹具在服务就绪后通过子进程输入触发相同信号处理函数。

Checklist

  • 阅读贡献指南,在原实现上通过真实子进程复现失败并确认正常关闭对照。
  • 覆盖正常退出、服务关闭错误、钩子错误后继续清理、诊断流和退出码。
  • 同步中英文 CLI 文档和 patch changeset。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T13:48:56.307854Z 032cdba PR opened
🔒 Security Review ✅ Completed 2026-11-25T13:50:51.200878Z 032cdba PR opened
ℹ️ 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 Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 032cdba

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 Nov 25, 2026

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

commit: 032cdba

@RealKai42
RealKai42 merged commit e3b1904 into main Nov 25, 2026
22 checks passed
@RealKai42
RealKai42 deleted the codex/issue-002-web-shutdown branch November 25, 2026 13:52
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
…ndency

Expose TestProcess and its options from the fixtures entry so CLI suites can
spawn the product entrypoint.

MoonshotAI#5434 stays in_progress: its regression test needs the signal-import
support the testkit wave will add, and the fork's localized shutdown path
needs a message/exit reconciliation with the upstream body.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
MoonshotAI#5359 and MoonshotAI#5404 need the fork's loop/ACP shapes (LiveTurn state machine,
session extensions), MoonshotAI#5434 depends on testkit signal imports, and MoonshotAI#5332
needs a merged SessionAction table. Each is in_progress with the precise
remaining work rather than a forced apply.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
Port the upstream regression suite onto the fork's localized shutdown
path: the none/server/hook cases assert the exit code and the reported
failing step, and TestProcess now materializes data-URL preloads to files
so the Windows signal preload reaches the child (Bun ignores data: with
--import).

Verified: foreground-shutdown 3 pass, apps/kimi-code and testkit
typecheck clean.
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