Repository navigation
feat(kap-server): add profile_revision and missing_model to agent state - #5449
Conversation
Agent settings reach clients through two channels: the /profile response and the batched agent frames. Add a profile_revision that changes only when the settings change, so clients can drop stale states whichever arrives first, and report a removed main-agent model alias in missing_model while model stays omitted for older clients. Mark the setting fields on prompt submissions as deprecated in the schema and kap.md.
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. |
🦋 Changeset detectedLatest commit: 972b1cf 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: 11a41db1bd
ℹ️ 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".
Removing the saved model from the config only changed the models section, which the agent feed ignored, so connected clients never saw missing_model until another agent event. Refresh agent frames on models and providers changes, and document that clients reset revision ordering after a reconnect because revisions are not persisted across restarts.
A provider model refresh can also drop the alias a session saved, and it only publishes ModelCatalogChanged. Refresh every live session's agent frames on that event too.
…eat/kap-agent-profile-revision # Conflicts: # packages/kap-server/test/apiSurface.test.ts
Requirement or Bug
Desktop 和 Web 同步会话设置(模型、思考强度、权限、plan / swarm / tower)时,修改结果从两路回来:
POST /sessions/{id}/profile的 HTTP 响应立即返回,WSagent帧在连接上攒 16ms 批量发送。两路之间没有任何顺序依据,客户端会把较旧的状态当成最新的,出现设置闪回,目前只能靠在写入后回放缓存帧这类补丁规避。另外,主 agent 的模型被从配置里删除时,推送里的model被省略,和「根本没有配置模型」无法区分。这个 PR 只改服务端契约,而且只做新增:给 agent 状态加上
profile_revision和missing_model,并把 prompt 上的设置字段标为弃用。客户端据此改造的部分在后续 PR。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:
readAgentState是 HTTP 响应和 WS 帧共同的读取入口。在这里按 agent 记住上一次的设置快照,设置变了才发一个新的、进程内单调递增且不小于当前时间的profile_revision;设置没变就沿用原值。这样无论哪一路先到,客户端都可以只接受 revision 不低于已知值的设置。profile_revisionagent帧、/profile响应的agentmissing_model关键决策
readAgentState里比对设置快照AgentState就自动被覆盖max(上一次 + 1, Date.now()),进程内全局单调missing_model)status、compacting、*_availablemodel仍然省略,另加missing_modelmodel再加状态字段model缺失来弹出选择模型的对话框(#5212),改了model会让它们把消息发给已删除的模型models、providers配置变化和ModelCatalogChangeddeprecated,行为不变plan_mode、goal_*报错plan_mode,Desktop 可能连到更新版本的服务端或 SSH 远程主机,报错会让侧聊不可用HOST_API_LEVELHOST_CONTRACTdigestcontract.txt的变化只有新增的可选字段,旧客户端和旧远程主机都不受影响阅读指南
packages/kap-server/src/transport/ws/v1/agentState.ts:revision 和missing_model的全部逻辑。packages/kap-server/docs/kap.md:新增的「Agent state」一节,写给外部调用方的使用规则。tests/scenarios/conversation.test.ts:新增的场景测试,演示 HTTP 响应和 WS 帧的 revision 一致。protocol/ws-agent.ts、protocol/rest-prompt.ts是 schema 声明,schema/下是生成文件,apiSurface.test.ts只改了 digest,可以略读。Behavior Changes and Affected Users
agent帧和/profile响应里的 agent 状态profile_revisionprofile_revisionmodelmodel,另带missing_model: "<原 alias>"model缺失来弹框的旧 Desktop / Web,行为不变POST /prompts、/steer上的model、thinking、permission_mode、plan_mode、swarm_mode、goal_objective、goal_controldeprecated,kap.md 写明前四个仍会在提交时修改会话、后三个一直被忽略profile_revisionmodels/providers变化,或模型目录刷新(ModelCatalogChanged)时的 WSagent帧受影响模块和测试覆盖:
kap-serveragent 状态:tests/scenarios/conversation.test.ts新增用例,覆盖改权限后 HTTP 响应和 WS 帧的 revision 相同且变大,只改标题时 revision 不变;packages/kap-server/test/sessions.test.ts现有的「模型被删除」用例补充断言,覆盖missing_model和重启后 revision 仍然变大。packages/kap-server/test/sessions.test.ts新增用例,客户端保持连接时从配置删除模型,收到带missing_model的帧;sessionEventBroadcaster.test.ts新增用例覆盖ModelCatalogChanged。两者在去掉修复后都会失败。packages/kap-server/test/apiSurface.test.ts的 digest 随contract.txt更新,openapi.test.ts通过。本地运行的检查
pnpm lint:通过pnpm exec tsc -p packages/kap-server/tsconfig.json --noEmit:通过pnpm exec vitest run packages/kap-server/test/apiSurface.test.ts packages/kap-server/test/openapi.test.ts packages/kap-server/test/sessionEventBroadcaster.test.ts packages/kap-server/test/prompts.test.ts packages/kap-server/test/sessions.test.ts tests/scenarios/conversation.test.ts:356 个用例中首次 1 个失败,原因是场景环境的默认权限就是 yolo、测试又设成 yolo,设置没变所以 revision 不变(符合设计);把测试改成切到 manual 后,conversation.test.ts28 个用例全部通过pnpm run check:duplication <base>:没有新增重复pnpm exec vitest run packages/kap-server/test/sessionEventBroadcaster.test.ts packages/kap-server/test/sessions.test.ts tests/scenarios/conversation.test.ts263 个用例全部通过;pnpm lint、kap-server 类型检查通过Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.