Repository navigation
feat: FrameError 事件增补会话归属与快照完整性元数据(#56) - #57
Merged
Merged
Conversation
added 3 commits
August 29, 2026 21:57
- FrameErrorEventArgs 新增 SessionId / ObservedByteCount / IsTruncated: SessionId 与 CurrentSessionId/SessionMessage.SessionId 同一编号空间, 事件在解码器内构造时绑定会话——重连后迟到的旧会话事件仍带旧编号; ObservedByteCount 恒 >= Bytes.Length(含义按 Kind 分化,XML 文档附语义表), IsTruncated 在构造函数内自动计算,杜绝与 ObservedByteCount 不一致 - FrameDecoder 四处事件构造传入 _sessionId 与实际观测字节数 (DecodeFailed=负载长、DiscardedByResync=丢弃长、Timeout=pendingBytes、 Overflow=buffer.Length) - 旧构造重载保留并委托新重载(源/二进制兼容);README 双语示例同步
- FrameDecoderTests:既有四类 Kind 事件补 SessionId/ObservedByteCount/IsTruncated 断言;新增 overflow 超 8KB 快照上限的截断上报(ObservedByteCount=9228、 Bytes=8192 前缀);新增"会话编号构造时绑定"测试——旧解码器(7)的事件不因 新解码器(8)存在而改写 - IncompleteFrameTimeoutTests:小半帧全量上报、9KB 半帧截断上报、双轮超时 编号随会话递增(1→2);重连后断言旧事件编号仍为 1 而当前会话已为 2 - ConnectionResilienceTests:DecodeFailed 在 Retry 窗口断言事件编号为 1 而 CurrentSessionId 已归零(回调时刻读当前编号无法归属的实证);SkipFrame 同会话编号一致;overflow 全量上报 + Retry 窗口编号归零 - SessionAwareConnectionTests 新增:DiscardedByResync(唯一不断开的 Kind) 跨会话重建,事件仍带来源会话编号(1 与 2),与当前会话严格区分
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.
摘要
实现 #56:
FrameError事件增补会话归属与快照完整性元数据。评审意见见 issue #56 评审评论,本 PR 按评审结论实现(采纳首选方案:直接增补FrameErrorEventArgs,否掉另开事件源的替代方案)。API(源/二进制兼容的纯增量)
observedByteCount: bytes.Length→IsTruncated恒 false),不变式自动成立。SessionId与CurrentSessionId/SessionMessage.SessionId同一编号空间,可跨 API 直接关联比对;事件参数在解码器内部构造、构造时绑定——重连后延迟到达的旧会话事件仍带旧编号(与消息通道的会话归属语义对齐,收口既有不一致)。ObservedByteCount含义按 Kind 分化(XML 文档附语义表):DecodeFailed=帧内负载、DiscardedByResync=被丢弃字节、Timeout/Overflow=半帧缓冲全长(含已收到的长度头)。实现要点
FrameDecoder四处事件构造传入_sessionId(此前被丢弃)与内部已知的实际字节数(payload.Length/discarded.Length/pendingBytes/buffer.Length)——只在错误路径上携带,零热路径成本。DecodeFailed/DiscardedByResync契约如实公开"完整拷贝"现状(ObservedByteCount == Bytes.Length && !IsTruncated);timeout/overflow超 8KB 快照上限时如实标记截断。回归测试(98 → 101,×3 TFM 全绿)
DiscardedByResync(唯一不断开的 Kind)跨会话重建仍带来源编号;解码器级"编号构造时绑定"(旧解码器 7 的事件不因新解码器 8 存在而改写)。DecodeFailed断言点CurrentSessionId已归零而事件携带 1——正是 issue 指出"回调时刻读当前编号无法归属"的场景。验证
dotnet build StreamFrame.slnx -c Release(0 警告 0 错误)dotnet test StreamFrame.slnx -c Release --no-build:net48 / net8.0 / net10.0 各 101 项通过Closes #56