Simplify public event sink setup - #240
Conversation
|
Warning Review limit reached
Next review available in: 37 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
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 |
There was a problem hiding this comment.
ℹ️ Minor suggestions only.
Reviewed changes
- Remove runtime sink synchronization —
SetPublicEventSink与publishPublicPayloads不再使用sinkMu,公开事件 sink 变为仅在组装阶段注入的依赖,并在 setter 注释中记录“运行期不得替换”的约定;生产组装路径(api.NewServer→sessions.NewHandler)在请求/worker 处理开始前完成注入,go语句创建的 goroutine 提供 happens-before 保证,因此该去除是安全的。 - Document worker→public status mapping — 为
publicSessionStatusPayloads补充函数级与行内注释,说明状态事件映射及重复发布跳过逻辑。 - Require exact event type matching —
SessionStatus不再对入参做strings.TrimSpace,事件类型必须精确匹配。
行为面核对:SessionStatus 的两个调用方(codesessions/status.go 的 publicEventTypeFromWorkerStatus 输出、sessions/event_effects.go 读取的 session_events.event_type)传入的都是已归一化的事件类型,去掉 trim 不会引入回归;SetPublicEventSink 全仓仅有 sessions/transport.go:32 一个调用点,且位于服务开始接收请求之前。
DeepSeek Flash | 𝕏
|
|
||
| func SessionStatus(eventType string) (string, bool) { | ||
| switch strings.TrimSpace(eventType) { | ||
| switch eventType { |
There was a problem hiding this comment.
SessionStatus 现在是 managedagentsevents 里唯一不做 TrimSpace 的匹配函数,与 ThreadStatus、CategoryFor、IsClientInput 等其余 helper 行为不一致。当前两个调用方传入的都是已归一化的类型,不会回归;但后续若有人把原始 worker payload 的 type 直接传入,会在状态投影路径上静默返回 ("", false)。建议在注释里说明这一不对称的原因,或补一个精确匹配的单元测试固定语义。
| return nil, nil | ||
| } | ||
| } | ||
| // |
There was a problem hiding this comment.
这里残留了一行空的 // 注释,像是删除原注释块后留下的,可以直接删掉。

What changed
Why
These changes were left out when #239 was merged. The sink is installed before request handling starts and is not replaced at runtime, so synchronization around every publish is unnecessary.
Validation
go test -race ./internal/codesessions ./internal/sessions ./internal/managedagentsevents -count=1golangci-lintjust dead-codejust duplicatesjust complexityjust large-files