-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: prevent duplicate operator approval requests in Telegram bot #4420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| fn handle_operator_approval(message: &TelegramMessage) -> Result<()> { | ||
| // Verificar si ya hay una solicitud pendiente para este usuario | ||
| if let Some(pending) = get_pending_approval(message.from.id) { | ||
| // Si ya hay una solicitud pendiente, no crear una nueva | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // Crear una nueva solicitud de aprobación | ||
| create_approval_request(message.from.id, message.text)?; | ||
|
Comment on lines
+3
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift Check-then-create is not atomic — race condition can still send duplicate approval requests. The exact bug this PR intends to fix (duplicate approval requests) can still occur if two messages from the same sender arrive concurrently: both can pass the Consider making the check-and-insert atomic (e.g., a single transaction, a DB-level uniqueness constraint on the sender/session key, or a mutex keyed by sender id) rather than two separate calls. 🤖 Prompt for AI Agents |
||
|
|
||
| Ok(()) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new handler is never compiled or called:
src/openhuman/mod.rsdoes not declare atelegrammodule, and a repo-wide search only findsget_pending_approval,TelegramMessage, andhandle_operator_approvalinside this new file. The live Telegram approval path remains undersrc/openhuman/channels/providers/telegram/, so duplicate operator prompts for real Telegram messages will continue to use the old flow and this fix has no effect.Useful? React with 👍 / 👎.