Skip to content

fix(kap-server): apply swarm mode from prompt submissions - #4460

Merged
wbxl2000 merged 1 commit into
MoonshotAI:mainfrom
kimi-agent-bot:fix/prompt-swarm-mode
Oct 27, 2026
Merged

wbxl2000 merged 1 commit into
MoonshotAI:mainfrom
kimi-agent-bot:fix/prompt-swarm-mode

Conversation

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Related: #3830。本 PR 只覆盖其中的 Swarm 首轮失效;Plan 与 goal 由独立 PR 处理。

Bug Reproduction Steps

  1. 创建一个新会话,首次提交 prompt 时携带 swarm_mode: true。
  2. 提交成功返回后读取 GET /api/v1/sessions/{session_id}/status,或观察首轮是否注入 Swarm 模式。
  3. 修复前:schema 接受该字段,但服务端仍报告 swarm_mode: false,首轮未进入 Swarm;再次通过 session profile 开启后才正常。

Root Cause

promptSubmissionSchema 已接受 swarm_mode,desktop / web 首轮也已经携带该字段,但 POST /sessions/{session_id}/prompts 只应用 model、thinking、permission 等覆盖项,从未读取 swarm_mode。

本 PR 是根本修复:在 prompt 入队前应用该字段,而不是要求客户端额外先发一次 profile 更新。

Code Changes

 POST /sessions/{id}/prompts
   validate media references and skills
   resolve the target agent
   apply profile / model / thinking / permission
+  if swarm_mode is present and differs from current state
+    enter or exit Swarm before submitting the prompt
   submit the prompt
  • 增加首轮开启、重复开启和关闭 Swarm 的回归测试,并断言模式切换发生在 prompt 提交之前。
  • 更新中英文 server API 文档,明确 swarm_mode 已生效;plan_mode 与 goal 字段不在本 PR 范围内。
  • 添加 patch changeset。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
prompt 携带 swarm_mode 字段通过校验但被忽略 在 prompt 提交前进入或退出目标 agent 的 Swarm desktop / web 首轮请求,以及直接调用 kap REST 的 SDK / 外部脚本;旧行为使公开参数失效,没有可保留的合理依赖 请求省略 swarm_mode,即保持本次提交不改变 Swarm
prompt 省略 swarm_mode 不改变 Swarm 不变 所有现有客户端与直接 REST 调用方 无需处理
plan_mode、goal_objective、goal_control 未应用 本 PR 不变 使用这些字段的客户端;整族修复由独立 PR 处理 无需处理
  • 影响模块:packages/kap-server prompt 提交路由。
  • 回归覆盖:真实 agent 状态、重复 true 不重复 enter、false 能 exit,以及 enter/exit 均早于 prompt submit;既有 prompt 测试覆盖字段省略时的旧行为。

Validation

  • pnpm exec vitest run packages/kap-server/test/prompts.test.ts --maxWorkers=1:72/72 通过。
  • pnpm --filter @moonshot-ai/kap-server typecheck:通过。
  • pnpm exec oxlint packages/kap-server/src/routes/prompts.ts packages/kap-server/test/prompts.test.ts:0 error;仅有 2 个测试文件既有 warning。
  • node scripts/check-no-comments.mjs:通过。
  • pnpm --filter kimi-code-docs run build:通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • 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 Oct 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 43d2eff

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 commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T06:23:47.039346Z 43d2eff PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026

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

commit: 43d2eff

@wbxl2000
wbxl2000 merged commit 78b72fe into MoonshotAI:main Oct 27, 2026
17 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
The behaviour of MoonshotAI#4421 has been in the requester since 94397aa, but its
suite still asserted only that the lowered system message lost its
`tools` field, which a message kept in place would also satisfy. Assert
instead that no system message survives and the history keeps its
length, and rename the case after what it protects.

Also settle ten ledger rows that were already implemented here: MoonshotAI#3733,
MoonshotAI#4413, MoonshotAI#4418, MoonshotAI#4421, MoonshotAI#4435, MoonshotAI#4460, MoonshotAI#4465, MoonshotAI#4516, MoonshotAI#4523, MoonshotAI#4532 and the
MoonshotAI#4558 test calibration, each with a probe over the suite that pins it.
Two rows carried a probe without a test-name selector (MoonshotAI#4557, MoonshotAI#4558),
which aborted `--verify` for every other row; MoonshotAI#4557 is a changelog sync
and now carries a manual probe.
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.

3 participants