Skip to content

fix(web): propagate afk mode to workers#2211

Open
he-yufeng wants to merge 1 commit into
MoonshotAI:mainfrom
he-yufeng:fix/web-afk-worker
Open

fix(web): propagate afk mode to workers#2211
he-yufeng wants to merge 1 commit into
MoonshotAI:mainfrom
he-yufeng:fix/web-afk-worker

Conversation

@he-yufeng
Copy link
Copy Markdown

@he-yufeng he-yufeng commented May 9, 2026

Summary

kimi --afk web sets the Web server up as a non-interactive session, but the worker subprocess currently starts without that invocation flag. That leaves Web sessions behaving like interactive clients: tool calls can still ask for approval, and ExitPlanMode falls through to the Web client's unsupported question flow.

This patch carries the root --afk flag into the Web worker through a small internal environment flag, then passes it to KimiCLI.create() so the existing approval/session-state path handles the rest.

Closes #2201

To verify

  • python -m uv run pytest tests\core\test_plan_flag.py::TestWebWorkerResumedDetection tests\core\test_web_afk_cli.py -q
  • python -m uv run ruff check src\kimi_cli\cli\__init__.py src\kimi_cli\web\app.py src\kimi_cli\web\runner\worker.py tests\core\test_plan_flag.py tests\core\test_web_afk_cli.py
  • python -m py_compile src\kimi_cli\cli\__init__.py src\kimi_cli\web\app.py src\kimi_cli\web\runner\worker.py tests\core\test_plan_flag.py tests\core\test_web_afk_cli.py
  • git diff --check

Open in Devin Review

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: a17becc5d5

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

Comment on lines +376 to +381
if ctx.invoked_subcommand == "web" and afk:
import os

from kimi_cli.web.app import ENV_DEFAULT_AFK

os.environ[ENV_DEFAULT_AFK] = "1"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear web afk env when --afk is not requested

Setting KIMI_WEB_DEFAULT_AFK only in the true branch makes the flag sticky for the lifetime of the Python process. If cli is invoked again in-process (e.g., embedded usage, repeated CliRunner invocations, or long-lived host processes), a prior kimi --afk web call causes later plain kimi web runs to still start workers in AFK mode unexpectedly because run_worker() reads this env var each time. The callback should also clear this variable when the web subcommand runs without --afk.

Useful? React with 👍 / 👎.

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 2 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

1 participant