Skip to content

Fix interactive UI creating duplicate messages on button press#67

Open
zhou-zhichao wants to merge 1 commit intosix-ddc:mainfrom
zhou-zhichao:fix/interactive-ui-duplicate-messages
Open

Fix interactive UI creating duplicate messages on button press#67
zhou-zhichao wants to merge 1 commit intosix-ddc:mainfrom
zhou-zhichao:fix/interactive-ui-duplicate-messages

Conversation

@zhou-zhichao
Copy link
Copy Markdown

Summary

  • Handle BadRequest: Message is not modified specifically — keep existing message instead of creating a duplicate
  • Delete old message before sending new one when edit genuinely fails, ensuring at most one interactive UI message per topic

Problem

Each button press (Up/Down/Enter/Space/Tab) on interactive UI inline keyboards could create a new message instead of editing the existing one. This happened because handle_interactive_ui caught all exceptions from edit_message_text and fell through to send_message without deleting the old message.

The most common trigger: Telegram raises BadRequest: Message is not modified when terminal content hasn't changed after a button press — the broad except Exception treated this as a failure and sent a duplicate.

Changes

Only src/ccbot/handlers/interactive_ui.py:

  1. Import BadRequest from telegram.error
  2. Catch BadRequest with "Message is not modified" → return True (keep existing message)
  3. On other edit failures → delete_message the old one before sending new

Test plan

  • Press interactive UI buttons (Up/Down/Space/Enter) rapidly — should always have exactly one UI message
  • Delete the UI message externally in Telegram, then press a button — should send a fresh message (no error)
  • Verify AskUserQuestion, PermissionPrompt, ExitPlanMode all work correctly

Fixes #66

When editing an existing interactive message fails with "Message is not
modified" (content unchanged after button press), the old code caught all
exceptions and fell through to send a new message, causing duplicates.

Changes:
- Handle BadRequest "Message is not modified" specifically: keep existing
  message and return early instead of creating a duplicate
- On other edit failures, send the replacement message first, then delete
  the old one only after the new one succeeds — prevents stranding users
  without controls if the replacement send also fails

Fixes six-ddc#66
@zhou-zhichao zhou-zhichao force-pushed the fix/interactive-ui-duplicate-messages branch from 43448aa to 4106d55 Compare March 26, 2026 01:51
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.

Interactive UI creates duplicate messages on button press instead of editing in-place

1 participant