Skip to content

feat(web): 添加 embedded session runtime 并默认启用 || feat(web): Add embedded session runtime and enable it by default#1650

Open
luzhongqiu wants to merge 6 commits intoMoonshotAI:mainfrom
luzhongqiu:codex/kimi-web-async
Open

feat(web): 添加 embedded session runtime 并默认启用 || feat(web): Add embedded session runtime and enable it by default#1650
luzhongqiu wants to merge 6 commits intoMoonshotAI:mainfrom
luzhongqiu:codex/kimi-web-async

Conversation

@luzhongqiu
Copy link
Copy Markdown
Contributor

@luzhongqiu luzhongqiu commented Mar 30, 2026

概要

  • kimi web 增加进程内的 embedded runtime,同时保留现有的 subprocess runtime
  • 将 Web runtime 的默认值切换为 embedded,并保留 KIMI_WEB_RUNTIME=process 作为回退开关
  • 保持当前 Web API、WebSocket 协议和前端行为不变
  • 将 session 工作目录从进程级 cwd 改为 session-local kaos 状态,避免 embedded 模式下的多 session 串扰

背景

#1641 讨论了 kimi web 是否还需要维持“每个 session 一个 worker 子进程”的模式。由于底层 CLI 已经可以作为 Python async 代码在进程内运行,因此这个 PR 尝试以最小改动验证 embedded 方案是否可行。

这次改动的目标是:

  • 不改现有 API 和前端契约
  • 在现有 subprocess 实现旁边新增 embedded 实现
  • 通过 runtime 选择开关完成切换,而不是重写整个 Web 层

改动内容

  • 新增 EmbeddedSessionProcessEmbeddedWireWorker,用于进程内执行 session
  • 保留原有 SessionProcess 作为 subprocess 实现,并在 KimiCLIRunner 中按配置选择 runtime
  • 复用现有 wire 协议和 websocket 广播链路,前端无需迁移
  • kimi web 的默认 runtime 切换为 embedded
  • 新增 ScopedLocalKaos,将 cwd 从进程级状态改为 session-local 状态
  • 保持 ACP 的相对路径行为:ACP session 使用 session-scoped kaos fallback,而不是依赖全局 chdir

兼容性

这次改动有意保持现有 Web 接口契约不变:

  • 不修改前端
  • 不修改 web/api/* 路由
  • 不修改 WebSocket 协议

如果需要回退到原有子进程模式,仍然可以通过:

KIMI_WEB_RUNTIME=process kimi web

测试

  • uv run ruff check src/kimi_cli/web/app.py src/kimi_cli/web/runner/process.py src/kimi_cli/web/runner/embedded_process.py src/kimi_cli/web/runner/embedded_worker.py tests/web/test_runner.py
  • uv run pytest tests/web/test_runner.py tests/vis/test_app.py
  • uv run pytest packages/kaos/tests/test_local_kaos.py
  • uv run pytest tests/acp/test_kaos.py tests/acp/test_session_notifications.py tests/acp/test_protocol_v1.py
  • uv run pyright packages/kaos/src packages/kaos/tests src/kimi_cli/acp/server.py tests/acp/test_kaos.py

Refs #1641


Summary

  • Add an in-process embedded runtime for kimi web while retaining the existing subprocess runtime
  • Switch the default value of Web runtime to embedded and keep KIMI_WEB_RUNTIME=process as fallback switch
  • Keep current Web API, WebSocket protocol and front-end behavior unchanged
  • Change the session working directory from process-level cwd to session-local kaos state to avoid multi-session crosstalk in embedded mode

Background

#1641 discussed whether kimi web still needs to maintain the "one worker child process per session" mode. Since the underlying CLI can already run in-process as Python async code, this PR attempts to verify whether the embedded solution is feasible with minimal changes.

The goals of this change are:

  • No changes to existing API and front-end contracts
  • Add embedded implementation next to existing subprocess implementation
  • Switching is done via a runtime selector instead of rewriting the entire web layer

Change content

  • Added EmbeddedSessionProcess and EmbeddedWireWorker for in-process session execution
  • Retain the original SessionProcess as subprocess implementation, and select the runtime according to configuration in KimiCLIRunner
  • Reuse existing wire protocol and websocket broadcast link, no need to migrate the front end
  • Switch the default runtime of kimi web to embedded
  • Added ScopedLocalKaos to change cwd from process-level state to session-local state
  • Maintain ACP's relative path behavior: ACP sessions use session-scoped kaos fallback instead of relying on global chdir

Compatibility

This change intentionally leaves the existing web interface contract unchanged:

  • No modifications to the frontend
  • Do not modify web/api/* routes
  • Does not modify the WebSocket protocol

If you need to return to the original sub-process mode, you can still pass:

KIMI_WEB_RUNTIME=process kimi web

Test

  • uv run ruff check src/kimi_cli/web/app.py src/kimi_cli/web/runner/process.py src/kimi_cli/web/runner/embedded_process.py src/kimi_cli/web/runner/embedded_worker.py tests/web/test_runner.py
  • uv run pytest tests/web/test_runner.py tests/vis/test_app.py
  • uv run pytest packages/kaos/tests/test_local_kaos.py
  • uv run pytest tests/acp/test_kaos.py tests/acp/test_session_notifications.py tests/acp/test_protocol_v1.py
  • uv run pyright packages/kaos/src packages/kaos/tests src/kimi_cli/acp/server.py tests/acp/test_kaos.py

Refs #1641

@luzhongqiu luzhongqiu changed the title feat(web): add embedded runtime for kimi web feat(web): add embedded session runtime and make it default Mar 30, 2026
@luzhongqiu luzhongqiu changed the title feat(web): add embedded session runtime and make it default feat(web): 添加 embedded session runtime 并默认启用 Mar 30, 2026
@github-actions github-actions bot changed the title feat(web): 添加 embedded session runtime 并默认启用 feat(web): 添加 embedded session runtime 并默认启用 || feat(web): Add embedded session runtime and enable it by default Mar 30, 2026
@luzhongqiu luzhongqiu force-pushed the codex/kimi-web-async branch from fa9f822 to 3938e20 Compare March 30, 2026 09:19
@luzhongqiu luzhongqiu marked this pull request as ready for review March 30, 2026 10:44
Copy link
Copy Markdown

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

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: 3b3a65d7c6

ℹ️ 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".

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

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