fix(provider): 回放签名按块数对齐,长度不符整体丢弃 - #234
Conversation
assistantToHanaContent 此前按下标取 replay.blocks 里的签名,不做长度校验。 落盘消息一旦出现 content 与 replay.blocks 不等(例如宿主中断提交路径以 interruptedBlocks() 裁掉 tool-call 却保留完整 replayState),签名会挂到别的块上。 现按宿主 assembler 同一口径:块数一致才采用签名,否则整体丢弃。 新增 provider-messages 三例覆盖长度不等与错位防护。
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesReplay signature alignment
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable issue remains from this review; the PR is mergeable after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change prevents potentially misaligned replay signatures from being attached while preserving message content. No new privilege or destination is evident. Risk remains low rather than minimal because downstream handling of unsigned replay has not been established. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
背景
.tmp/zhipu-bugreport-reply.md第六节备案的回放块下标对齐隐患:DSHana 回放块按下标对齐,担心剪枝/压缩让content与replay.blocks长度不等时签名错位。核实结论
dsh-llm的assembler.assembled()在replay.blocks.length !== all.length时整体丢弃replayState,等长时blocks与 replay 用同一个kept同步 filter。一条消息内要么等长、要么 replay 为 undefined。agent.ts用live.interruptedBlocks()落盘内容(会裁掉 tool-call 与空白块),却仍带完整的live.replayState(按all.length校验)⇒ 落盘消息content短于replay.blocks。assistantToHanaContent的metaBlocks[i]只判对象存在,不校验长度。stream.ts的 index 分配与 content 顺序一致,streamed.has(index)不会误判,不改。改动
packages/provider/lib/messages.ts:metaBlocks仅在replay.blocks.length === blocks.length时采用,否则整体丢弃(与宿主 assembler 同口径)。只对齐长度,不逐块校验类型,其余行为不变。tests/cordis/provider-messages.test.mjs:+3 例(长度不等整体丢弃 / 短 meta 不错位 / 非 hana 信封不采用)。验证
单文件
node --test(沙箱下目录模式 spawn 受阻,按文件在进程内跑):git diff --check:干净判别力验证:把守卫临时改回无长度校验的写法,新增用例 2 例失败;恢复后全绿——用例确实锁住了该缺陷。
遗留(宿主侧,本 PR 不改)
真实缺口在 DSH 中断提交路径(
agent.ts内容与replayState口径不一致),属 vendored 上游代码,需另行跟进/上报。本 PR 是 DSHana 侧的纵深防御:不再因长度不等而错挂签名。Summary by CodeRabbit