Skip to content

feat(agent-core): default print mode to steer with unbounded limits - #1722

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/print-mode-steer-defaults
Jul 15, 2026
Merged

feat(agent-core): default print mode to steer with unbounded limits#1722
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/print-mode-steer-defaults

Conversation

@sailist

@sailist sailist commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

None — see Problem below.

Problem

In print mode (kimi -p), a headless run exited as soon as the main turn finished (default print_background_mode = "exit"). Background tasks the agent had launched were abandoned, and their completions never fed back into the run — even though a headless invocation has no user around to continue the work. The limits that did exist (1h wait ceiling, 50 steered turns, 2h subagent timeout) were also tuned for interactive use and could cut a long headless run short.

What changed

1. Default print background mode: exitsteer

Problem: a kimi -p run finished after one turn even with background tasks still pending.

What was done:

  • Session.resolvePrintBackgroundMode now falls back to 'steer' when neither print_background_mode nor the legacy keep_alive_on_exit is set, so the run stays alive while background tasks are pending and each completion steers a new main turn.
  • Setting print_background_mode = "exit" (or "drain") restores the previous behavior; the legacy keep_alive_on_exit = true'drain' mapping is unchanged.

2. Print-mode config defaults

Problem: interactive-tuned limits (1h wait ceiling, 50 steered turns, 2h subagent timeout) could cut a headless run short.

What was done:

  • New applyPrintModeConfigDefaults (config/print-defaults.ts) fills only values the user left unset: an effectively unbounded print_wait_ceiling_s (~10 years) and print_max_turns (100k), a 72h subagent timeout, and max_steps_per_turn = 0.
  • A new uiMode option is threaded from SDKRpcClient through KimiCore into session create/resume (withPrintModeDefaults); the raw user config is left untouched so config reads/writes still round-trip the file values.

3. Timer clamp for huge timeouts

Problem: Node clamps setTimeout delays above 0x7fffffff to 1ms, so an "effectively unbounded" timeout would fire immediately.

What was done:

  • timeoutOutcome / resettableTimeoutOutcome now clamp delays to MAX_TIMER_DELAY_MS (~24.8 days).

Tests: new KimiCore print-mode defaults suite in test/harness/runtime.test.ts (defaults applied, explicit user config wins, defaults off outside print mode, defaults applied on session reload) and updated handlePrintMainTurnCompleted cases in test/session/lifecycle-hooks.test.ts.

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. (.changeset/print-mode-steer-defaults.md included)
  • Ran gen-docs skill, or this PR needs no doc update.

- change the default print background mode from 'exit' to 'steer' so
  `kimi -p` stays alive while background tasks are pending and each
  completion steers a new main turn
- add print-mode config defaults (applyPrintModeConfigDefaults):
  effectively unbounded wait ceiling and turn cap, 72h subagent
  timeout; explicit user config always wins
- thread the new `uiMode` option from SDKRpcClient through KimiCore
  into session create/resume
- clamp setTimeout delays to 0x7fffffff so huge timeouts are not
  clamped to 1ms by Node
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: da21e40

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 Minor

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 15, 2026

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

commit: da21e40

@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: da21e40899

ℹ️ 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".

parseEnv: parseBooleanEnv,
});
return keepAliveOnExit ? 'drain' : 'exit';
return keepAliveOnExit ? 'drain' : 'steer';

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 Preserve explicit keep-alive false as exit

When an existing print-mode config explicitly sets [background] keep_alive_on_exit = false (or the env override to false), this now resolves to steer because the false result is treated the same as the unset default. The new behavior is documented here as defaulting to steer only “when neither is set,” while the legacy mapping made explicit false exit immediately; those users will unexpectedly keep kimi -p alive for background completions unless they add a new print_background_mode = "exit". Check whether the legacy option/env was present before falling through to the new default.

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 3703d03 into MoonshotAI:main Jul 15, 2026
15 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 15, 2026
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