Skip to content

fix(workflow): guard nil intermediateMessage in chatflow suggest - #2743

Open
skyzhao1223 wants to merge 1 commit into
coze-dev:mainfrom
skyzhao1223:fix/chatflow-suggest-nil-guard
Open

skyzhao1223 wants to merge 1 commit into
coze-dev:mainfrom
skyzhao1223:fix/chatflow-suggest-nil-guard

Conversation

@skyzhao1223

Copy link
Copy Markdown

Fixes a nil pointer dereference in the chatflow success path.

Problem

In application/workflow/chatflow.go, the WorkflowSuccess branch dereferences intermediateMessage.Content when suggest mode is enabled:

if info.suggestReplyInfo != nil && ... && info.suggestReplyInfo.GetSuggestReplyMode() != ...Disable {
    sInfo := &vo.SuggestInfo{
        AnswerInput: schema.AssistantMessage(intermediateMessage.Content, nil),
        ...

But intermediateMessage starts as nil and is only assigned when a DataMessage is received (the needRegeneratedMessage path, around line 1106). A workflow that completes without emitting any DataMessage (e.g. an end-only workflow, or one whose outputs are all StateMessages) reaches this line with intermediateMessage == nil → nil pointer dereference panic.

Every other access site in the same function (:818, :931, :953) already guards with intermediateMessage != nil; this one was missed.

Fix

Add && intermediateMessage != nil to the suggest-mode condition. When there is no intermediate message there is nothing to base suggestions on, so suggest generation is skipped (safe degradation) instead of panicking.

go build ./application/workflow/
go test ./application/workflow/

The WorkflowSuccess branch dereferenced intermediateMessage.Content when
suggest mode was enabled, but intermediateMessage is only set when a
DataMessage is received (needRegeneratedMessage path). A workflow that
completes without emitting a DataMessage (e.g. an end-only workflow)
panicked with a nil pointer dereference. Skip suggest generation when
there is no intermediate message, consistent with the nil guards already
present at the other access sites.
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