Skip to content

fix(kap-server): drop reserved metadata keys from session profile updates - #4842

Merged
wbxl2000 merged 2 commits into
release/2026-11-12from
fix/profile-metadata-reserved-keys
Nov 11, 2026
Merged

wbxl2000 merged 2 commits into
release/2026-11-12from
fix/profile-metadata-reserved-keys

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

POST /api/v1/sessions 会丢掉 metadata 里的保留键(cwd、goal、parent_session_id、child_session_kind),但 POST /api/v1/sessions/{session_id}/profile 会把它们原样写进会话的自定义元数据。通过 profile 接口可以把任意会话挂到另一个会话的子会话列表下,也可以把真正的子会话从父会话下摘掉。

Bug Reproduction Steps

  1. 创建两个会话 A、B。
  2. POST /api/v1/sessions/B/profile,body {"metadata": {"parent_session_id": "<A>", "child_session_kind": "child"}}。
  3. GET /api/v1/sessions/A/children 列出 B。

反过来,对一个真正的子会话写 {"metadata": {"parent_session_id": null, "child_session_kind": null}},它就不再出现在父会话的子会话列表里。

Root Cause

保留键的过滤只写在创建接口的路由里,profile 接口用请求的 metadata 整体替换会话的自定义元数据,保留键也跟着被客户端覆盖或删除。根本修复:保留键由服务端掌管。创建接口丢弃请求里的保留键;profile 接口替换时,新的自定义元数据 = 请求中的非保留键 + 会话已存的保留键。

Code Changes

 POST /sessions
-  inline destructure drops cwd / goal / parent_session_id / child_session_kind
+  customSessionMetadata(body.metadata)
 POST /sessions/{id}/profile
-  metadata.update({ custom: { ...body.metadata } })
+  metadata.update({ custom: { ...customSessionMetadata(body.metadata), ...reservedSessionMetadata(stored.custom) } })

profile 接口仍然是「请求的 metadata 非空就整体替换」,这个约定不变。

文档没有在这个 PR 里改:server-api.md 正在由 #4841 整页重写,两个 PR 都合入后,再在新的「会话接口」页补上 profile 接口丢弃保留键的说明,避免两边冲突。

Behavior Changes and Affected Users

行为 之前 之后 谁依赖旧行为 退路
profile 写 metadata.parent_session_id / child_session_kind 写入自定义元数据,改变子会话关系 请求里的值被忽略,会话已存的值保留 无已知调用方;子会话只应通过 POST /sessions/{id}/children 创建 无,旧行为是缺陷
子会话的 profile 只写普通键(如 { source }) 整体替换,父子关系被冲掉 父子关系保留 无 无,旧行为是缺陷
profile 写 metadata.goal 写入自定义元数据(读取时本来就会被丢掉) 忽略 无 无需
profile 写 metadata.cwd 写入 custom.cwd。会话读取时用真实工作目录覆盖它;只有既没有 v2 cwd、也没有 v1 workDir 的旧会话,索引会用 custom.cwd 作为工作目录,profile 写入任何 metadata 都可能改掉或冲掉它 请求里的值被忽略,已存的 custom.cwd 保留 desktop / web 的 updateSession 支持 cwd 参数,但现有代码路径都不传;没有其他调用方 无,工作目录本就不应通过 profile 修改
profile 写其他 metadata 键 整体替换 不变 — —

测试(packages/kap-server/test/sessions.test.ts):

  • profile 丢弃请求里的保留键、照常保存其他键,不会建立子会话关系;
  • 子会话写普通键、写 null 的父子键、回写别的父会话 id 三种情况,父子关系都保留;
  • 只写保留键的请求仍然整体替换自定义元数据。

创建接口原有的同类测试不变。

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 Nov 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e2b0f6e

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 Nov 11, 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-11T13:26:15.453454Z e2b0f6e New commits
ℹ️ 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 Nov 11, 2026 •

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

commit: e2b0f6e

@wbxl2000
wbxl2000 force-pushed the fix/profile-metadata-reserved-keys branch from 06046f1 to 2079c71 Compare November 11, 2026 13:15
@wbxl2000
wbxl2000 changed the base branch from main to release/2026-11-12 November 11, 2026 13:15

@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: 06046f1a24

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

@wbxl2000
wbxl2000 merged commit 421388b into release/2026-11-12 Nov 11, 2026
15 checks passed
@wbxl2000
wbxl2000 deleted the fix/profile-metadata-reserved-keys branch November 11, 2026 13:34
@github-actions github-actions Bot mentioned this pull request Nov 11, 2026
Grapedge added a commit that referenced this pull request Nov 12, 2026
* fix(agent-core-v2): truncate oversized skill content (#4834)

* fix(kap-server): bind the main agent when a session is created (#4839)

* fix(kap-server): bind the main agent when a session is created

* fix(kap-server): reject a profile on prompt submissions

* fix(kap-server): reject a profile change through the session profile

* fix(kap-server): wait for model configuration before binding a new session

* fix(agent-core-v2): deduplicate restored task notifications (#4836)

* fix(agent-core-v2): deduplicate restored task notifications

* chore: add notification replay fix changeset

* fix(agent-core-v2): preserve task notifications after prompt-only crashes

* fix(agent-core-v2): complete prompts before ending turns

* test: align lifecycle snapshots with prompt completion order

* fix(agent-core-v2): settle all prompts during turn finalization

* fix(kap-server): drop reserved metadata keys from session profile updates (#4842)

* fix(kap-server): drop reserved metadata keys from session profile updates

* fix(kap-server): keep stored reserved metadata keys on profile updates

* docs: split and rewrite the server API reference (#4841)

* docs: split and rewrite the server API reference

* docs: redirect old server API anchors to the split pages

* docs: describe profile metadata as a replacement

* docs: mark question responses as answered-only

* fix(kap-server): avoid heartbeat timeout after scheduling stalls (#4823)

* fix(kap-server): avoid heartbeat timeout reaping after stalls or clock jumps

* fix(kap-server): grace heartbeat window for short scheduling stalls

* fix(kap-server): treat only clearly late heartbeats as scheduling stalls

* fix(kap-server): time heartbeats on a monotonic clock and drain queued input before reaping

---------

Co-authored-by: Kimi Code (Grok Bot) <[email protected]>

* fix(kap-server): undo a turn only once when requests race (#4846)

* docs: describe heartbeat stall handling (#4849)

* docs: describe heartbeat stall handling

* docs: explain the monotonic clock in the heartbeat notes

* fix(agent-core-v2): acquire session lock before loop restoration (#4848)

* fix(agent-core-v2): acquire session lock before loop restoration

* chore: add session lock lifecycle changeset

* fix(agent-core-v2): hold session lock through loop restoration

- add an operation-scoped lease to the session run gate
- hold it across loop initialization, reset, and pending drains
- cover idle timeout and release ordering

* fix(agent-core-v2): keep the output of stopped tool calls (#4854)

* fix(kap-server): drop the partial reply of a retried step (#4855)

* fix(agent-core-v2): dedupe historical tool schemas (#4862)

* fix(agent-core-v2): dedupe historical tool schemas

* chore: add duplicate tool schema changeset

* fix(agent-core-v2): preserve first tool schema declaration

* fix(agent-core-v2): remind on changed tool schemas

* fix(agent-core-v2): block stale tool schema calls

* fix(agent-core-v2): normalize registry schemas in pending checks

* fix(agent-core-v2): import registry tool metadata type

* fix(agent-core-v2): preserve abort handling during validation

* fix(agent-core-v2): refine validation hook preparation

* fix(agent-core-v2): make validation hooks synchronous

* fix(agent-core-v2): preserve tool result notes on fork (#4867)

* fix(agent-core-v2): preserve tool result notes on fork

* chore: add fork tool result note changeset

* fix(agent-core-v2): scope tool result note restoration to forks

* fix(agent-core-v2): normalize inherited tool result notes

* fix(agent-core-v2): isolate fork note restoration

* feat(tui): sweep running titles toward text and add KIMI_CODE_TUI_ANIMATION_FPS (#4843) (#4870)

* chore: sync web dist from code-app (#4871)

code-app: 8ab17294e031323186d357d121c5360b8353900e

Co-authored-by: kimi-agent-bot <[email protected]>

* ci: release packages (#4835)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: sync web dist from code-app

code-app: 5835391dac3a2b9e0c65ffbd418f0d6042a7adb2

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: qer <[email protected]>
Co-authored-by: Kimi Code (Grok Bot) <[email protected]>
Co-authored-by: grapedge <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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