Skip to content

fix: resume the reaction resweep within the run once a FloodWait expires (#224) - #226

Merged
GeiserX merged 4 commits into
mainfrom
ai/issue-224-resume
Jul 21, 2026
Merged

GeiserX merged 4 commits into
mainfrom
ai/issue-224-resume

Conversation

@GeiserX

@GeiserX GeiserX commented Jul 21, 2026 •

Copy link
Copy Markdown
Owner

Reopens and completes #224 per the reporter's follow-up on #225.

Problem

The v7.25.0 defer-on-first-FloodWait protected against retry-burn but over-corrected on accounts with small flood buckets (~4 requests vs ~27 on our test instance): one flood deferred the entire remaining run, so a run covered 2 chats and deferred 498 — while the run itself continued for ~6 more minutes with the bucket long refilled (the reported wait was 53s). Net coverage loss versus the old sleep-through-floods behavior.

Fix (the reporter's proposed middle ground, implemented faithfully)

  • On a resweep FloodWait, record the expiry deadline (server-requested seconds + 2s margin) and pause — nothing sleeps, nothing retries, no fallback onto the get_messages bucket. Message iteration and the rest of the backup continue untouched.
  • Chats reached while the window is still cooling skip to the next-run cycle cursor (as before).
  • Once wall-clock passes the deadline, the resweep resumes within the same run. Full deferral now happens only when the window outlives the run — or after 3 floods in one run (a repeatedly-flooding bucket is degrading and should be left alone until the next scheduled run).
  • The finalize/persist condition is now exact: the cursor persists iff at least one chat was actually deferred.
  • README gains sizing guidance from the reporter's measurements: on small-bucket accounts a lower REACTION_RESWEEP_MAX_PER_CHAT (e.g. 100) spends ~1 request per chat and lets a single run reach every eligible chat.

No new environment variables; the resume margin and flood cap are internal constants.

Testing

2269 tests pass (new: in-run resume after cooldown with a controlled clock, hard-defer after repeated floods, cooldown-skip counting; updated: pause semantics on both request paths, finalize keyed on actual deferral). Live validation on a production instance planned before release.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reaction re-sweeps under Telegram rate limiting, including the fallback reaction fetch path.
    • FloodWaits now pause and resume within the same run after the server cooldown (with a small margin), preserving mid-chat progress.
    • Repeated FloodWaits stop further work for the rest of the run (hard-deferred mode).
  • Documentation
    • README and example env notes now more precisely describe FloodWait pause/resume behavior and resweep pacing, including per-chat sizing tradeoffs.
  • Tests
    • Updated reaction resweep tests to validate cooldown-based pause/resume and deferred vs. hard-deferred behavior.
  • Chores
    • Bumped version to 7.25.1.

…xpires (#224)

Deferring the entire rest of a run on the first FloodWait over-corrected
on accounts with small flood buckets: a ~1-minute window turned into
hours of cycle latency (one production report covered 2 chats and
deferred 498 where the previous behavior covered the full eligible set
in one run). The resweep now records the flood expiry and pauses -
nothing sleeps, nothing retries, no second-bucket fallback - then
resumes within the same run once the server-requested window (plus a
2s margin) has elapsed. Chats reached while cooling down and the
window outliving the run still defer to the cycle cursor exactly as
before, and after three floods in one run the remainder defers
outright since a repeatedly-flooding bucket should be left alone.
Adds README sizing guidance for REACTION_RESWEEP_MAX_PER_CHAT on
small-bucket accounts. Bumps version to 7.25.1.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 974adc6c-50eb-402a-9b87-19cce8753059

📥 Commits

Reviewing files that changed from the base of the PR and between 30029bc and 494bf2c.

📒 Files selected for processing (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

📝 Walkthrough

Walkthrough

The reaction resweep now pauses and resumes within the same run after FloodWait responses, tracks partial progress, hard-defers after repeated floods, persists deferred state, updates tests and documentation, and bumps the package version to 7.25.1.

Changes

Reaction resweep updates

Layer / File(s) Summary
FloodWait state and registration
src/telegram_backup.py
Adds cooldown, flood-count, hard-deferral, partial-progress, and deferred-state tracking for resweep runs.
Pause, resume, and cycle persistence
src/telegram_backup.py
Updates primary and fallback API paths to pause, resume, or defer work based on FloodWait state and persists deferred cycle progress.
FloodWait and finalization tests
tests/test_reaction_resweep.py
Covers raw and fallback pauses, same-run resume, repeated-flood hard deferral, partial progress, and deferred finalization.
Version and behavior documentation
pyproject.toml, src/__init__.py, README.md, .env.example
Bumps the package version to 7.25.1 and documents revised resweep pacing and FloodWait behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • GeiserX/Telegram-Archive issue 224 — Addresses the FloodWait behavior and resweep pacing changed here.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The body is substantive but misses several required template sections, including Type of Change, Database Changes, Security Checklist, and Deployment Notes. Reformat the PR body to the repository template and add the missing sections, especially Type of Change, Database Changes, Data Consistency Checklist, Security Checklist, and Deployment Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main behavior change: resuming reaction resweeps after a FloodWait expires.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ai/issue-224-resume

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.53%. Comparing base (71951a8) to head (494bf2c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   93.51%   93.53%   +0.01%     
==========================================
  Files          27       27              
  Lines        8092     8115      +23     
==========================================
+ Hits         7567     7590      +23     
  Misses        525      525              
Files with missing lines Coverage Δ
src/__init__.py 100.00% <100.00%> (ø)
src/telegram_backup.py 95.31% <100.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 407-409: Update the re-sweep documentation around the persisted
per-cycle progress to avoid promising exact resume positions: replace “resumes
exactly where the last one stopped” with wording that clearly states resumption
is approximate, while preserving the surrounding behavior description.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d7950840-7a94-4d76-bab0-6ba2992c9db0

📥 Commits

Reviewing files that changed from the base of the PR and between 71951a8 and f27786c.

📒 Files selected for processing (5)
  • README.md
  • pyproject.toml
  • src/__init__.py
  • src/telegram_backup.py
  • tests/test_reaction_resweep.py

Comment thread README.md Resolved
@GeiserX

GeiserX commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit's wording catch fixed in the latest commit — the cursor resumes approximately where the previous run stopped (the window shifts between runs; the idempotent reconcile makes overlap harmless), matching what the code comments already said.

@github-actions

Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

… logs and offset advance

Panel findings: .env.example and one raw-path comment still described the
superseded defer-on-first-flood behavior; the pacing test class docstring
likewise. Adds a PII guard test over the new flood/pause/resume log lines
and a double-flood-same-chat test proving the parked mid-chat offset
advances instead of resetting.
@GeiserX

GeiserX commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

Ran a 3-perspective panel (state-machine logic, adversarial behavior, tests) with adversarial verification: zero serious findings — the pause/resume state machine verified sound on gate order, cap-trip progress parking, exact finalize keying, double-count immunity, and clock discipline. Five doc/test findings all addressed in the latest commit: stale defer-on-first-flood narratives in .env.example, one code comment, and the test-class docstring; plus two new tests (PII guard over the flood/pause/resume log lines, and a double-flood-on-one-chat case proving the parked offset advances rather than resetting). 2271 tests green.

@github-actions

Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

@GeiserX

GeiserX commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 9 minutes.

@GeiserX

GeiserX commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 407-409: Update the FloodWait-related environment-variable table
entry near the existing resweep settings to match the current behavior described
in the re-sweep documentation and .env.example: the first FloodWait should pause
and resume within the same run when possible, deferring only when the wait
exceeds the run or repeated floods occur. Remove the stale statement that
immediately defers the remaining resweep after the first FloodWait.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 728d1046-83de-4f71-a215-ccb4be3f0c99

📥 Commits

Reviewing files that changed from the base of the PR and between 71951a8 and 30029bc.

📒 Files selected for processing (6)
  • .env.example
  • README.md
  • pyproject.toml
  • src/__init__.py
  • src/telegram_backup.py
  • tests/test_reaction_resweep.py

Comment thread README.md Resolved
@GeiserX

GeiserX commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

Last stale narrative fixed — the env-table row for REACTION_RESWEEP_BATCH_DELAY_SECONDS now matches the re-sweep section and .env.example (pause and resume within the run; defer only when the wait outlives the run or floods repeat). CodeRabbit has substantively reviewed this PR clean twice; merging once the CI suite is green on this docs-only commit rather than cycling its rate-limited status a third time.

@github-actions

Copy link
Copy Markdown

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

@GeiserX
GeiserX merged commit 36ce070 into main Jul 21, 2026
9 checks passed
@GeiserX
GeiserX deleted the ai/issue-224-resume branch July 21, 2026 10:31
GeiserX added a commit that referenced this pull request Jul 28, 2026
…res (#224) (#226)

* fix(reactions): resume the resweep within the run after a FloodWait expires (#224)

Deferring the entire rest of a run on the first FloodWait over-corrected
on accounts with small flood buckets: a ~1-minute window turned into
hours of cycle latency (one production report covered 2 chats and
deferred 498 where the previous behavior covered the full eligible set
in one run). The resweep now records the flood expiry and pauses -
nothing sleeps, nothing retries, no second-bucket fallback - then
resumes within the same run once the server-requested window (plus a
2s margin) has elapsed. Chats reached while cooling down and the
window outliving the run still defer to the cycle cursor exactly as
before, and after three floods in one run the remainder defers
outright since a repeatedly-flooding bucket should be left alone.
Adds README sizing guidance for REACTION_RESWEEP_MAX_PER_CHAT on
small-bucket accounts. Bumps version to 7.25.1.

* docs(readme): resume position is approximate, not exact

* docs+tests(review): align narratives with pause-and-resume, guard PII logs and offset advance

Panel findings: .env.example and one raw-path comment still described the
superseded defer-on-first-flood behavior; the pacing test class docstring
likewise. Adds a PII guard test over the new flood/pause/resume log lines
and a double-flood-same-chat test proving the parked mid-chat offset
advances instead of resetting.

* docs(readme): align the env-table row with pause-and-resume behavior
GeiserX added a commit that referenced this pull request Oct 2, 2026
…res (#224) (#226)

* fix(reactions): resume the resweep within the run after a FloodWait expires (#224)

Deferring the entire rest of a run on the first FloodWait over-corrected
on accounts with small flood buckets: a ~1-minute window turned into
hours of cycle latency (one production report covered 2 chats and
deferred 498 where the previous behavior covered the full eligible set
in one run). The resweep now records the flood expiry and pauses -
nothing sleeps, nothing retries, no second-bucket fallback - then
resumes within the same run once the server-requested window (plus a
2s margin) has elapsed. Chats reached while cooling down and the
window outliving the run still defer to the cycle cursor exactly as
before, and after three floods in one run the remainder defers
outright since a repeatedly-flooding bucket should be left alone.
Adds README sizing guidance for REACTION_RESWEEP_MAX_PER_CHAT on
small-bucket accounts. Bumps version to 7.25.1.

* docs(readme): resume position is approximate, not exact

* docs+tests(review): align narratives with pause-and-resume, guard PII logs and offset advance

Panel findings: .env.example and one raw-path comment still described the
superseded defer-on-first-flood behavior; the pacing test class docstring
likewise. Adds a PII guard test over the new flood/pause/resume log lines
and a double-flood-same-chat test proving the parked mid-chat offset
advances instead of resetting.

* docs(readme): align the env-table row with pause-and-resume behavior
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.

1 participant