feat(background): add print_background_mode steer for multi-turn -p runs#1497
feat(background): add print_background_mode steer for multi-turn -p runs#1497sailist wants to merge 2 commits into
Conversation
… -p runs - add `[background].print_background_mode` (`exit`/`drain`/`steer`) and `print_max_turns`; when unset, falls back to `keep_alive_on_exit = true` mapping to `drain`, preserving existing behavior - core: `Session.handlePrintMainTurnCompleted()` returns `finish`/`continue`; in `steer` mode the run stays alive so a background-task completion `turn.steer`s the main agent into a new turn (matching background subagents), bounded by `print_wait_ceiling_s` and `print_max_turns` - cli: print driver follows every main turn instead of only the first and defers `finish()` until the run quiesces or a limit is hit - plumb `handlePrintMainTurnCompleted` through node-sdk RPC; docs + tests
🦋 Changeset detectedLatest commit: 6721c05 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: c0b9cd8e00
ℹ️ 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".
| if (this.countActiveBackgroundTasks() > 0) { | ||
| return 'continue'; |
There was a problem hiding this comment.
Enforce the steer wait ceiling while tasks are pending
When print_background_mode = "steer" and a background task is still running after the main turn, this returns continue immediately. The print driver only calls handlePrintMainTurnCompleted() again after another main turn.ended, so a hung or long-running background task produces no wake-up and the deadline checked above is never re-evaluated; kimi -p can therefore hang past print_wait_ceiling_s instead of being bounded as documented.
Useful? React with 👍 / 👎.
Related Issue
Problem
In
kimi -p(print) mode, the main agent's run finished after a single turn.The only knob for background tasks was
background.keep_alive_on_exit: whentrue, the driver suppressed terminal notifications and drained everybackground task before exiting. That gives the main agent no chance to react
to a background result — a completion could not
turn.steerthe main agentinto a follow-up turn the way it does for background subagents. So multi-turn
-pruns driven by background-task completions were not possible.What changed
Added an explicit
background.print_background_modepolicy and taught theprint driver to follow the main agent across turns.
1. New print-mode background policy (
agent-core)What was done:
[background].print_background_mode('exit' | 'drain' | 'steer') andprint_max_turnstoBackgroundConfigSchema.Session.resolvePrintBackgroundMode():print_background_modeisauthoritative; when unset it falls back to the legacy
keep_alive_on_exitmapping (
true ⇒ 'drain', otherwise'exit'), so existing configs keeptheir behavior.
waitForBackgroundTasksOnPrint()now only runs under the'drain'mode.Session.handlePrintMainTurnCompleted()returning'finish' | 'continue':'exit'→ finish immediately (default);'drain'→ suppress + drain, then finish;'steer'→ return'continue'while background tasks are still pending so acompletion can
turn.steerthe main agent into a new turn; finish oncequiescent, or when
print_wait_ceiling_s/print_max_turnsis hit.2. Print driver follows every main turn (
apps/kimi-code)What was done:
runPromptTurnno longer maps only the firstturn.started; it tracks themain agent across subsequent turns so steered turns render too.
turn.endedwithreason === 'completed', it flushes the bufferedassistant message, then calls
handlePrintMainTurnCompleted()and defersfinish()when the action is'continue'.3. SDK plumbing, docs, and tests
What was done:
handlePrintMainTurnCompletedthroughnode-sdkRPC andSession.docs/enanddocs/zhconfig references and release notes.apps/kimi-code/test/cli/run-prompt.test.tsandpackages/agent-core/test/session/lifecycle-hooks.test.ts.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.