[Fix] 稳定 prompt pick 选择结果#878
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough将 {pick(...)} 从每次随机选择改为会话/种子感知的稳定选择:在 selectFromList 中加入可选 seed 并用 SHA‑1 哈希产生确定性索引;在 Prompt renderer 中根据 cfg 的 conversationId 传入 seed;相关测试已补充。 ChangesPick 函数稳定选择
Sequence DiagramsequenceDiagram
participant PromptRenderer
participant PickFunction
participant SelectFromList
participant SHA1
PromptRenderer->>PickFunction: call pick(args, _variables, cfg)
PickFunction->>SelectFromList: selectFromList(args.join(','), true, cfg?.conversationId ?? '')
SelectFromList->>SHA1: compute SHA-1(`${seed}:${args}`)
SHA1->>SelectFromList: return hash bytes
SelectFromList->>SelectFromList: idx = readUInt32BE(0) % items.length
SelectFromList->>PromptRenderer: return selected item
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request implements stable selection for the pick function provider by introducing a seed-based hashing mechanism in selectFromList. The seed is derived from session and conversation metadata to ensure deterministic output. A critical issue was identified in prompt_renderer.ts where accessing properties on an optional configuration object could lead to runtime crashes; using optional chaining was suggested to mitigate this risk.
|
已根据 Gemini Code Assist 的建议补充处理:
本地验证:
|
|
确实,这里原来的实现想得太宽了。 我已经把 seed 收敛到 另外补了两个用例,覆盖无 |
|
这个也改掉了:调用处不再 |
|
大佬我先睡啦,早点休息 |
|
A conversation must be resolved before this pull request can be merged. |
好的佬,我明天中午做 |
83bc1f9 to
ff6455b
Compare
|
已处理:
当前 GitHub API 显示 4 个 commit verification 都是 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/utils/string.ts`:
- Around line 320-324: Change the selectFromList signature to require seed be a
string (not unknown) so the function contract matches actual usage; update the
parameter in the export of selectFromList (the seed parameter default can remain
''), and adjust any callers or tests if they were passing non-strings so they
cast/convert to string before calling; this makes the template literal
`${seed}:${args}` type-safe and clearer in the selectFromList function.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5b54039d-5459-4904-8a21-85b2ac605bb1
📒 Files selected for processing (3)
packages/core/src/services/prompt_renderer.tspackages/core/src/utils/string.tspackages/core/tests/conversation-utils.spec.ts
|
等下次版本发布的时候会跟着一起发的!建议多测一下 1.4 alpha 的 bug,稳定了我们直接发正式版了 |
关联 Issue
Fixes #877
问题
{pick(...)}之前和{random(...)}一样每次渲染都走Math.random(),同一会话中的系统提示、作者注记或用户提示可能在连续请求里选到不同分支,导致角色语气、称呼或提示词约束漂移。修复内容
selectFromList增加稳定种子参数。pick使用会话/对话上下文和候选列表生成 SHA-1 哈希,稳定映射到同一个候选值。random原有随机行为不变。selectFromList的稳定选择测试。验证
COREPACK_HOME=/tmp/corepack corepack yarn fast-build shared-prompt-rendererCOREPACK_HOME=/tmp/corepack corepack yarn fast-build coreCOREPACK_HOME=/tmp/corepack corepack yarn mocha -r tsconfig-paths/register -r esbuild-register -r yml-register --exit packages/core/tests/conversation-utils.spec.tsCOREPACK_HOME=/tmp/corepack corepack yarn eslint packages/core/src/services/prompt_renderer.ts packages/core/src/utils/string.ts补充说明:全量
COREPACK_HOME=/tmp/corepack corepack yarn test当前有 10 个既有失败,失败点在归档、回滚、测试桩和缺失的 extension-agent 文件路径;本次新增的selectFromList用例在全量输出和单文件测试中均通过。