Skip to content

fix(acp): make session/set_mode plan idempotent on sessions created in plan mode - #3407

Open
ApexYash11 wants to merge 1 commit into
MoonshotAI:mainfrom
ApexYash11:fix/acp-set-mode-plan
Open

fix(acp): make session/set_mode plan idempotent on sessions created in plan mode#3407
ApexYash11 wants to merge 1 commit into
MoonshotAI:mainfrom
ApexYash11:fix/acp-set-mode-plan

Conversation

@ApexYash11

Copy link
Copy Markdown

Related Issue

Resolve #3356

Problem

Over ACP, session/set_mode with modeId: "plan" fails with -32603 Internal error ("Already in plan mode") right after session/new reports currentModeId: "default". When default_plan_mode = true, the engine enters plan mode at session creation, but the ACP server's local mode state stays "default" and setMode re-enters plan unconditionally, tripping the engine's guard. ACP clients that apply a configured plan mode right after session/new abort session creation entirely.

What changed

In packages/acp-server/src/session.ts:

  • Seed the local currentModeId from the engine's actual plan state during session init, so session/new truthfully reports "plan" when the engine entered plan mode at create time.
  • Make setMode's plan toggle idempotent — only call enterPlan/cancelPlan when the engine's plan state differs from the requested mode — so re-asserting the active mode no longer throws "Already in plan mode".

Added an integration test in packages/acp-server/test/config.test.ts that boots with default_plan_mode = true, asserts session/new reports plan, and verifies session/set_mode "plan" succeeds.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • 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 Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ac44034

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

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

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

sessionId: this.sessionId,
error: error instanceof Error ? error.message : String(error),
});
return false;

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 Preserve plan cancellation when status reads fail

When getPlan() rejects while the engine is actually in plan mode (for example, status() hits a non-missing plan-file I/O error), returning false treats the state as inactive. That makes init() report default, and more importantly makes setMode('default' | 'auto' | 'yolo') skip cancelPlan() before updating permission/currentModeId and emitting a non-plan mode, leaving the engine in plan mode while ACP says it exited; propagate the unknown state or still issue the cancel for non-plan targets.

Useful? React with 👍 / 👎.

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.

ACP: session/set_mode "plan" fails with -32603 "Already in plan mode" after session/new reports currentModeId "default"

1 participant