-
Notifications
You must be signed in to change notification settings - Fork 395
feat: hold print-mode turn until background subagents drain #1371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6455ee8
5d565f3
f84dba4
bce3d77
54bb19d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Wait for background subagents to finish and respond to their results before exiting in `kimi -p`, instead of ending the turn early. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -729,6 +729,28 @@ export class TurnFlow { | |
| if (this.flushSteerBuffer()) return { continue: true }; | ||
| signal.throwIfAborted(); | ||
|
|
||
| // Print-mode drain: when `kimi -p` ends a turn while background | ||
| // subagents are still running, hold the turn open and idle-wait | ||
| // until they finish (or the drain deadline is reached). Their | ||
| // completions steer into the buffer during the wait and are | ||
| // flushed afterward, so the model gets one wrap-up step to react | ||
| // (nominate, backfill, ...) before the turn ends. Gated on a | ||
| // session flag so interactive / goal modes are unaffected. | ||
| if (this.agent.printDrainAgentTasksOnStop) { | ||
| const remaining = this.agent.printDrainDeadlineMs - Date.now(); | ||
| const hasActiveAgentTask = this.agent.background | ||
| .list(true) | ||
| .some((task) => task.kind === 'agent'); | ||
| if (hasActiveAgentTask && remaining > 0) { | ||
| await this.agent.background.waitForActiveTasks( | ||
| (task) => task.kind === 'agent', | ||
| { timeoutMs: remaining, signal }, | ||
| ); | ||
| this.flushSteerBuffer(); | ||
| return { continue: true }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
| // 2. After UpdateGoal marks a goal terminal, ask the model for one | ||
| // final user-facing outcome message before the turn ends. | ||
| if ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
kimi -p -r <id>orkimi -p --continue, the branches above callresumeSessionand never set this new option (there is no resume-side equivalent), so resumed main agents keepprintDrainAgentTasksOnStopfalse. A resumed print turn can still launchAgent(run_in_background=true)and then exit before those completion notifications are folded into the turn, leaving the original print-mode failure unfixed for resumed sessions. Please thread the drain flag through the resume/continue path or enable it on the resumed main agent for print mode.Useful? React with 👍 / 👎.