Skip to content

feat(agent-core-v2): make /init runs cancellable - #1667

Merged
liruifengv merged 1 commit into
mainfrom
feat/agent-core-v2-init-cancel
Jul 14, 2026
Merged

liruifengv merged 1 commit into
mainfrom
feat/agent-core-v2-init-cancel

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No tracking issue — the problem is explained below.

Problem

In the v2 engine, /init (SessionInitService.generateAgentsMd) spawns a coder subagent through agentLifecycle.run with an AbortController that is a local of generateAgentsMd. Nothing outside the service can reach it, so there is no way to cancel an init run: a client's cancel path (e.g. Ctrl+C in a TUI) only cancels the main agent's loop turn, which does not exist during /init. The run simply continues to completion. This was hit by the tui-v2 client, the first v2 consumer that exposes /init.

What changed

  • ISessionInitService gains cancelInit(). The service keeps the in-flight run's AbortController on the instance (assigned before the run, cleared in finally), and cancelInit() aborts it with a user-cancellation reason. It is a no-op while idle, so callers can invoke it unconditionally alongside the main agent's turn cancel.
  • generateAgentsMd no longer wraps cancellations into SESSION_INIT_FAILED: UserCancellationError / AbortError propagate unwrapped (and mirrorAgentRun suppresses the subagent.failed event for them), so callers can distinguish "aborted" from "failed".
  • Added tests: cancellation propagates unwrapped without a failure event, and cancelInit is a no-op when idle.

This is additive only — no existing signatures change. Verified: package typecheck clean, full agent-core-v2 suite passes (236 files / 3302 tests), lint:domain OK.

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.

The init run spawns a coder subagent through agentLifecycle.run with an
AbortController that was a local of generateAgentsMd, so nothing outside
the service could cancel it: Ctrl+C in clients only cancels the main
agent's loop turn, which does not exist during /init.

ISessionInitService gains cancelInit(): the service keeps the in-flight
run's AbortController (cleared in finally), and cancelInit aborts it with
a user-cancellation reason. Cancellations propagate unwrapped from
generateAgentsMd (UserCancellationError / AbortError, never
SESSION_INIT_FAILED, no subagent.failed event) so callers can distinguish
"aborted" from "failed".
@changeset-bot

changeset-bot Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a8d21e9

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 no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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@a8d21e9
npx https://pkg.pr.new/@moonshot-ai/kimi-code@a8d21e9

commit: a8d21e9

@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: a3a6187445

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

@liruifengv
liruifengv force-pushed the feat/agent-core-v2-init-cancel branch from a3a6187 to a8d21e9 Compare July 14, 2026 04:34
@liruifengv
liruifengv merged commit d780b23 into main Jul 14, 2026
14 checks passed
@liruifengv
liruifengv deleted the feat/agent-core-v2-init-cancel branch July 14, 2026 05:31
liruifengv added a commit that referenced this pull request Jul 14, 2026
CoreSession.cancel() now also calls sessionInit.cancelInit() (a no-op
while idle): /init runs outside the main agent's loop turns, so the RPC
turn cancel alone could not reach it. Builds on the engine support that
landed in #1667.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 15, 2026
The init run spawns a coder subagent through agentLifecycle.run with an
AbortController that was a local of generateAgentsMd, so nothing outside
the service could cancel it: Ctrl+C in clients only cancels the main
agent's loop turn, which does not exist during /init.

ISessionInitService gains cancelInit(): the service keeps the in-flight
run's AbortController (cleared in finally), and cancelInit aborts it with
a user-cancellation reason. Cancellations propagate unwrapped from
generateAgentsMd (UserCancellationError / AbortError, never
SESSION_INIT_FAILED, no subagent.failed event) so callers can distinguish
"aborted" from "failed".
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