Skip to content

feat(cli): drain background bash at end of turn in kimi -p#1396

Open
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/print-drain-bash
Open

feat(cli): drain background bash at end of turn in kimi -p#1396
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/print-drain-bash

Conversation

@sailist

@sailist sailist commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. The motivation is described in Problem.

Problem

In kimi -p (print mode) with the default background.keep_alive_on_exit = false, when the main agent ends a turn while a background bash command is still running, nothing waits for it: the end-of-turn drain only covers background subagents (kind === 'agent'), the exit-time wait is gated on keep_alive_on_exit = true, and session teardown kills the bash and suppresses its completion notification. The model therefore never sees the bash result before the run exits. (Background subagents already get a wrap-up step via the end-of-turn drain added in #1371; bash did not.)

What changed

  • Hold the main turn open while background bash (kind === 'process') is still running and deliver its completion into the turn so the model gets one wrap-up step before the run exits — mirroring the existing subagent drain.
  • Unify the wait path: agent and process draining now share one waitForActiveTasks call, one aggregate print_wait_ceiling_s deadline, and the same flush + continue in the turn loop. They keep separate trigger flags.
  • Add a drainProcessTasksOnStop session option (SDK -> RPC -> session -> agent) and enable it in the kimi -p flow alongside drainAgentTasksOnStop. keep_alive_on_exit is unchanged and still governs only the exit-time wait/teardown.
  • Update the en/zh config docs and add tests for the process-kind drain.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

- Hold the main turn for still-running background bash and deliver its
  completion before the run exits, mirroring the subagent drain.
- Reuse the subagent drain's wait path and shared print_wait_ceiling_s
  deadline, gated by a new drainProcessTasksOnStop session option.
- keep_alive_on_exit still governs only the exit-time wait and teardown.
@changeset-bot

changeset-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f437f42

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 Jul 5, 2026

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

commit: f437f42

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

Copy link
Copy Markdown

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

permission: 'auto',
additionalDirs: opts.addDirs?.length ? opts.addDirs : undefined,
drainAgentTasksOnStop: true,
drainProcessTasksOnStop: true,

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 Enable process draining for resumed print sessions

When kimi -p -r <id> or kimi -p -c resumes an existing session, resolvePromptSession returns from the two harness.resumeSession(...) branches above and never reaches this fresh-session createSession option; ResumeSessionOptions also has no equivalent drain flag. In those resumed print runs, a background Bash started by the prompt turn still is not held/drained before exit, so the new behavior only works for brand-new kimi -p sessions despite the feature/docs describing print mode generally.

Useful? React with 👍 / 👎.

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