Skip to content

feat: remove experimental subagent context forking - #5254

Merged
7Sageer merged 4 commits into
MoonshotAI:mainfrom
7Sageer:chore/remove-subagent-fork
Nov 23, 2026
Merged

7Sageer merged 4 commits into
MoonshotAI:mainfrom
7Sageer:chore/remove-subagent-fork

Conversation

@7Sageer

@7Sageer 7Sageer commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

维护者决定下线实验性的 subagent context forking 能力。此前显式启用 subagent_fork 的用户可以让 Agent / AgentSwarm 创建的 subagent 继承调用方对话快照;这会额外维护一条与普通 subagent 创建完全不同的生命周期、工具继承和提示词路径。

本 PR 删除该实验开关及专属运行时分支,让所有新 subagent 统一走现有的 profile/model 校验、环境 lease 和 agentLifecycle.create 路径;通用会话 /fork、BTW 和底层 agent lifecycle fork 保持可用。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路是删除公开参数和分支,而不是把实验开关默认值翻转后继续保留不可达实现。删除后,新 subagent 只有一条创建路径:

 Agent / AgentSwarm
-  根据 subagent_fork 开关决定是否暴露 fork 参数和指导
-  planSpawn 根据 fork 跳过 profile / allowlist / model 校验
-  spawn 根据 fork 选择:
-    lifecycle.fork:复制调用方历史、模型、类型与工具
-    lifecycle.create:创建普通 subagent
+  schema 不再包含 fork
+  planSpawn 始终执行既有 profile / allowlist / model 校验
+  spawn 始终获取环境 lease 并调用 lifecycle.create
+  始终继承普通 subagent 用户工具并应用 profile prompt prefix

具体变化:

  • 从 Agent 和 AgentSwarm 的输入 schema 中删除 fork,并增加契约断言,防止该参数重新出现。
  • 删除 subagent_fork flag、对应环境变量、实验功能列表注册、legacy config migration 注册和两段 fork 工具指导。
  • 残留的 [experimental].subagent_fork 与其他未注册实验 ID 一样沿用原有容忍行为,不增加退役 key 专用校验。
  • 删除 fork 与 resume / subagent_type / model 的兼容校验,以及 fork 专属 reminder。
  • 从 SubagentSpawnPlan、AgentRunSpawnedMeta 和 subagent_created 遥测中删除 fork 字段。
  • 保留旧会话恢复所需的 forkedFrom metadata、通用 lifecycle fork、BTW 和 /fork 会话路径;本 PR 没有修改 wire/state manifest 或历史会话格式。
  • 同步删除中英文当前配置文档中的环境变量条目;历史 changelog 作为已发布历史保留。

阅读顺序:

  1. packages/agent-core-v2/src/agent/tools/agent/agent.ts 与 agentTool.ts:确认 Agent 契约和执行分支。
  2. packages/agent-core-v2/src/features/swarm/tools/agent-swarm/:确认 swarm 参数与批量 spawn plan。
  3. packages/agent-core-v2/src/session/subagent/spawn.ts 与 subagentService.ts:确认最终只剩普通创建路径。
  4. packages/agent-core-v2/src/app/telemetry/events.ts、docs/{en,zh}/configuration/env-vars.md:确认遥测和公开配置同步。

其余改动主要是专属测试删除、普通测试夹具收敛、changeset 和 test-double 基线下降。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Agent 输入 启用 subagent_fork 后可传 fork: true schema 不再公布 fork,带该参数的调用会被工具参数校验拒绝 在 TUI、print、desktop/web、VS Code、ACP、SDK 或 KAP 驱动会话中使用该实验参数的调用方 无等价开关;把必要上下文显式写进 subagent prompt
AgentSwarm 输入 启用后可让所有 item spawn 继承调用方历史 schema 不再公布 fork,批量调用只能创建普通 subagent 使用实验性 fork swarm 的调用方 无等价开关;把共享上下文写进 prompt_template
Agent 工具指导 指导句子要求模型通过 fork: true 继承当前类型、模型和工具集 指导删除;schema 和普通创建路径约束模型行为 依赖该提示句子自动选择 fork 的模型行为 在任务 prompt 中显式提供上下文
AgentSwarm 工具指导 指导句子要求模型通过 fork: true 让每个 item subagent 继承调用方历史 指导删除;schema 和普通批量创建路径约束模型行为 依赖该提示句子自动选择 fork swarm 的模型行为 在 prompt_template 中显式提供共享上下文
实验开关 KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK、[experimental].subagent_fork 或总开关可启用功能 flag 不再注册或出现在实验功能列表;残留的 [experimental].subagent_fork 与其他未注册实验 ID 一样被忽略,同 section 的其他有效 flag 保持生效 已配置该环境变量或 config key 的 experimental flag 用户 可从配置中删除失效 key;无功能等价开关
subagent 历史 fork spawn 复制调用方已完成对话快照,并追加“这是参考快照而非自身历史”的 reminder 新 subagent 从普通空上下文开始,只接收本次 prompt 依赖隐式继承历史的 experimental 用户 在 prompt 中传入所需上下文
profile、model 与工具 fork spawn 继承调用方 profile/model/tool set,并跳过普通 allowlist、unknown-profile 和 secondary-model 选择 新 subagent 始终执行普通 profile/allowlist/model 校验并按该 profile 配置工具 依赖 fork 绕过这些约束的调用方 选择合法的 subagent_type / model
环境与 prompt prefix fork spawn 不获取 process lease,也不应用目标 profile prompt prefix 新 subagent 始终获取调用方环境 lease,并应用目标 profile prompt prefix 依赖 fork 跳过环境或 prefix 的调用方 使用普通 subagent profile 契约
subagent_created 遥测 事件包含布尔字段 fork 字段删除 消费该内部遥测属性的分析管道 停止读取该字段;无兼容字段
legacy config migration migration 识别并保留已注册的 subagent_fork 该 key 不再注册,因此 legacy migration 会过滤它 从 ~/.kimi/ 迁移且配置了该 flag 的用户 无需迁移该失效设置
旧会话与通用 fork forkedFrom metadata、wire 数据、BTW、/fork 和 lifecycle fork 可用 保持不变;本 PR 只禁止通过 Agent / AgentSwarm 新建 context-fork subagent 旧版本写入的会话、BTW 用户、/fork 用户 N/A

受影响模块与覆盖:

  • Agent / AgentSwarm schema:两条断言固定 fork 不再出现。
  • 普通 subagent planning/spawn:覆盖 profile allowlist、model binding、环境 lease、prompt prefix、用户工具继承和错误包装。
  • swarm:覆盖普通 item spawn、resume、并发、超时和结果渲染。
  • 持久化与 BTW:保留 reminder 恢复、压缩后注入、BTW request parity、后台 subagent 中断与 replay 覆盖。
  • flag/config:TUI experiments、KAP /meta 与 SDK telemetry 测试改用仍存在的实验 flag;继续由现有测试固定未注册实验 ID 的容忍行为。
  • 文档:中英文环境变量表镜像删除,VitePress 构建通过。
验证记录

通过:

  • pnpm lint
  • pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit
  • pnpm exec tsc -p packages/node-sdk/tsconfig.json --noEmit
  • pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit
  • pnpm exec tsc -p packages/migration-legacy/tsconfig.json --noEmit
  • 九个相关测试文件:294 tests passed,另有一项既存失败,详见下方基线核对
  • migration config:34 tests passed
  • tool.test.ts -t 'removed':7 tests passed
  • SDK 实验 flag 定向用例:1 test passed
  • flag/config 与 KAP /meta:36 tests passed
  • TUI experiments:8 tests passed
  • 两个 SDK 定向用例:均通过
  • pnpm -C docs run build
  • pnpm changeset status
  • pnpm run check:duplication 634db7a7a9d656cf72289a012b59bca6edb963c2

基线失败核对:

  • 九个相关测试文件得到 294 passed / 1 failed。
  • 失败为 sdk-rpc-client-v2.test.ts 的 serves suggestFiles through the workspace handler fs service:默认建议包含 ignored-app.ts。
  • 在未修改的 base 634db7a7a9 独立 worktree 中单独运行同一用例,得到相同断言失败;本 PR 没有修改文件建议逻辑或该用例。

Changeset:

  • @moonshot-ai/agent-core-v2: patch
  • @moonshot-ai/migration-legacy: patch
  • @moonshot-ai/kimi-code-sdk: minor
  • @moonshot-ai/kimi-code: minor
  • kimi-code-app: minor
  • kimi-code: minor

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).(无 issue;本 PR 实现维护者直接提出的实验功能下线要求。)
  • 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 Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: de97dcd

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

This PR includes changesets to release 5 packages
Name Type
@moonshot-ai/kimi-code Minor
@moonshot-ai/agent-core-v2 Patch
kimi-code-app Minor
@moonshot-ai/kimi-code-sdk Minor
kimi-code Minor

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

@7Sageer
7Sageer force-pushed the chore/remove-subagent-fork branch from 25d5b2a to e110723 Compare November 23, 2026 05:53
@7Sageer

7Sageer commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T07:26:47.090909Z 0992d81 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@7Hanrui

7Hanrui commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@codex review

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

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

surface: 'core',
};

registerFlagDefinition(subagentForkFlag);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject stale subagent_fork configuration

When an upgrade leaves [experimental].subagent_fork = true in config.toml, removing this registration does not make the setting invalid: ExperimentalConfigSchema still accepts any boolean key and FlagService only evaluates registered definitions, so startup succeeds, /meta drops the flag, and the user's explicit setting has no effect. Add retired-key validation with a clear removal error instead of silently accepting this configuration.

AGENTS.md reference: AGENTS.md:L118-L118

Useful? React with 👍 / 👎.

@@ -0,0 +1,5 @@
---
"@moonshot-ai/agent-core-v2": patch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the SDK removal changeset

Standalone @moonshot-ai/kimi-code-sdk consumers receive the removed tool schemas too, because packages/node-sdk/tsdown.config.ts bundles every @moonshot-ai/* dependency and this commit updates SDK integration tests for the new core behavior. None of the new changesets names the SDK, so its next build can ship this user-visible removal under only unrelated pending release notes; add an SDK changeset that describes the lost experimental parameter.

AGENTS.md reference: AGENTS.md:L169-L170

Useful? React with 👍 / 👎.

@7Sageer
7Sageer force-pushed the chore/remove-subagent-fork branch from e110723 to de97dcd Compare November 23, 2026 06:22
@7Hanrui

7Hanrui commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@codex review

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

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

@@ -0,0 +1,5 @@
---
"@moonshot-ai/agent-core-v2": patch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the migration-legacy changeset

This diff changes packages/migration-legacy/src/steps/config.ts so legacy migrations no longer register or preserve subagent_fork, but none of the new changesets names @moonshot-ai/migration-legacy. That leaves this changed library without the required version/changelog entry; add a technical changeset for that package.

AGENTS.md reference: AGENTS.md:L169-L170

Useful? React with 👍 / 👎.

Comment on lines +17 to +20
.refine((flags) => !('subagent_fork' in flags), {
path: ['subagent_fork'],
message:
'The experimental flag "subagent_fork" was removed. Remove it from [experimental] in config.toml.',

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 Align the SDK validator with the retired flag rule

For SDK consumers that call the exported createKimiConfigRpc().validateConfigToml (or loadRuntimeConfigSafe), this refinement exists only in the core registry: packages/node-sdk/src/config/schema.ts still accepts every boolean experimental key, and config-rpc.ts validates through that schema. Consequently [experimental].subagent_fork = true is reported valid by the SDK even though engine startup and config writes now reject it here; update the SDK schema and its validator tests as well.

AGENTS.md reference: AGENTS.md:L118-L118

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 0992d81560

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

@7Sageer
7Sageer marked this pull request as ready for review November 23, 2026 07:22

@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: 0992d81560

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

requested ?? (fork ? (own.profileName ?? DEFAULT_PROFILE_NAME) : DEFAULT_PROFILE_NAME);
input.profileName !== undefined && input.profileName.length > 0
? input.profileName
: DEFAULT_PROFILE_NAME;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve an escape hatch for opted-in context forks

For users who opted into context forking, this now defaults an omitted subagent_type to coder, and the spawn path always creates a fresh agent, so there is no way to retain the old behavior. The changeset records the loss, but the diff provides neither an escape hatch nor a test preserving that behavior; the repository requires a test and either an escape hatch or explicit maintainer sign-off before deleting it.

AGENTS.md reference: AGENTS.md:L195-L197

Useful? React with 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026

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

commit: 0992d81

@7Sageer
7Sageer merged commit 314a6bd into MoonshotAI:main Nov 23, 2026
38 of 39 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
Remove the experimental `fork` parameter from the Agent and AgentSwarm
tools (MoonshotAI#5254): the subagent_fork flag and its /experiments entry, the
schema parameters and flag-gated parameter sets, the lifecycle fork spawn
path and its reminder notice, the `fork` plan field, the subagent_created
telemetry field, the fork-only backend compatibility rule, and the pending
changeset that announced the feature. Docs drop the env var and the
parameter text in both locales; six changesets describe the removal for
the CLI, engine, desktop, migration, SDK and VS Code packages.

Fork adaptations: the external-backend parameter, the subagent depth
labels and the fork's DI shapes stay. The unrelated model-with-resume-only
rejection that the merge resolution had carried from the still-pending
MoonshotAI#5190 is dropped, so the fork keeps ignoring `model` when resuming without
items. The port also fixes two defects in that resolution which the tests
exposed: planSpawn reads the caller profile through IAgentProfileService,
and spawn passes the computed labels so the subagentDepth label survives.

Verified: agent-core-v2 affected files 285 pass / 2 fail, both failures
pre-existing at 2fa1821 (tool.test registered-user-tools wire snapshot,
forkParity TaskStop timeout); swarm 32, sessionSwarm 50, spawn 22,
experiments 13, node-sdk flags 1, node-sdk prompt events 18, kap-server
meta 10; typecheck clean for agent-core-v2, kap-server, node-sdk and
kimi-code; check:no-comments and the locale gates green.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
The MoonshotAI#5254 row carried the counts from the interrupted first pass: 285
pass / 2 fail with both called pre-existing. Re-running the six-file set
through the package's own 30s timeout gives 286 pass / 1 fail, and the
forkParity TaskStop case passes in 10.4s, so only the tool.test
registered-user-tools snapshot is red and its block and producers are
unchanged since a512a85.

Record the measured figures and drop the per-file counts the first pass
did not measure.
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