Skip to content

fix(chat): do not retry a long poll while the chat is paused - #6847

Open
ToteMeiSter wants to merge 2 commits into
nextcloud:masterfrom
ToteMeiSter:fix/long-poll-retry-respects-pause
Open

ToteMeiSter wants to merge 2 commits into
nextcloud:masterfrom
ToteMeiSter:fix/long-poll-retry-respects-pause

Conversation

@ToteMeiSter

@ToteMeiSter ToteMeiSter commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On a server without HPB the chat is kept up to date by a long poll (initLongPolling, timeout=30). It checks itIsPaused only before it starts a new cycle. ChatMessageSyncer.pullMessagesFlow retries a failed request up to four times with a 1–3 s delay and does not check the pause state. When the system closes the socket of a backgrounded app, the request fails and is sent again, so a new timeout=30 request starts in the background.

Change

pullMessagesFlow and pullAndPersistMessages take a canRetry: () -> Boolean predicate (default: always true). The long poll passes !itIsPaused. When the chat is paused, a failed request ends with an error and initLongPolling waits for the resume as before. Other callers are unchanged.

Notes

How to test

  • Unit: ChatMessageSyncerTest (pullMessagesFlow does not retry a failed request once retrying is not allowed) fails without the change (TooManyActualInvocations), passes with it.
  • Device: not checked on a device.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

The change was drafted with Claude Code (Assisted-by: Claude-Code:claude-sonnet-5-5).

pullMessagesFlow retries a failed chat request up to four times and never
looked at the pause state, so a long poll killed by the system in the
background was restarted with a new timeout=30 request. initLongPolling
checks itIsPaused only before it starts a cycle.

pullMessagesFlow now takes a canRetry predicate. The long poll passes
!itIsPaused, a failed request on a paused chat ends with an error and the
loop waits for the resume. Other callers keep the default.

Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
Assisted-by: Claude-Code:claude-sonnet-5-5
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10b5a11e-a68f-44c5-9293-f5bfaa67bfcc

📥 Commits

Reviewing files that changed from the base of the PR and between 9b52e33 and d572885.


📒 Files selected for processing (2)
  • app/src/main/java/com/nextcloud/talk/chat/data/network/ChatMessageSyncer.kt
  • app/src/test/java/com/nextcloud/talk/chat/data/network/ChatMessageSyncerTest.kt

🚧 Files skipped from review as they are similar to previous changes (2)
  • app/src/test/java/com/nextcloud/talk/chat/data/network/ChatMessageSyncerTest.kt
  • app/src/main/java/com/nextcloud/talk/chat/data/network/ChatMessageSyncer.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

Chat message sync now accepts a retry predicate, which defaults to allowing retries. After a failed request, the flow checks the predicate before and after backoff. If the predicate returns false, the flow emits a retry-cancelled error and stops. Long polling supplies a predicate that disallows retries while the repository is paused. Tests verify that retries stop when eligibility is false before or after backoff.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to d5728

A failed long poll will not retry while chat is paused, and polling waits for resume. The change is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing chat long-poll retries while the chat is paused.
Description check Passed The description explains the problem, change, testing, notes, and checklist status. The screenshots and TODO sections are not included, but they are non-critical for this change.
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.

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4d300af6-4360-4968-b47d-fdf5bcc507ae
📥 Commits

Reviewing files that changed from the base of the PR and between acc10f9 and 9b52e33.

📒 Files selected for processing (3)
  • app/src/main/java/com/nextcloud/talk/chat/data/network/ChatMessageSyncer.kt
  • app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt
  • app/src/test/java/com/nextcloud/talk/chat/data/network/ChatMessageSyncerTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

pullMessagesFlow evaluated canRetry right after a failed request and then
slept for up to four seconds. A chat paused during that backoff still sent
the next request when the delay ended.

canRetry is now evaluated again after the delay and before the next
request. The check before the delay stays, so a chat that is already
paused does not wait for nothing.

Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
Assisted-by: Claude-Code:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants