Repository navigation
fix(kap-server): apply agent_config and custom metadata when creating a session - #4778
Conversation
🦋 Changeset detectedLatest commit: a120646 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac1bbd582e
ℹ️ 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".
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b5c914b2d
ℹ️ 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".
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 714e52232d
ℹ️ 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".
…ession The profile route already treats an empty model as absent, but session creation counted it as a setting and created the main agent eagerly, so a no-op request could fail creation. Creation now drops the empty model before deciding whether to apply the config. Also pin that profile updates still carrying the fields removed from the schema keep succeeding.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af5d146084
ℹ️ 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".
…pply Session creation decided whether to apply agent_config by its key count, so a config holding only values the apply step never acts on, such as a lone tower_base, still created the main agent eagerly. Apply the config only when it carries a non-empty model or a setting other than tower_base, which is only read together with tower_mode.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 699366250e
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 699366250e
ℹ️ 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".
…done Entering Tower mode creates a branch, commits pending changes, and switches the worktree, and a goal setting applied after it could still fail and remove the new session while those changes stayed behind. Tower mode and goals are mutually exclusive, so creation now rejects tower_mode: true combined with goal_objective or goal_control during validation, before anything is created. The creation schema also required metadata.cwd whenever metadata was present, so a request addressing a workspace by workspace_id could not pass custom metadata without repeating the root. metadata.cwd is now optional there; the route still requires either workspace_id or cwd.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8629cf5a5c
ℹ️ 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".
…t-ignored # Conflicts: # packages/kap-server/test/sessions.test.ts
Profile updates apply agent_config through the same code as session creation, so they can fail with the same goal errors, but the route declared only the Tower mode failure. It now reuses the shared goal error set, and the creation docs list those codes and the new 40001 case.
Entering Tower mode switches the worktree to a new branch before steps that can still fail, such as the snapshot commit, and session creation cannot undo those repository changes when it rolls back. Rejecting only tower_mode combined with goal settings left that path open. Creation now rejects tower_mode: true during validation, so it never touches the repository; clients enable Tower mode through the session profile once the session exists, as code-app already does.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 737f047d99
ℹ️ 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".
Session creation now keeps custom metadata, and parent_session_id with child_session_kind are the keys the session index uses to list a session's children. An ordinary creation request carrying them made the new session show up as a child of any existing session. Creation drops them along with cwd and goal; only the child-session route sets them.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 404aecfb1f
ℹ️ 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".
… error The profile service rejects a thinking level the model does not support with model.config_invalid, which the error table did not map, so profile updates, prompts, and now session creation answered an invalid client setting with 50001. It now maps to 40001 like config.invalid, which an unknown model already raises. A test pins that creation with an unknown model returns 40001 and leaves no session behind.
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
Requirement or Bug
两个会话接口收下参数却不生效,调用方得不到任何提示:
POST /api/v1/sessions的请求 schema 接受agent_config和自定义metadata,但创建时只用metadata.cwd,其余都被丢掉。desktop 在用户选了模型后会随创建请求带上agent_config.model,这个字段不生效:desktop 只能在建好会话后再单独发一次 profile 请求补设模型和各模式,并先在本地把模型补到会话上显示。创建响应和event.session.created里的会话都没有模型。agent_config里的system_prompt、tools、mcp_servers和顶层的permission_rules,从来不应用它们,文档里也写着「schema 接受但不应用」。Bug Reproduction Steps
POST /api/v1/sessions,body 为{ "metadata": { "cwd": "…", "source": "composer" }, "agent_config": { "plan_mode": true } }。metadata里没有source,main agent 也没有进入 Plan 模式。Root Cause
创建路由只读取
metadata.cwd、title、workspace_id和 environment 字段,没有像 profile 路由那样应用agent_config,也没有保存自定义 metadata。profile 接口那四个字段则在实现时就没有接到任何能力上。这是根本修复:能接上现有能力的接上,接不上的从契约里删掉。
Code Changes
SessionStart/SessionEndhook,也不发出任何会话事件,接口返回对应的错误。applySessionAgentConfig拆出applyAgentConfigToSession(session, config),profile 路由和创建路由共用同一份应用逻辑。agent_config里没有应用步骤会执行的设置时(只有被删掉的字段、空字符串的model,或没有tower_mode的tower_base),不调用应用逻辑,不会提前创建 main agent。metadata.goal是目标功能保留的键,读取时本来就会被隐藏,创建时直接丢弃,不写入。parent_session_id、child_session_kind是会话索引列出子会话用的键,只有子会话路由会写入,创建普通会话时同样丢弃,避免伪造父子关系。tower_mode: true在校验阶段返回 40001,不登记工作区、不建会话。进入 Tower 会建分支、提交未提交的改动并切换工作树,其中有些步骤在可能失败的步骤之前执行,这些仓库改动无法随创建失败回滚。所以 Tower 只能在会话建好后通过 profile 接口开启,code-app 本来就是这么做的;会话创建这个可回滚的阶段因此完全不碰仓库。model.config_invalid→ 40001:模型不支持请求的思考强度时,profile 接口、提交输入和创建会话原来都返回 50001,现在与模型未配置时的config.invalid一样返回 40001。workspace_id时,metadata可以不含cwd,自定义 metadata 照样保存;目录仍由「workspace_id与metadata.cwd二选一」的校验保证。agent_config可能返回的目标相关错误(40913–40918、40920),OpenAPI 描述里能看到它们。server-api.md(中英)同步:创建接口的agent_config改为会应用,metadata写明保留键goal、parent_session_id、child_session_kind,agent_config写明创建时不能开启 Tower,错误码列表补上 40001 的新情况和目标相关错误;会话对象agent_config.model的说明补上创建响应;删掉 profile 接口「schema 接受但不应用」的说明。Behavior Changes and Affected Users
agent_configmetadata里cwd和保留键以外的键goal、parent_session_id、child_session_kind仍被丢弃)agent_config无法应用agent_configSessionStarthook 的时机model仍是默认模型(存量行为,未改)event.session.created和创建响应里的agent_config.model""tower_mode: trueworkspace_id、metadata不含cwdsystem_prompt/tools/mcp_servers/permission_rules契约:
agent-core-v2的sessionLegacy/sessionProtocol.ts(会话请求、响应 schema)、CreateSessionOptions(新增可选的prepare),以及 kap-server 的创建请求 schema(带workspace_id时metadata.cwd可省略;拒绝tower_mode: true)。消费者是 code-app 的 desktop / web,它们不发送、也不读取被删掉的字段。apiSurface快照没有变化。测试(
test/sessions.test.ts):agent_config并保存自定义 metadata。agent_config无法应用时,不留下会话,也不发出任何event.session.*事件。agent_config只有空字符串的model或单独的tower_base时,不创建 main agent。workspace_id创建时保存自定义 metadata。model.config_invalid映射为 40001(test/transport-errors.test.ts)。tower_mode返回 40001,不留下会话。「不创建 main agent」和「带着已删除字段的 profile 请求仍然成功」两个用例钉住的是本 PR 不能改变的行为,在改动前的代码上本来就通过;其余用例在改动前的代码上都会失败。
Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.