Skip to content

fix(edge): 恢复主运行 goroutine 与聚合器 panic,幂等 Bus.Close - #1735

Merged
DeliciousBuding merged 1 commit into
masterfrom
fix/edge-panic-safety
Aug 17, 2026
Merged

fix(edge): 恢复主运行 goroutine 与聚合器 panic,幂等 Bus.Close#1735
DeliciousBuding merged 1 commit into
masterfrom
fix/edge-panic-safety

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

背景

Edge 主 run() goroutine、output publish、watch、cancel grace、result aggregator 全部裸 go,任一 panic(adapter parse、emitter chain、nil deref、类型断言失败)会崩溃整个 Edge 进程,所有在飞 run 被孤儿化、WS 客户端断连。pkg/safego docstring 明确写「unguarded goroutine crashes the whole process」,但主执行链没有用。同时 events.Bus.Close() 非幂等(二次 close panic),finish() 不清包级 hubCallbackQueues/hubStreamChunkSeq,panic 路径泄漏条目。

变更

  • edge-server/internal/lifecycle/run/watchRunProcess/publishOutput/publishStructuredOutput/cancelGrace/resultAggregator/resultAggregatorTimeout 全部裸 go 改走 safeGo。run 的 defer e.finish(run.ID) 在 panic unwinding 期间仍执行(defers run before recover catches),terminal 状态与包级 map 卫生保留。
  • edge-server/internal/events/bus.goBus.Closesync.Once 幂等化,二次调用返回 nil 不再 re-close stopCh panic。
  • edge-server/internal/events/bus_behavior_test.go:删「NOT idempotent」注释,新增 TestBusCloseIdempotent
  • edge-server/internal/lifecycle/process_executor_finish.gofinish() 末尾 LoadAndDelete hubCallbackQueuesclose channel,Delete hubStreamChunkSeq,避免 panic 路径跳过 fireHubDone/fireHubFail 时条目泄漏。sync.Map.Delete 幂等,与 consumer defer 不冲突。
  • edge-server/internal/lifecycle/process_executor_hub_callback.go:新增 hubCallbackQueueState.close() 幂等方法(mutex + closed flag),供 finishenqueueTerminalHubJob 共用。

证据

  • real_tested=false:单元测试覆盖 panic 恢复与幂等 close;未跑真实 agent CLI。
  • 本地门禁:go build ./... + go test ./internal/lifecycle/... ./internal/events/... -short -count=1 + go test ./... -short -count=1(全绿)+ go vet + gofmt -l(干净)+ verify-ci-gates.py + verify-doc-ssot.py + git diff --check 全绿。
  • 新增测试:TestBusCloseIdempotent(二次 Close 不 panic)。

关联

审计 P0-1(主 run goroutine 无 recover)+ P1-5(Bus.Close 非幂等)+ P2-7(包级 sync.Map 在 panic 路径泄漏)。

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@DeliciousBuding, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f6656f36-6b17-4798-baf9-469fba58f547

📥 Commits

Reviewing files that changed from the base of the PR and between 531ca07 and 779be27.

📒 Files selected for processing (8)
  • edge-server/internal/events/bus.go
  • edge-server/internal/events/bus_behavior_test.go
  • edge-server/internal/lifecycle/process_executor_build.go
  • edge-server/internal/lifecycle/process_executor_cancel.go
  • edge-server/internal/lifecycle/process_executor_finish.go
  • edge-server/internal/lifecycle/process_executor_hub_callback.go
  • edge-server/internal/lifecycle/process_executor_start.go
  • edge-server/internal/lifecycle/result_aggregator.go

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DeliciousBuding
DeliciousBuding force-pushed the fix/edge-panic-safety branch 2 times, most recently from 75009de to 3dc7c15 Compare August 17, 2026 09:30
- lifecycle:把 run/watchRunProcess/publishOutput/publishStructuredOutput/cancelGrace/resultAggregator/resultAggregatorTimeout 全部裸 go 改走 safeGo,避免任一 panic 崩溃整个 Edge 进程
- events.Bus.Close:用 sync.Once 幂等化,二次调用不再 panic;新增 TestBusCloseIdempotent
- finish:清理包级 hubCallbackQueues/hubStreamChunkSeq,避免 panic 路径跳过 fireHubDone/Fail 时条目泄漏
- hubCallbackQueueState.close:新增幂等 close 方法供 finish 与 terminal enqueue 共用

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
@DeliciousBuding
DeliciousBuding merged commit ab7559d into master Aug 17, 2026
33 checks passed
@DeliciousBuding
DeliciousBuding deleted the fix/edge-panic-safety branch August 17, 2026 09:41
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.

1 participant