Skip to content

feat(v2-print): align kimi -p run lifecycle with the default engine#2017

Open
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/v2-print-run-lifecycle
Open

feat(v2-print): align kimi -p run lifecycle with the default engine#2017
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/v2-print-run-lifecycle

Conversation

@sailist

@sailist sailist commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

In the v2 engine, the kimi -p (print mode) run lifecycle diverged from the default engine in several ways:

  • Print mode did not fill in the config defaults the default engine relies on (bash task timeout, max steps per turn, and subagent timeout should be unbounded in print mode), so runs could be cut short by unintended limits.
  • The default print background mode was exit, so a run could terminate even while cron tasks still had future fires waiting to be steered.
  • BashTool had no configurable background task timeout, and subagents could not opt out of the timeout entirely.
  • Turn retry events (turn.step.retrying) were not surfaced in print output.

What changed

1. Print-mode config defaults

  • Added applyPrintModeConfigDefaults in agent-core-v2: fills print-mode config defaults (bash task timeout / max steps per turn / subagent timeout, all unbounded) into the memory layer while respecting user-set keys.
  • Added the task.bashTaskTimeoutS config key and wired it into BashTool's detachTimeoutMs.
  • Allowed subagent timeoutMs = 0 to mean no timeout.

2. Print background lifecycle

  • Changed the default print background mode from exit to steer.
  • Added applyPrintBackgroundPolicy: keeps the run alive while cron tasks have future fires so their steered turns can run, with an anti-spin guard for wedged ticks; goal/cron waiting shares the steer ceiling budget.

3. Print output

  • The v2 print runner now forwards turn.step.retrying events to writeRetrying.

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.

…13 files)

- add applyPrintModeConfigDefaults in agent-core-v2: fill print-mode config
  defaults (bash task timeout / max steps per turn / subagent timeout all
  unbounded) into the memory layer, respecting user-set keys
- applyPrintBackgroundPolicy: keep the run alive while cron tasks have
  future fires so their steered turns can run, with an anti-spin guard for
  wedged ticks; goal/cron waiting shares the steer ceiling budget
- default print background mode changed from exit to steer
- add task.bashTaskTimeoutS config key and wire it into BashTool's
  detachTimeoutMs
- v2 print runner now forwards turn.step.retrying events to writeRetrying
- allow subagent timeoutMs = 0 (no timeout)
@changeset-bot

changeset-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 20fc0ce

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

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

commit: 20fc0ce

@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: 20fc0ce128

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

* never have a subagent killed by a wall-clock cap; only the model itself may
* stop one.
*/
export const PRINT_SUBAGENT_TIMEOUT_MS_DEFAULT = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat zero swarm timeout as unbounded

In print mode this default is written to [subagent], and AgentSwarmTool passes resolveSubagentTimeoutMs() through as task.timeout to AgentRunBatch; that scheduler arms setTimeout whenever the timeout is defined, so 0 aborts immediately rather than disabling the cap. Any AgentSwarm call under kimi -p without an explicit subagent timeout will fail right away, so either map 0 to undefined at the swarm boundary or make the batch scheduler treat 0 as no timeout.

Useful? React with 👍 / 👎.

detached: startsInBackground,
timeoutMs,
detachTimeoutMs: DEFAULT_BACKGROUND_TIMEOUT_S * MS_PER_SECOND,
detachTimeoutMs: this.detachTimeoutMs(),

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 Apply bashTaskTimeoutS to initially backgrounded commands

When run_in_background=true and the tool call omits timeout, timeoutMs is still computed from the built-in background default (normalizeTimeoutMs(args.timeout, true), 600s); this new config value is only supplied as detachTimeoutMs, which is applied when a foreground task is later detached. In kimi -p, applyPrintModeConfigDefaults sets bashTaskTimeoutS=0, but commands that start directly in the background will still be killed after 10 minutes unless the model also sends disable_timeout=true.

Useful? React with 👍 / 👎.

Comment on lines +753 to +755
const ended = await input.turnEndings.next(
Math.max(fireAt - input.now(), 0) + CRON_FIRE_GRACE_MS,
input.skipTurnId,

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 Cap cron waits at the print ceiling

When the next cron fire is beyond printWaitCeilingS, this waits until fireAt + grace instead of the remaining ceiling budget. Because createPrintTurnEndings.next() uses a ref'd timer, a run configured with a small ceiling (for example 60s) and a cron scheduled hours later will stay alive until that cron fire rather than honoring the ceiling; clamp this wait to deadline - now and finish/warn when the ceiling is reached.

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