Skip to content

fix(devops): use errEvt payload when sending error SSE event#786

Open
SKDG042 wants to merge 1 commit intocloudwego:mainfrom
SKDG042:fix/devops-debug-err-event-payload
Open

fix(devops): use errEvt payload when sending error SSE event#786
SKDG042 wants to merge 1 commit intocloudwego:mainfrom
SKDG042:fix/devops-debug-err-event-payload

Conversation

@SKDG042
Copy link
Copy Markdown
Contributor

@SKDG042 SKDG042 commented Apr 17, 2026

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

发送错误 SSE 事件时使用 errEvt 的 payload

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
In devops/internal/apihandler/debug.go:165, when constructing the SSE response for the error branch, the event type is correctly taken from errEvt.Type but the payload is mistakenly taken from evt.JsonBytes() (the data event constructed one line earlier) instead of errEvt.JsonBytes(). As a result, the frontend receives an SSE message whose event: claims error but whose data: body is actually a regular data event JSON, so the real error string (err.Error()) is silently dropped and the error reporting path becomes unusable.
Before

errEvt := types.DebugRunErrEVT(debugID, err.Error())
sseStreamResponseChan <- NewStreamResponse(string(errEvt.Type), string(evt.JsonBytes()))
//                                                              ^^^^^^^^^^^^^^^^^^^^ wrong source

After

  errEvt := types.DebugRunErrEVT(debugID, err.Error())
  sseStreamResponseChan <- NewStreamResponse(string(errEvt.Type), string(errEvt.JsonBytes()))

This aligns with the other error-sending site in the same file (line 178), where both the type and the payload come from the same event variable.
zh(optional):
devops/internal/apihandler/debug.go:165 在错误分支构造 SSE 响应时,事件类型正确地使用 errEvt.Type,但数据体却错误地取自 evt.JsonBytes(),而不是应该使用的 errEvt.JsonBytes()。这导致前端收到一条 event: error 但 data却是普通数据事件 JSON 的不一致消息,真实错误信息 err.Error() 被静默丢弃, 该修改与同文件第 178 行的另一处错误上报(类型与 payload 同源于一个事件变量)保持一致。

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@SKDG042
Copy link
Copy Markdown
Contributor Author

SKDG042 commented Apr 17, 2026

devops\internal\apihandler\debug.go:line140 这边貌似有点问题

	debugID, stateCh, errCh, err := service.DebugSVC.DebugRun(ctx, m, rs.Input)
	if err != nil {
		log.Errorf("DebugRun err: %v", err)
		return
	}

	sseStreamResponseChan := make(chan SSEResponse, 50)
	wg := sync.WaitGroup{}
	wg.Add(1)
	safego.Go(ctx, func() {
		defer wg.Done()
		for {
			select {
			case <-ctx.Done():
				return
			case state, ok := <-stateCh:
				if !ok {
					evt := types.DebugRunFinishEVT(debugID)
					sseStreamResponseChan <- NewStreamResponse(string(evt.Type), string(evt.JsonBytes()))
					return
				}

				evt := types.DebugRunDataEVT(debugID, state)
				if err != nil {
					errEvt := types.DebugRunErrEVT(debugID, err.Error())
					sseStreamResponseChan <- NewStreamResponse(string(errEvt.Type), string(errEvt.JsonBytes()))
					return
				}
				sseStreamResponseChan <- NewStreamResponse(string(evt.Type), string(evt.JsonBytes()))
			}
		}
	})

	safego.Go(ctx, func() {
		defer close(sseStreamResponseChan)
		wg.Wait()
		for e := range errCh {
			evt := types.DebugRunErrEVT(debugID, e.Error())
			sseStreamResponseChan <- NewStreamResponse(string(evt.Type), string(evt.JsonBytes()))
		}
	})

err == nil 的时候, 才会执行到下面 select, 此时err的值为nil,

	if err != nil {
					errEvt := types.DebugRunErrEVT(debugID, err.Error())
					sseStreamResponseChan <- NewStreamResponse(string(errEvt.Type), string(errEvt.JsonBytes()))
					return
				}

这一段错误处理永远不会触发, 所以这个bug一直没发现(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant