Skip to content

fix(core): Don't include last human message twice on Chat hub message regeneration#26430

Merged
Cadiac merged 1 commit intomasterfrom
cha-83-bug-duplicate-user-message-sent-on-regeneration
Mar 3, 2026
Merged

fix(core): Don't include last human message twice on Chat hub message regeneration#26430
Cadiac merged 1 commit intomasterfrom
cha-83-bug-duplicate-user-message-sent-on-regeneration

Conversation

@Cadiac
Copy link
Contributor

@Cadiac Cadiac commented Mar 2, 2026

Summary

When user regenerated messages on Chat hub we accidentally included the last human message both oh the chat history and as a new human message triggering that turn.

Instead don't include the human message on the history, as it gets replayed which inserts it into the memory again.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CHA-83/bug-duplicate-user-message-sent-on-regeneration

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Mar 2, 2026
@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Architecture diagram
sequenceDiagram
    participant UI as Chat UI
    participant CHS as ChatHubService
    participant DB as Message Repository
    participant WES as WorkflowExecutionService
    participant MN as Restore Chat Memory Node
    participant CT as Chat Trigger Node

    Note over UI,CT: Message Regeneration Flow

    UI->>CHS: regenerateAIMessage(retryId)
    CHS->>DB: getManyBySessionId(sessionId)
    DB-->>CHS: full conversation history
    
    CHS->>CHS: Identify target AI message & preceding human message
    
    Note right of CHS: CHANGED: history.splice(lastHumanMessageIndex)<br/>removes the trigger message from history<br/>to prevent double-injection.

    CHS->>WES: executeChatWorkflow(workflow, executionData)
    
    rect rgb(20, 30, 50)
        Note over WES,CT: Workflow Execution Context
        WES->>MN: NEW: Inject truncated history (excluding last human message)
        WES->>CT: Inject last human message as "current" trigger input
    end

    CT->>WES: Continue workflow turn...
    WES-->>CHS: executionId & stream
    CHS-->>UI: stream response tokens
    
    Note over CHS,DB: Post-Execution
    CHS->>DB: Save new AI response
Loading

@Cadiac Cadiac requested a review from autologie March 2, 2026 15:36
@Moses-main

This comment was marked as spam.

Copy link
Contributor

@autologie autologie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@Cadiac Cadiac added this pull request to the merge queue Mar 3, 2026
Merged via the queue into master with commit 672bfc3 Mar 3, 2026
48 checks passed
@Cadiac Cadiac deleted the cha-83-bug-duplicate-user-message-sent-on-regeneration branch March 3, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants