fix(channelbridge): 窗口准入落到车道头 + lane.go 按职责拆分(M23 复审 r1 P2)
P2-1(行为缺陷):窗口准入此前只在 prepareInbound 里算 `solo`,而 prepare 发生在 **窗口等待之后** —— 平台帧(action / 系统通知 / 我们自己的 message_sent 回执)照样 进窗、照样把滑动计时重置:一条回执就能把这一批的静默期一直续住(群友说了三句话, 她因为「撤回事件」迟迟不开口)。这与任务书「窗口只收 chat/image/voice/file」相反。 - `laneWindowAdmits(msg)` 成为**唯一准入判据**,只看结构化事实(ContentType + isSystemNoticeMessage,绝不解析正文); - `splitWindowItems` 在窗口等待阶段把到达的条目分成「进窗口」与「不进窗口」两半; - 非准入帧**不建窗口、不重置计时**(首条即到达即发车),窗口中途到达的只收进 solos, 这一批发车后**原样回插队首**各自单跑(保序、不合并、不丢弃); - prepareInbound 里的 `solo` 保留为第二道保险(适配器将来把平台事件标成 text 时, 仍会在组批前被切出去)。 P2-2(硬约束):lane.go 682 行 → 按职责纯搬移成 5 个文件(最大 246 行): lane.go(车道类型与注册表)/ lane_queue.go(入队与取队列)/ lane_worker.go(单消费者与回合槽)/ lane_drop.go(丢弃与停机诚实)/ lane_owner.go(主人私聊判据与车道键)。语义零改动:去注释后的声明集合 (34 个顶层声明,含函数体/字段/常量值)逐字节全等;既有用例一条未改。 顺带:把两处「IsOwner() && !IsGroupChat()」的注释改成代码真正用的判据 (ownerPrivateLane = !msg.IsGroup() && actor.IsOwner()),并记下这处 P3 分叉。 验证:全树 build/vet/test 全绿(73 包 ok);三包 -race 全绿; 新增 4 条准入用例在「准入失效」变异下三条必红、对照组保持绿。
This commit is contained in:
1 parent
ca8577f05b
commit
4c9cabce1b
10 files changed
+873
-527
No files matched your search
@@ -25,19 +25,29 @@ import (
|
||||
// 这段期间攒下的整片取出 ⇒ 一轮续跑(见 flushLaneBatch 的 continued 计数)。
|
||||
func (b *Bridge) runBatchLaneItem(ctx context.Context, l *lane, first laneItem) {
|
||||
w, windowed := b.coalesceWindowFor(l.key, laneStrangerPrivate(first))
|
||||
if !windowed {
|
||||
// 关窗(或该会话不适用窗口):行为**逐字回到 M22** —— 到达即投递、一条一轮。
|
||||
// 刻意**不** takeAll:多取的条目会让「特性关闭」变成「悄悄合并」。
|
||||
if !windowed || !laneWindowAdmits(first.msg) {
|
||||
// 三种「到达即发车」:关窗(逐字回到 M22)、该会话不适用窗口、以及**不进窗口的帧**
|
||||
// (系统通知 / action 帧 / 我们自己的出站回执)。最后一种刻意**不**建窗口:
|
||||
// 一条回执不该让这一批的静默计时重新开始(M23 任务书的窗口准入条件)。
|
||||
// 刻意**不** takeAll:多取的条目会让「不合并」变成「悄悄合并」。
|
||||
b.flushLaneBatch(ctx, l, []laneItem{first}, w, false, coalesceFlushOff)
|
||||
return
|
||||
}
|
||||
items := append([]laneItem{first}, b.takeAll(l)...)
|
||||
items, solos := splitWindowItems(b.takeAll(l))
|
||||
items = append([]laneItem{first}, items...)
|
||||
var flushReason string
|
||||
items, flushReason = b.coalesceWait(ctx, l, items, w)
|
||||
var moreSolos []laneItem
|
||||
items, moreSolos, flushReason = b.coalesceWait(ctx, l, items, w)
|
||||
solos = append(solos, moreSolos...)
|
||||
if flushReason == coalesceFlushStop {
|
||||
b.abandonAtStop(l, items)
|
||||
b.abandonAtStop(l, append(append([]laneItem{}, items...), solos...))
|
||||
return
|
||||
}
|
||||
if len(solos) > 0 {
|
||||
// 不进窗口的帧原样**插回队首**:本批先发车,随后它们各自单跑(一条一轮、
|
||||
// 不建窗口)。回插保序:它们比队列里其余条目都早,front 因此在 ch/spill 之前。
|
||||
b.requeueFront(l, solos)
|
||||
}
|
||||
b.flushLaneBatch(ctx, l, items, w, true, flushReason)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user