fix: slash-command responses use a message-scoped chatID for structural isolation

Co-authored-by: dj-oyu <68707227+dj-oyu@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-20 11:57:21 +00:00
parent b759bb0c8f
commit f7961a8fe7
2 changed files with 31 additions and 2 deletions

View file

@ -475,8 +475,10 @@ func (c *TelegramChannel) handleQuickCommand(ctx context.Context, message telego
"peer_id": peerID, "peer_id": peerID,
} }
// No "Thinking..." placeholder — send directly via message bus // Use a message-scoped chatID so this response never matches the ongoing
c.HandleMessage(fmt.Sprintf("%d", user.ID), fmt.Sprintf("%d", chatID), content, nil, metadata) // LLM task's placeholder or stopThinking entry for this chat.
chatIDStr := fmt.Sprintf("%d#%d", chatID, message.MessageID)
c.HandleMessage(fmt.Sprintf("%d", user.ID), chatIDStr, content, nil, metadata)
return nil return nil
} }
@ -520,6 +522,11 @@ func (c *TelegramChannel) downloadFile(ctx context.Context, fileID, ext string)
} }
func parseChatID(chatIDStr string) (int64, error) { func parseChatID(chatIDStr string) (int64, error) {
// Strip message-scoped suffix used by quick-command responses.
// e.g. "123456789#42" → parse as "123456789"
if idx := strings.IndexByte(chatIDStr, '#'); idx >= 0 {
chatIDStr = chatIDStr[:idx]
}
var id int64 var id int64
_, err := fmt.Sscanf(chatIDStr, "%d", &id) _, err := fmt.Sscanf(chatIDStr, "%d", &id)
return id, err return id, err

View file

@ -86,3 +86,25 @@ func TestDisplayWidth_EmojiIsThree(t *testing.T) {
t.Fatalf("displayWidth(stars) = %d, want 15", got) t.Fatalf("displayWidth(stars) = %d, want 15", got)
} }
} }
func TestParseChatID_Plain(t *testing.T) {
id, err := parseChatID("123456789")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if id != 123456789 {
t.Errorf("expected 123456789, got %d", id)
}
}
func TestParseChatID_MessageScopedSuffix(t *testing.T) {
// Quick-command responses use "chatID#messageID" to ensure uniqueness.
// parseChatID must strip the suffix so delivery still works.
id, err := parseChatID("123456789#42")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if id != 123456789 {
t.Errorf("expected 123456789, got %d", id)
}
}