fix(messages): gate inbound msg on pending UI + always repost card#88
Merged
Merged
Conversation
Two adjacent races/inconsistencies in the inbound-message path: 1. **Pending interactive UI consumes user keystrokes.** When an AskUserQuestion / ExitPlanMode / Permission prompt was on the pane and status_polling hadn't surfaced it yet (1-second poll cadence), a user-typed message went straight to send_to_window and got interpreted as menu navigation — digits selected options, Enter submitted, kb-mode keyboard never appeared in chat. The old guard in text_handler detected the UI but fell through to send the text anyway. New helper ``_intercept_if_pending_ui`` captures the pane, and on detection surfaces the prompt via ``enter_kb_mode`` for the active session (or the legacy floating-msg fallback for orphan / bg windows), notifies the user, and returns True. All inbound handlers (text / voice / photo / document / caption / forwarded slash) now ``return`` on True instead of sending. 2. **Live card didn't repost after photo / voice / document / caption / slash.** ``text_handler`` already runs the resume_card_view + repost_intent + repost_card bracket so a fresh card lands below the user's message and old one drops; the other inbound paths skipped it, leaving the card pinned above the user's file/caption. New async-context-manager ``_card_repost_bracket`` factors the pattern out (with a ``commit()`` handle so failed sends skip the repost). photo_handler, document_handler, voice_handler, caption-forward in unsupported_content_handler, and forward_command_handler now wrap their send_to_window / _forward_inbox_file calls in it. Tests: ``test_forward_command.py`` mocks gain ``capture_pane`` → empty string and ``find_session_by_window`` → None so the new guard + bracket no-op. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two adjacent races/inconsistencies in the inbound-message path, observed in session
local_bottoday:status_pollinghadn't surfaced the kb-mode keyboard yet (1-second poll cadence), a user-typed message went straight tosend_to_windowand got interpreted as menu navigation — digits selected options, Enter submitted, kb-mode never appeared in TG. The old guard intext_handlerdetected the UI but fell through to send the text anyway.text_handleralready runs theresume_card_view+repost_intent+repost_cardbracket so the card lands below the user's message; the other inbound paths skipped it, leaving the card pinned above the user's file/caption.Changes (
src/ccbot/bot/messages.py)_intercept_if_pending_ui(bot, user_id, wid, reply_to)— captures pane, surfaces viaenter_kb_mode(active session) orhandle_interactive_ui(orphan/bg), notifies user, returns True. Callerreturns on True instead of sending._card_repost_bracket(bot, user_id, sess)async-context-manager with acommit()handle. Failed sends skip the repost; successful ones spawn a fresh card below the user msg and drop the old one.text_handler(intercept only — repost bracket already inline),voice_handler,photo_handler,document_handler, caption-forward inunsupported_content_handler,forward_command_handler.Test plan
uv run ruff check src/ tests/— cleanuv run pyright src/ccbot/— 0 errorsuv run pytest tests/— 473 passed🤖 Generated with Claude Code