Skip to content

fix(crates/panache-mcp): 稳定工具目录中的随机种子描述 - #29

Merged
SXP-Simon merged 1 commit into
mainfrom
fix/mcp-stable-seed-schema
Nov 25, 2026
Merged

SXP-Simon merged 1 commit into
mainfrom
fix/mcp-stable-seed-schema

Conversation

@SXP-Simon

@SXP-Simon SXP-Simon commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

问题

Style::default() 为新稿生成随机 seed。生成工具 schema 时也执行了该默认逻辑,导致任意一个取样值被写成 save_section.style.seed.default。它并不代表下一次省略 seed 的实际值;甚至同一 MCP 会话反复查询也可能不同。

改动

只用 schemars 的字段 transform 移除 Style.seed 输出 schema 的 default。不改变类型、可选性、字段语义和运行时随机生成;显式 seed 仍可用于复现。新增同一结构的专项单元测试。没有编辑 #27 对 Tune 的保护条件;两份补丁的适用检查通过。

本地验证

基线 e1e2546a 与独立候选分别构建,Rust 1.94.1、真实 Markdown worker、Python MCP SDK 1.29.0,协商协议均为 2025-11-25。每臂 8 个独立进程,每进程查询三次完整工具目录并写三份合成新稿:

判据 基线 候选
8 次启动的首份目录不同摘要个数 8 1
同会话 3 次目录出现漂移 6/8 0/8
省略 style 的 8 份稿件中不同存储 seed 个数 8 8
提供 style 但省略 seed 的不同存储值个数 8 8
显式 seed 42 原样写入 8/8 8/8

仅在基线目录忽略该随机字段后,与候选所有目录的规范化摘要完全相同。通过 cargo test --locked -p panache-mcp seed_schema_tests;使用当前二进制真实调用 save_section 并以 SQLite drafts.style 验证。以上是可复现性修复,不把它描述成已证实的客户端缓存故障或 MCP 规范違例。

草稿,不加标签,不手动触发 Actions。

Summary by Sourcery

Remove the random Style seed default from generated schemas while preserving existing runtime and serialization behavior.

Bug Fixes:

  • Prevent the randomly generated Style seed from being exposed as a misleading default in generated tool schemas, eliminating schema instability while preserving runtime seed generation and explicit-seed reproducibility.

Tests:

  • Add focused schema tests covering deterministic generation, seed optionality, preservation of other defaults, deserialization, and explicit seed round-tripping.

背景:Style 默认会生成随机 seed。schemars 把生成 schema 时的随机取样作为固定 default 暴露,导致重复工具发现的目录可不同。

解决手段:仅对 Style.seed 的 schema 删除该 default,并用专项回归固定类型、可选性和显式种子的反序列化。运行时仍按原逻辑给省略 seed 的稿件随机分配。

收益:8 个本地真实 MCP 会话各 3 次查询,候选 24 份目录稳定一致,显式和省略三类保存行为保持。便于对照实验与一致地描述客户端能力。
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Remove the random seed default from Style's generated schema while preserving the field's runtime behavior and public shape.

  • crates/panache-mcp/src/inputs.rs L36-42

Tests

Add regression coverage for stable schema output, seed optionality, unchanged defaults, and explicit seed deserialization and serialization.

  • crates/panache-mcp/src/inputs.rs L302-331

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Owner Author

重复查询与实际保存的核对

  • 基线统一目录的实际握手协议均为 2025-11-25。示例:同一次会话连续查询的 seed.default 为 413393065, 3673945197, 413393065,并不是单次启动内固定不变。
  • 每个进程使用独立临时 MCP home,从 Python SDK 分别三次调用 list_tools,按键排序后取紧凑 JSON 整体 SHA-256。8 个基线进程首个原始摘要各异,去掉且仅去掉 save_section.style.seed.default 后,24 份统一为 c760d7c2433c030b2cbdba56f00aa00d23372925282388978e9587e0cbf74b78;候选 24 份未经任何删减的摘要和它相同。
  • 每个进程另通过实际 stdio 保存三份相同正文的合成稿:省略 style、提供 style 但省略 seed、显式 42。以 SQLite drafts.style 中的值为准;两种省略在两臂都各生成 8 个不同值,显式 42 两臂都 8/8。无需依赖随机种子是否恰好匹配某个目录取样。
  • 复跑:cargo test --locked -p panache-mcp seed_schema_tests 并使用隔离的 cargo build --locked -p panache-mcp 构建两臂;设置正式字体和文本 worker 路径,循环进行 initialize/list_tools 三次和上述保存。比对完整 schema,不要顺便忽略其他差异。
  • 这是单独的 schema 属性而非 Style::default() 更改;不宣称所有客户端填充默认值,也不宣称新旧发布二进制可互换。

@SXP-Simon
SXP-Simon marked this pull request as ready for review November 25, 2026 12:04
@SXP-Simon
SXP-Simon merged commit 642f758 into main Nov 25, 2026

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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