Skip to content

fix(storage): enforce Mooncake correctness contracts - #5

Open
overloadedHenry wants to merge 2 commits into
redai-studio:mainfrom
overloadedHenry:fix/mooncake-loss-guards
Open

fix(storage): enforce Mooncake correctness contracts#5
overloadedHenry wants to merge 2 commits into
redai-studio:mainfrom
overloadedHenry:fix/mooncake-loss-guards

Conversation

@overloadedHenry

Copy link
Copy Markdown

fix(storage): 强化 Mooncake 正确性契约

背景

本 PR 根据 redai-infra/Relax#278 中维护者的要求,将 Mooncake 正确性修复提交到 TransferQueue 上游,不再由 Relax 通过运行时 monkey patch 维护。

当前 MooncakeStore 路径存在三类可能被错误视为成功的失败场景:

  1. 批量写入或读取的重试调用可能返回少于请求 key 数量的结果码;
  2. batch_remove 失败时只记录日志,不向调用方传播错误;
  3. production-status 通知缺少 ACK 或收到负 ACK 时,producer 不会明确失败。

这些情况可能使不完整的存储操作或被 controller 拒绝的 readiness 更新继续执行,形成静默数据丢失风险。

修改内容

校验每一次 Mooncake 批量调用的返回结果

新增统一的结果数量校验,并应用于:

  • batch_upsert_from 的首次调用和每次重试;
  • batch_get_into 的首次调用和每次重试;
  • batch_remove

每次调用都必须为每个请求 key 返回且仅返回一个结果码。返回值不可计算长度或结果数量不匹配时,立即抛出 RuntimeError

删除失败时显式报错

MooncakeStoreClient.clear() 现在会:

  • batch_remove 返回数量异常时抛错;
  • 在出现非零且不可幂等处理的删除错误时抛错;
  • 继续将 Mooncake 的 -704(对象不存在)视为幂等删除成功。

production-status 必须收到正 ACK

Storage notification 现在采用 fail-closed 语义:

  • controller 信息缺失时立即抛错;
  • 使用绝对 deadline 等待 ACK;
  • 只有 NOTIFY_DATA_UPDATE_ACKsuccess is True 才视为成功;
  • 负 ACK、等待超时和接收异常都会向调用方传播;
  • 成功和异常路径都会关闭 notification socket。

行为变化

场景 修改前 修改后
批量调用返回结果过短 可能被当作成功 显式抛错
批量调用返回值不可计算长度 可能间接失败 使用稳定错误显式抛错
batch_remove 失败 只记录日志 显式抛错
production-status 缺少 ACK 或收到负 ACK 记录日志或被视为完成 producer fail closed
删除不存在的对象(-704 允许 继续允许

测试覆盖

本次修改增加了以下测试场景:

  • batch_upsert_from 重试返回结果过短;
  • batch_get_into 重试返回结果过短;
  • 批量调用返回不可计算长度的结果;
  • batch_remove 返回结果过短或删除失败;
  • -704 幂等删除;
  • controller 信息缺失;
  • production-status 正 ACK 和负 ACK;
  • ACK 等待超时;
  • notification socket 在连接失败时正确关闭。

相关测试文件:

  • tests/test_mooncake_utils.py
  • tests/test_storage_manager_notifications.py

兼容性与风险

  • 不修改 storage payload 格式或公开配置;
  • 成功的 Mooncake 操作保持原有行为;
  • 过去在 storage 或 notification 失败后仍会继续运行的任务,现在将显式失败,这是为了避免静默数据丢失的预期行为变化;
  • 保留对象不存在(-704)的幂等删除语义。

后续工作

本 PR 合入后,Relax 需要将 TransferQueue pin 更新到包含本修复的版本或 commit,并删除临时的 Mooncake runtime patch 及其调用点。

关联 PR

Copilot AI lite review requested due to automatic review settings August 24, 2026 06:32

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 26, 2026 17:27

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants