Skip to content

feat(kimi-code): keep print-mode goal runs alive until the goal settles - #1712

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:fix/v2-print-goal-continuation
Jul 14, 2026
Merged

feat(kimi-code): keep print-mode goal runs alive until the goal settles#1712
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:fix/v2-print-goal-continuation

Conversation

@sailist

@sailist sailist commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below. (This is the one remaining piece of #1710, which duplicated the already-merged #1704 and was closed.)

Problem

On the experimental engine (agent-core-v2), kimi -p "/goal ..." exited right after the first turn even when the goal was still active. v2 drives goal continuation by launching new turns (v1 keeps a single turn alive across the whole goal), and the print runner only awaited the first turn's result, so the cleanup path cancelled the continuation turn milliseconds after it started — multi-turn goals could never complete in print mode. This contradicts the documented headless-goal contract ("the goal driver keeps the prompt's turn-run alive across continuation turns until the goal reaches a terminal state").

What changed

  • The print background policy (applyPrintBackgroundPolicy) gains a goalActive probe: while a goal is active, the run keeps waiting for continuation turns regardless of the print_background_mode, bounded by print_wait_ceiling_s as a safety net (with a warning if hit). Once the goal reaches a terminal state, the normal exit / drain / steer policy applies, and the goal summary still drives the exit code.
  • The turn.ended collector accepts a non-finite wait budget (no timer) used by the goal wait.
  • Unit tests cover waiting through continuation turns and the goal-wait ceiling; verified end-to-end with the SEA build: a 3-turn counting goal completes (Goal [complete] (turns: 3), exit 0), a 1-turn budget blocks the goal (Goal [blocked], exit 3).

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.

- applyPrintBackgroundPolicy waits for goal continuation turns via a goalActive hook before applying the exit/drain/steer mode, bounded by the wait ceiling
- createPrintTurnEndings skips the timeout when the remaining budget is not finite
- update the changeset to cover the goal-run lifecycle
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ed50764

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

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

commit: ed50764

@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: 4240e4ec90

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

Comment on lines +607 to +610
const ended = await input.turnEndings.next(
goalDeadline - input.now(),
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 Wake the goal wait on terminal goal updates

When a goal stops without producing another turn.ended after this wait starts (for example, a continuation launch fails and the goal service pauses the goal via goal.updated after handling the same turn end), this loop waits only on turnEndings.next. If the current turn end was already consumed before goalActive() observes the pause, no further turn ending arrives, so kimi -p "/goal ..." remains alive until print_wait_ceiling_s (default 3600s) instead of immediately printing the paused/blocked summary; the wait should also be woken by terminal goal updates or otherwise re-check after the goal service settles.

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 78ca44b into MoonshotAI:main Jul 14, 2026
14 checks passed
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