Skip to content

feat(cli): keep print sessions alive for pending work - #1555

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/prompt-goal-cron-lifecycle
Jul 11, 2026
Merged

feat(cli): keep print sessions alive for pending work#1555
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/prompt-goal-cron-lifecycle

Conversation

@sailist

@sailist sailist commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Keep non-interactive kimi -p sessions alive while an autonomous goal remains active or cron tasks are pending, so follow-up goal turns and scheduled work can finish instead of being terminated after the first prompt response.

Related Issue

No related issue. In print mode, the CLI exited after the initial agent turn even when the session still had an active goal or pending cron tasks, preventing those workflows from completing.


1. Print-mode session lifecycle

Problem: kimi -p treated the end of the initial response as the end of the process, regardless of session-owned background work.

What was done:

  • Updated the prompt runner to continue processing while a goal is active or cron tasks remain pending.
  • Preserved existing exit behavior when neither condition applies.
  • Added CLI tests covering goal continuation, pending cron work, and normal completion.

2. Session state exposure

Problem: The CLI and SDK did not have a supported way to inspect the goal and cron state needed to make the lifecycle decision.

What was done:

  • Added RPC and SDK accessors for active-goal and pending-cron state.
  • Exposed the relevant agent-core APIs through existing package boundaries.
  • Added agent-core and node SDK tests for the new state queries.

What changed

The CLI now bases print-mode termination on both the current turn and outstanding session work. Agent core exposes pending cron state over RPC, and the node SDK exposes the corresponding session queries used by the CLI. Tests cover the behavior across agent core, SDK, and CLI layers.

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.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

…are pending

A kimi -p run settled the moment the main agent's turn ended (end_turn),
so a goal created mid-run was cancelled during cleanup and a scheduled
cron task never fired in the same run.

- runPromptTurn now re-evaluates completion when the main agent goes idle
  and stays alive while a goal is still active (the goal driver runs the
  continuation turns) or while cron tasks with a future fire remain (their
  fire steers a fresh turn). A ref'd handle keeps the event loop alive
  during the wait since the cron scheduler tick is unref'd.
- a terminal goal.updated (e.g. the driver blocking a goal on a hard
  budget, which emits no further turn.ended) also re-evaluates so the run
  cannot hang.
- add getCronTasks RPC and Session.getCronTasks() so the print flow can
  enumerate pending cron tasks.
@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7994590

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

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

commit: 7994590

@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: 79945909d0

ℹ️ 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 (settled || activeTurnId !== undefined) return;
// A task whose expression has no future fire can never trigger a
// turn; don't hold the run open for it.
if (tasks.some((task) => task.nextFireAt !== null)) {

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 Avoid waiting on disabled cron tasks

When KIMI_DISABLE_CRON=1 is set, CronManager wires the scheduler's isKilled check so existing scheduled tasks never fire, but getCronTasks() still reports their nextFireAt. In a resumed kimi -p session that already has a cron task, this branch installs the ref'd keep-alive timer and returns without any future event that can re-enter completion, so the print command hangs until killed instead of exiting while cron is disabled.

Useful? React with 👍 / 👎.

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