Skip to content

fix: cancel active turns during session shutdown#661

Merged
7Sageer merged 2 commits into
MoonshotAI:mainfrom
7Sageer:fix/cancel-active-turns-on-close
Jun 11, 2026
Merged

fix: cancel active turns during session shutdown#661
7Sageer merged 2 commits into
MoonshotAI:mainfrom
7Sageer:fix/cancel-active-turns-on-close

Conversation

@7Sageer

@7Sageer 7Sageer commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This fixes a prompt-mode shutdown regression where foreground Bash processes could outlive kimi -p when the CLI receives SIGTERM or SIGHUP.

Problem

Prompt-mode signal cleanup closed the harness, but session shutdown only stopped managed background tasks. If a foreground Bash tool was still running, the active turn was not canceled during Session.close(), so the Bash tool never received the abort signal it uses to terminate the child process. Managed background Bash timeout timers also remained referenced, which could keep kimi -p alive after the prompt completed.

What changed

  • Cancel active turns during Session.close() before background-task shutdown, with a bounded wait and timeout warning.
  • unref() managed background Bash timeout timers so they do not keep prompt mode alive.
  • Handle SIGHUP in prompt-mode termination cleanup, matching standard signal exit code 129.
  • Add unit coverage for active turn cancellation and prompt-mode SIGTERM/SIGHUP cleanup.

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.

@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3a069a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@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 Jun 11, 2026

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

commit: 3a069a4

@7Sageer 7Sageer merged commit 0927f79 into MoonshotAI:main Jun 11, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 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