From f3616a11ea60ed414de06ad42a81504c5906eefc Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Mon, 24 Aug 2026 17:38:49 +0800 Subject: [PATCH] fix: acknowledge queued text inputs Co-Authored-By: Codex --- src/telegram_agent_bot/bot.py | 4 +- .../test_existing_window_binding.py | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/telegram_agent_bot/bot.py b/src/telegram_agent_bot/bot.py index 5d39ce2..db07593 100644 --- a/src/telegram_agent_bot/bot.py +++ b/src/telegram_agent_bot/bot.py @@ -5327,7 +5327,9 @@ async def text_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No if not success: await safe_reply(update.message, f"❌ {message}") return - if not queued: + if queued: + await safe_reply(update.message, f"⏳ {message}") + else: await mark_window_working(context.bot, user.id, wid, thread_id) # Start background capture for ! bash command output diff --git a/tests/telegram_agent_bot/test_existing_window_binding.py b/tests/telegram_agent_bot/test_existing_window_binding.py index b9ceeee..166b227 100644 --- a/tests/telegram_agent_bot/test_existing_window_binding.py +++ b/tests/telegram_agent_bot/test_existing_window_binding.py @@ -661,6 +661,57 @@ async def test_bound_topic_does_not_block_on_background_confirmation(self): safe_reply.assert_not_awaited() + @pytest.mark.asyncio + async def test_bound_topic_acknowledges_queued_text(self): + update = _make_text_update("hi") + context = _make_context() + + fake_window = MagicMock() + fake_window.window_id = "@1" + fake_window.window_name = "Projects" + fake_window.cwd = "/tmp/project" + + with ( + patch("telegram_agent_bot.bot.is_user_allowed", return_value=True), + patch("telegram_agent_bot.bot._get_thread_id", return_value=42), + patch("telegram_agent_bot.bot.session_manager") as mock_sm, + patch("telegram_agent_bot.bot.tmux_manager") as mock_tmux, + patch( + "telegram_agent_bot.bot.enqueue_status_update", new_callable=AsyncMock + ), + patch( + "telegram_agent_bot.bot.safe_reply", new_callable=AsyncMock + ) as safe_reply, + patch( + "telegram_agent_bot.bot._send_or_queue_agent_input", + new_callable=AsyncMock, + return_value=( + True, + "Agent is busy; queued until ready (1/20)", + True, + ), + ), + patch( + "telegram_agent_bot.bot.mark_window_working", + new_callable=AsyncMock, + ) as mark_working, + patch("telegram_agent_bot.bot._cancel_bash_capture"), + ): + mock_sm.get_window_for_thread.return_value = "@1" + mock_sm.window_has_usage_limit_exceeded = AsyncMock(return_value=False) + mock_tmux.find_window_by_id = AsyncMock(return_value=fake_window) + mock_tmux.capture_pane = AsyncMock(return_value="") + + from telegram_agent_bot.bot import text_handler + + await text_handler(update, context) + + safe_reply.assert_awaited_once_with( + update.message, + "⏳ Agent is busy; queued until ready (1/20)", + ) + mark_working.assert_not_awaited() + @pytest.mark.asyncio async def test_bound_topic_reports_when_direct_send_fails(self): update = _make_text_update("hi")