fix(web): propagate afk mode to workers#2211
Conversation
There was a problem hiding this comment.
💡 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".
| if ctx.invoked_subcommand == "web" and afk: | ||
| import os | ||
|
|
||
| from kimi_cli.web.app import ENV_DEFAULT_AFK | ||
|
|
||
| os.environ[ENV_DEFAULT_AFK] = "1" |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
kimi --afk websets 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, andExitPlanModefalls through to the Web client's unsupported question flow.This patch carries the root
--afkflag into the Web worker through a small internal environment flag, then passes it toKimiCLI.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 -qpython -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.pypython -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.pygit diff --check