Skip to content

fix: harden durable Telegram delivery#38

Merged
krotname merged 1 commit into
masterfrom
agent/harden-durable-delivery
Jul 14, 2026
Merged

fix: harden durable Telegram delivery#38
krotname merged 1 commit into
masterfrom
agent/harden-durable-delivery

Conversation

@krotname

Copy link
Copy Markdown
Owner

Summary

  • What changed: hardened numeric-ID authorization and route parsing; added Telegram UTF-16 limits; made delivery leases and confirmation previews durable in SQLite; added multi-target retry/idempotency handling, admin/health/export diagnostics, and matching deployment documentation.
  • Why changed: prevent username-based authorization bypasses, duplicate deliveries under concurrency/restarts, lost confirmation state, oversized Telegram API payloads, malformed route configuration, and stale security-audit suppressions.
  • Tests run:
    • py -3.12 -m pytest -p no:cacheprovider (112 passed, 87.16% coverage)
    • py -3.12 -m ruff check src tests
    • py -3.12 -m ruff format --check src tests
    • py -3.12 -m mypy src
    • py -3.12 -m compileall -q src tests
    • py -3.12 -m pip check
    • py -3.12 -m build --no-isolation

Reliability details

  • Fences delivery ownership across both the current request ID and its legacy alias so a partially superseded lease cannot complete.
  • Removes obsolete pip-audit CVE ignores now that the lock uses aiogram 3.29.0 and aiohttp 3.14.1.
  • Documents the unavoidable narrow non-atomic window between Telegram acceptance and the following SQLite commit.

Checklist

  • Added/updated tests
  • Updated documentation
  • No hard-coded secrets in code
  • Lint/type checks passed

Comment thread tests/unit/test_app.py
import pytest
from aiogram import Dispatcher, Router

import telegram_resender.storage as storage_module
Comment thread tests/unit/test_app.py
assert bot.attempts == 1
assert second_message.answers == [RU_MESSAGES.request_in_progress]
bot.release.set()
await first
Comment thread tests/unit/test_app.py
bot.release.set()

with pytest.raises(RuntimeError, match="temporary delivery failure"):
await first_confirm
from telegram_resender.storage import RequestLog, export_records_csv
import pytest

import telegram_resender.storage as storage_module
@krotname
krotname marked this pull request as ready for review July 14, 2026 10:58
@krotname
krotname merged commit c12a3e5 into master Jul 14, 2026
13 checks passed
@krotname
krotname deleted the agent/harden-durable-delivery branch July 14, 2026 11:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 330ee8b8b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

owner_token, owner_version, owner_expires_at
FROM pending_requests
WHERE chat_id = ? AND user_id = ? AND expires_at > ?
AND owner_token IS NULL {request_predicate}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not skip the newest claimed preview for bare confirms

When a user has multiple pending previews and the newest one is already claimed by an in-flight /confirm, this owner_token IS NULL filter removes that newest row before ORDER BY version DESC, so a second /confirm without an ID claims and forwards the next older unclaimed request instead. The prompt says bare commands apply to the latest request; in this scenario they should report that the latest request is in progress rather than silently delivering a stale preview.

Useful? React with 👍 / 👎.

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.

2 participants