Skip to content

fix(dispatch): stop prepending the agent-bot signature (double-apply) - #11

Open
mateusbellozupko wants to merge 2 commits into
evolution-foundation:mainfrom
mateusbellozupko:fix/agent-bot-signature-centralize
Open

mateusbellozupko wants to merge 2 commits into
evolution-foundation:mainfrom
mateusbellozupko:fix/agent-bot-signature-centralize

Conversation

@mateusbellozupko

@mateusbellozupko mateusbellozupko commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary

  • dispatch_engine.go prepended cfg.MessageSignature to the first message part with no separator (cfg.MessageSignature + parts[0]), so a signature like "Atendente" glued straight onto the reply text ("AtendentePronto, Mateus!...").
  • The CRM (evo-ai-crm-community) now applies this prefix itself, once, for every outgoing AgentBot message regardless of which path created it (see companion PR evolution-foundation/evo-ai-crm-community#400) — including this dispatcher's postback. Prepending it here too would double it.
  • Removed the prepend; BotConfig.MessageSignature stays on the struct for callers that still read it, but Dispatch no longer acts on it.

Test plan

  • Updated dispatch_engine_test.go and test/e2e/e2e_test.go to assert the signature is not applied by bot_runtime.
  • Could not run go test ./... locally in this environment (no Go toolchain available) — relying on CI.

Summary by Sourcery

Remove bot_runtime signature application so the CRM can add the agent-bot prefix exactly once to outgoing messages.

Bug Fixes:

  • Stop applying the agent-bot message signature in bot_runtime to prevent duplicate prefixes when the CRM adds it centrally.

Enhancements:

  • Keep dispatched segmented and unsegmented content unchanged regardless of MessageSignature, while preserving the configuration field for callers that still read it.

Tests:

  • Update dispatch and end-to-end tests to verify segmentation and postback content remain untouched by the bot runtime signature.

dispatch_engine.go prepended cfg.MessageSignature to the first message
part with no separator, so a signature like "Atendente" glued straight
onto the reply text ("AtendentePronto, Mateus!..."). The CRM now
applies this prefix itself, once, for every outgoing AgentBot message
regardless of which path created it (Message#apply_agent_bot_signature
in evo-ai-crm-community) — including this dispatcher's postback.
Prepending it here too would double it.

BotConfig.MessageSignature is left on the struct for callers that
still read it; Dispatch itself no longer acts on it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR prevents double application of the agent-bot display-name prefix by making bot_runtime leave dispatch content untouched; tests now validate that behavior across unit and end-to-end segmentation paths.

Sequence diagram for centralized AgentBot signature application

sequenceDiagram
    participant Dispatch as bot_runtime Dispatch
    participant CRM as CRM
    participant AgentBot as AgentBot recipient

    Dispatch->>Dispatch: segmentContent(residual, cfg)
    Dispatch->>CRM: Send dispatch parts without MessageSignature
    CRM->>CRM: Apply display-name prefix once
    CRM->>AgentBot: Deliver prefixed message
Loading

File-Level Changes

Change Details Files
Removed agent-bot signature mutation from dispatch so outgoing content is passed through unchanged and the CRM remains the single point responsible for applying the prefix.
  • Deleted first-part signature prepending from Dispatch.
  • Retained MessageSignature on BotConfig for compatibility with callers that read it.
  • Updated unit and end-to-end expectations to verify signatures are not applied during dispatch, including segmented and unsegmented responses.
  • Removed the now-redundant empty-signature test.
pkg/dispatch/service/dispatch_engine.go
pkg/dispatch/service/dispatch_engine_test.go
test/e2e/e2e_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pkg/dispatch/service/dispatch_engine.go" line_range="84" />
<code_context>
-	if cfg.MessageSignature != "" && len(parts) > 0 {
-		parts[0] = cfg.MessageSignature + parts[0]
-	}
+	// FR-21's agent-bot display-name prefix is no longer applied here: the CRM
+	// now applies it once, centrally, for every outgoing AgentBot message
+	// (including this postback), so doing it here too would double-prefix it.
</code_context>
<issue_to_address>
**nitpick:** The `DispatchEngine` interface comment still says dispatch appends the message signature, but `Dispatch` now deliberately sends content unchanged, so the public contract documentation is false.

**Suggested fix:** Update the interface comment to state that dispatch segments and sends the AI response without applying `MessageSignature`.
</issue_to_address>

### Comment 2
<location path="pkg/dispatch/service/dispatch_engine_test.go" line_range="75-77" />
<code_context>
-	}
-	for i, p := range parts[1:] {
+	for i, p := range parts {
 		if strings.Contains(p, "[bot]") {
-			t.Errorf("signature must NOT be on part %d: %q", i+1, p)
+			t.Errorf("MessageSignature must not be applied by bot_runtime, found it on part %d: %q", i, p)
 		}
 	}
 }
</code_context>
<issue_to_address>
**nitpick (testing):** The multipart regression test only checks that `[bot]` is absent; it passes if dispatch drops, alters, or sends the wrong segmented content as long as that marker is missing, so it does not verify the stated requirement that message content remains untouched.

**Triggers:** When a future change regresses segmentation or modifies content without adding the signature marker.

**Suggested fix:** Assert the complete expected parts, such as `[]string{"hello world this", "is test"}`, in addition to checking that the signature is absent.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. If the CRM does not apply the prefix exactly as assumed, outgoing AgentBot messages will be sent with a missing or double signature. Reverting restores the old behavior for future messages, but it cannot undo messages already delivered externally.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pkg/dispatch/service/dispatch_engine.go
Comment thread pkg/dispatch/service/dispatch_engine_test.go Outdated
… test

- DispatchEngine's interface comment still said it appends the message
  signature; it deliberately doesn't since the CRM prefix centralization.
- The multipart test only checked "[bot]" was absent, which would still
  pass if a regression dropped or mangled segment content as long as
  that literal string was missing. Assert the exact expected parts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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