fix: prevent echo of synthetic plan-start message from MiniApp

Strip "source" metadata from the synthetic "begin executing" message
and guard echo with "echoed" flag so only the original user command
is echoed to chat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-22 09:04:09 +09:00
parent 08dfe188c1
commit 19bd5e6a42

View file

@ -243,7 +243,7 @@ func (al *AgentLoop) Run(ctx context.Context) error {
} }
// Echo commands sent from the Mini App so the user can see what was sent. // Echo commands sent from the Mini App so the user can see what was sent.
if msg.Metadata["source"] == "webapp" && msg.Content != "" { if msg.Metadata["source"] == "webapp" && msg.Metadata["echoed"] == "" && msg.Content != "" {
al.bus.PublishOutbound(bus.OutboundMessage{ al.bus.PublishOutbound(bus.OutboundMessage{
Channel: msg.Channel, Channel: msg.Channel,
ChatID: msg.ChatID, ChatID: msg.ChatID,
@ -266,6 +266,12 @@ func (al *AgentLoop) Run(ctx context.Context) error {
// the LLM worker actually begins executing the plan. // the LLM worker actually begins executing the plan.
if al.planStartPending { if al.planStartPending {
al.planStartPending = false al.planStartPending = false
syntheticMeta := map[string]string{"echoed": "1"}
for k, v := range msg.Metadata {
if k != "source" {
syntheticMeta[k] = v
}
}
select { select {
case llmQueue <- bus.InboundMessage{ case llmQueue <- bus.InboundMessage{
Channel: msg.Channel, Channel: msg.Channel,
@ -273,7 +279,7 @@ func (al *AgentLoop) Run(ctx context.Context) error {
SenderID: msg.SenderID, SenderID: msg.SenderID,
SessionKey: msg.SessionKey, SessionKey: msg.SessionKey,
Content: "The plan has been approved. Begin executing.", Content: "The plan has been approved. Begin executing.",
Metadata: msg.Metadata, Metadata: syntheticMeta,
}: }:
case <-ctx.Done(): case <-ctx.Done():
return nil return nil