Skip to content

feat: persist Telegram files in R2 - #151

Merged
QueryPlanner merged 4 commits into
mainfrom
codex/persistent-r2-attachments
Aug 19, 2026
Merged

feat: persist Telegram files in R2#151
QueryPlanner merged 4 commits into
mainfrom
codex/persistent-r2-attachments

Conversation

@QueryPlanner

@QueryPlanner QueryPlanner commented Aug 15, 2026

Copy link
Copy Markdown
Owner

What

Persist supported Telegram attachments in private Cloudflare R2 while keeping
a sender-scoped SQLite catalog and a working copy in the active sandbox.

Why

Telegram attachment bytes currently disappear when an ephemeral sandbox dies.
Users need durable, private storage that the agent can discover and restore into
a replacement sandbox without exposing R2 credentials, keys, or other users'
objects.

How

  • Add an asynchronous boto3 R2 boundary with verified size and SHA-256 metadata.
  • Add a persistent SQLite catalog with opaque IDs, owner-scoped deduplication,
    deterministic orphan reconciliation, and infinite retention by default —
    files are kept until the bucket is deleted, unless R2_FILE_RETENTION_DAYS
    is explicitly set to a bounded window (1-3650 days).
  • Shield durable ingestion from cancellable model turns and materialize unique
    sandbox working paths for documents, photos, audio, video, and voice.
  • Preserve native Telegram photo input and enforce declared and actual byte
    limits before storage.
  • Add Telegram-root-only list, restore, and confirmation-required delete tools.
  • Inject at most ten escaped recent-file metadata entries as explicitly
    untrusted prompt data.
  • Wire least-privilege R2 environment settings into deployment configuration.
    Document that an R2 lifecycle rule is only needed if R2_FILE_RETENTION_DAYS
    is set, to keep the bucket in sync with the bounded-retention catalog.

Tests

  • uv run ruff format --check
  • uv run ruff check
  • uv run mypy .
  • uv run pytest --cov=src — 1,587 passed, 1 skipped, 100% coverage

Related Issues

Fixes #150

- Add sender-scoped R2 storage and a persistent SQLite catalog
- Restore durable files into ephemeral Telegram sandboxes
- Add private file tools, prompt metadata, tests, and evals

@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: d9fa71791b

ℹ️ 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".

Comment thread src/blacki/telegram/bot.py Outdated
Comment thread src/blacki/user_files/service.py
Comment thread src/blacki/telegram/bot.py Outdated
- Preserve temporary processing when R2 configuration is invalid
- Replace expired hashes before cataloging identical uploads
- Avoid hard-coded retention promises in fallback messages
- Resolve container.py/privacy.py/registry.py conflicts by
  keeping both R2 file storage and Google health storage
- Merge telegram bot.py refactor (album buffer, settings
  menu extraction) with R2 attachment ingest/session changes
- Merge test_registry.py and test_telegram_bot.py additions
  from both branches
- Regenerate uv.lock via `uv lock` instead of hand-editing
- Default R2_FILE_RETENTION_DAYS to unset, meaning files
  never expire until the bucket itself is deleted
- Allow expires_at to be NULL in the catalog schema and
  treat NULL as never-expiring in all lookup queries
- Keep bounded retention available by setting
  R2_FILE_RETENTION_DAYS explicitly (1-3650 days)
- Update .env.example and docs to describe the new default
- Add storage/service/config tests for the infinite path
@QueryPlanner
QueryPlanner merged commit 1868b04 into main Aug 19, 2026
3 checks passed
@QueryPlanner
QueryPlanner deleted the codex/persistent-r2-attachments branch August 19, 2026 09:59
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.

Persist Telegram attachments in Cloudflare R2

1 participant