Repository navigation
fix(chat): skip insurance requests while the chat is paused - #6842
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughThe repository marks Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Insurance polling skips paused chats and resumes on schedule. The tests verify actual network requests, and no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/src/test/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepositoryTest.kt (1)
235-238: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winVerify that the resumed tick sends a request.
This test uses a fresh
ChatMessageSyncerwith no HTTP-synced anchor.fetchNewMessages()callsdeleteExpiredMessages(), then returns without sending a network request. The assertion proves that the polling loop invoked the fetch method, but it does not prove the request behavior named in the test. Establish an HTTP-synced anchor in the fixture and verify the expectednetwork.pullChatMessages()call.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e9e6ff96-3899-4ef6-ad93-907506599d95
📒 Files selected for processing (2)
app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.ktapp/src/test/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepositoryTest.kt
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
|
@coderabbitai Thanks, the nitpick from your review on The pause tests now record an HTTP-synced anchor through the initial load (
Without the fix in this PR, both tests now fail with AI disclosure: the test change was written with the help of Claude Code (claude-opus-5-5). |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
fd -t f '^OfflineFirstChatRepositoryTest\.kt$' . | while IFS= read -r file; do
ast-grep outline "$file" --match 'insurance|Initial|initial' --view expanded
rg -n -C 30 'insurance requests are skipped|insurance requests resume|fun .*Initial|fun .*initial|loadInitialMessages\(' "$file"
doneLength of output: 11046
The assertions cover five intervals without a request while paused, no request half a tick after resume, and exactly one request on the next tick. This addresses the test concern. I did not rerun the tests or lint checks. If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
fd -t f '^OfflineFirstChatRepositoryTest\.kt$' . | while IFS= read -r file; do
ast-grep outline "$file" --match 'insurance|Initial|initial' --view expanded
rg -n -C 30 'insurance requests are skipped|insurance requests resume|fun .*Initial|fun .*initial|loadInitialMessages\(' "$file"
doneLength of output: 11046
The assertions cover five intervals without a request while paused, no request half a tick after resume, and exactly one request on the next tick. This addresses the test concern. I did not rerun the tests or lint checks. You are interacting with an AI system. |
With a high performance backend the insurance loop sent a chat GET every 2 minutes for as long as ChatActivity stayed in the back stack, in the background and overnight. Long polling already honours itIsPaused; the insurance loop did not. Skip the tick while paused. Returning to the chat is covered by ChatViewModel.onResume, which fetches immediately. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
The pause tests counted deleteExpiredMessages calls, which only show that fetchNewMessages ran: without an HTTP-synced anchor it returns before any network request. Record an anchor through the initial load and verify pullChatMessages instead: no call while paused, one call on the first tick after the chat is resumed. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
75e1e1c to
bf3af05
Compare
Symptom
With a high performance backend, a chat that stays in the back stack keeps sending
GET .../chat/<token>?...lookIntoFuture=1&limit=200&timeout=0every 2 minutes while the app is in the background, including all night with the screen off. In one server access log: 226 such requests from one device between 23:18 and 07:05, 120–122 s apart, all answered with 304.Cause
OfflineFirstChatRepository.initInsuranceRequests()loopsdelay(INSURANCE_REQUEST_DELAY)→fetchNewMessages()and never checks the repository's pause flag.initLongPolling()(used without the high performance backend) already waits whileitIsPausedis set, so only the insurance loop runs in the background.Change
itIsPausedis set, reusing the flag set byhandleOnPause/handleOnResume. The loop keeps its normal 2-minute step.ChatViewModel.onResumealready callsfetchNewMessages()right afterhandleOnResume()when the chat comes back to the foreground.itIsPausedis now@Volatile: it is written on the main thread and read from the polling coroutine.How to test
GET .../chat/<token>?...limit=200&timeout=0every 2 minutes. After: none while the chat is paused.Unit tests:
OfflineFirstChatRepositoryTest—insurance requests are skipped while the chat is paused,insurance requests resume with the next tick after the chat is resumed(both fail without the change; they use virtual time).Not yet tested on a device after the change.
Related
Each of these background requests also cleared the user's chat notifications of that conversation, because
fetchNewMessages()sends nomarkNotificationsAsRead=0; that is fixed separately in #6841. This PR touches the neighbouringinitInsuranceRequests(); #6832 changesinitLongPolling()just above it.🖼️ Screenshots
Not applicable.
🚧 TODO
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)
The analysis, code, tests and this description were prepared with Claude Code (claude-opus-5-5) and reviewed by me. The commit carries an
Assisted-bytrailer.