feat(cli): drain background bash at end of turn in kimi -p#1396
Conversation
- 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 detectedLatest commit: f437f42 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
There was a problem hiding this comment.
💡 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, |
There was a problem hiding this comment.
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 👍 / 👎.
Related Issue
No linked issue. The motivation is described in Problem.
Problem
In
kimi -p(print mode) with the defaultbackground.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 onkeep_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
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.waitForActiveTaskscall, one aggregateprint_wait_ceiling_sdeadline, and the same flush + continue in the turn loop. They keep separate trigger flags.drainProcessTasksOnStopsession option (SDK -> RPC -> session -> agent) and enable it in thekimi -pflow alongsidedrainAgentTasksOnStop.keep_alive_on_exitis unchanged and still governs only the exit-time wait/teardown.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.