fix: 管理员种子匹配缺口 + 通用技能 SKILL.md 走 system prompt 缓存 - #19
Open
JHdehao wants to merge 2 commits into
Open
Conversation
seed.py:管理员账号查找同时匹配 id=="admin" 或 username=="admin", 此前只按 id 匹配会在"id 不是 admin 但用户名是 admin"的场景插入 重复行、撞 (tenant_id, username) 唯一约束。 stage_protocol.py:render_stage_user_message 把静态的阶段规则/ 输出约束放到易变的时间戳/用户输入之前,避免每次调用都变化的内容 出现在 prompt 前部导致 DeepSeek 等 provider 的前缀缓存完全失效。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Plan/Repair/Review 三个会用到 SKILL.md 全文的阶段,之前把全文塞进 每轮都变化的 stage payload 尾部,导致同一个技能被连续调用时,DeepSeek/ Gemini 等 provider 的前缀缓存完全命中不到这部分内容,每轮都要重新计费。 改成通过 unified_system_prompt(skill_markdown) 把全文放进 system message(对同一技能的 Plan/Repair/Review 调用保持字节级一致), payload 里不再重复携带。Selector/Reply 两个阶段不需要全文,保持不变。 顺带修掉 _skill_package_payload 里 SKILL.md 被重复发送两遍的问题 (markdown 字段 + package.files 里的 content_preview 各发一份相同内容)。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
JHdehao
pushed a commit
to JHdehao/StaffDeck
that referenced
this pull request
Jul 18, 2026
这个分支是从干净的 upstream/main 切出来的,不带 PR OpenBMB#19 里已经修好的 管理员种子匹配 bug(commit ebba3e1),而本地数据库已经是用修复后的 代码种过的状态,用未修复的旧逻辑启动会直接因为主键冲突崩溃。 这个 commit 只是为了让本地开发环境能跑起来,等 PR OpenBMB#19 合并后这里 应该会被自然吸收/可以 drop,不需要单独提交上游。
Collaborator
|
我进一步检查了通用技能的权限链路,目前不建议按现状整体合并这个 PR。 管理员种子匹配修复是有效且有必要的,建议拆成独立 PR 合并。 Prompt 前缀缓存优化方向也合理,但当前实现把 建议拆分为:
例如保持固定的 StaffDeck system prompt,再把 SKILL.md 放进位于动态阶段输入之前的稳定 user/context message。这样仍然能够利用 provider 的前缀缓存,同时不会提升第三方技能内容的指令权限。 另外希望补充实际的 cache hit、input token 或延迟对比,确认这项调整确实产生收益。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
管理员账号种子逻辑(
backend/app/db/seed.py)查找管理员账号原本只匹配
id == "admin",如果种子时 id 不是 "admin"但 username 是 "admin",会插入重复行撞
(tenant_id, username)唯一约束。改成
id == "admin" OR username == "admin"双重匹配。prompt 前缀缓存排序(
backend/app/llm/stage_protocol.py)render_stage_user_message之前把易变内容(时间戳、用户本轮输入)排在静态大块内容(阶段规则/输出约束)前面,导致 DeepSeek 等 provider
的前缀缓存完全失效。改成静态内容在前、易变内容在后。
通用技能 SKILL.md 走 system prompt 缓存
(
backend/app/general_skills/runner.py,backend/app/llm/stage_protocol.py)Plan/Repair/Review 三个阶段之前把 SKILL.md 全文塞进每轮都变化的
payload 尾部,同一技能被连续调用时完全吃不到 provider 的前缀缓存。
改成通过
unified_system_prompt(skill_markdown)把全文放进 systemmessage(对同一技能保持字节级一致)。Selector/Reply 阶段不需要全文,
保持不变。
顺带修掉
_skill_package_payload里 SKILL.md 被重复发送两遍的问题。测试
test_general_skill_substages_share_base_prompt_with_skill_caching_suffix)。🤖 Generated with Claude Code