fix: prevent infinite render loop in Calibre Wireless after file transfer#1070
Conversation
…sfer Fixed infinite render loop in CalibreConnectActivity that occurred after a file transfer completed and the 6-second "File received" message timeout expired. The web server's wsLastCompleteAt timestamp persists indefinitely. When the 6-second timeout set lastCompleteAt=0, the next loop iteration would restore the old value from the server and immediately trigger the timeout again, creating an infinite cycle. Added lastProcessedCompleteAt to track which server timestamp has already been processed, preventing re-processing of the same old value after the timeout.
|
No actionable comments were generated in the recent review. 🎉 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (3)📓 Common learnings📚 Learning: 2026-02-12T06:57:35.955ZApplied to files:
📚 Learning: 2026-02-16T20:43:19.339ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (4)
📝 WalkthroughWalkthroughThe changes add a deduplication mechanism to CalibreConnectActivity by introducing a new state variable that tracks which server completion values have already been processed, preventing duplicate event processing while maintaining the existing timeout behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
Hi @itsthisjustin, could you validate this fix? This was my first time transferring a book from Calibre, and I started noticing the screen behaving strangely. I investigated further, and Claude found the solution. |
|
Will take a look tonight! |
Yes I saw the same thing. Locked up and wouldn't let me go back either. Was going to jump into this but patched the plugin yesterday instead. Good to see it's approved. |
|
Hi @daveallie, could this PR get a review? After a file transfer finishes in Calibre Wireless, a render loop starts, leaving ghost text on the screen that doesn’t clear, even after a full refresh. This occurs after a transfer finishes and the device goes to sleep (~10 min.). |

Summary
What is the goal of this PR?
Fix an infinite render loop bug in CalibreConnectActivity that caused the e-ink display to refresh continuously every ~421ms after a file transfer completed.
What changes are included?
Problem Description
After receiving a file via Calibre Wireless, the activity displays "Received: [filename]" for 6 seconds, then clears the message. However, the web server's wsLastCompleteAt timestamp persists indefinitely and is never cleared.
This created a race condition:
After 6 seconds, lastCompleteAt is set to 0 (timeout)
In the next loop iteration, status.lastCompleteAt (still has the old timestamp) ≠ lastCompleteAt (0)
The code restores lastCompleteAt from the server value
Immediately, the 6-second timeout condition is met again
This creates an infinite cycle causing unnecessary e-ink refreshes
Solution
The fix introduces lastProcessedCompleteAt to track which server timestamp value has already been processed:
Only accept a new status.lastCompleteAt if it differs from lastProcessedCompleteAt
Update lastProcessedCompleteAt when processing a new value
Do NOT reset lastProcessedCompleteAt when the 6-second timeout clears lastCompleteAt
This prevents re-processing the same old server value after the timeout.
Testing
Tested on device with multiple file transfer scenarios:
✅ File received message appears correctly after transfer
✅ Message clears after 6 seconds as expected
✅ No infinite render loop after timeout
✅ Multiple consecutive transfers work correctly
✅ Exiting and re-entering Calibre Wireless works as expected
Performance Impact
Before: Infinite refreshes every ~421ms after timeout (high battery drain, display wear)
After: 2-3 refreshes after timeout, then stops (normal behavior)
Additional Context
This is a targeted fix that only affects the Calibre Wireless file transfer screen. The root cause is the architectural difference between the persistent web server state (wsLastCompleteAt) and the per-activity display state (lastCompleteAt).
An alternative fix would be to clear wsLastCompleteAt in the web server after some timeout, but that would affect all consumers of the web server status. The chosen solution keeps the fix localized to CalibreConnectActivity.
AI Usage
Did you use AI tools to help write this code? < YES >