feat(cli): keep print sessions alive for pending work - #1555
Conversation
…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 detectedLatest commit: 7994590 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: 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)) { |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Keep non-interactive
kimi -psessions 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 -ptreated the end of the initial response as the end of the process, regardless of session-owned background work.What was done:
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:
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
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.make gen-changelogto update the changelog.make gen-docsto update the user documentation.