habitist icon indicating copy to clipboard operation
habitist copied to clipboard

Unexpected task completions on nightly reset

Open lukefernandez opened this issue 3 years ago • 3 comments

Issue: Every morning (I set the cron to run at midnight), I was noticing that I already had a large number of completed tasks for the day. Digging into the code a bit, I realized that tasks I didn't complete the previous day were being marked complete when the count was reset to zero. That isn't exactly what I would expect. If I did not complete a task, I would want it to reset to zero, but I wouldn't want it to be marked as complete.

Resolution: Instead of making a call to item.update_date_complete, make a call to item.update so that the count resets to zero but the item is not marked as complete.

This change has been proposed in PR #26.

Let me know if you need additional context! Thanks for putting this awesome project together!

lukefernandez avatar Aug 23 '21 04:08 lukefernandez

@lukefernandez Thank you. Can you test this in your fork for a few days and let me if this works correctly?

I reviewed old commits and saw that I had switched from update to update_date_complete here. But can't recall the exact reason. I guess it was due to some issue with the date not being set correctly when using update.

amitness avatar Aug 23 '21 10:08 amitness

Yeah, it seems to be working on my end, but I'll think of some more rigorous test cases and upload the results here in the next few days. Thanks!

lukefernandez avatar Aug 23 '21 21:08 lukefernandez

Unfortunately, I haven't had the time to test this programmatically, but I tested it empirically for the last few months and behavior has been as expected. Below you can find a basic before and after result.

Before: before

After: after

I staged each task's state to match its name/description (seen in the before image) and then waited for habitist to run overnight. The after image shows the state the next day after a successful habitist run.

All of my "test cases" passed, but I might have missed an edge case or two.

@amitness That said, I have noticed some issues with dates getting updated in general. I think it is related to the time of day that tasks are completed, specifically when a task is completed between midnight (when Todoist updates due dates) and the time that habitist runs.

For example, I have my habitist scheduled to run right after midnight. But GitHub Action schedules are non-guaranteed (see https://upptime.js.org/blog/2021/01/22/github-actions-schedule-not-working/), so my runs go through on average around 12:13am. So, if I'm completing tasks anytime between midnight and 12:13am (or whenever habitist runs, if it even does), task due dates are going to get out of sync.

Not sure of a good way to solve that timing problem, but maybe that's why your dates are getting out of sync?

lukefernandez avatar Oct 27 '21 22:10 lukefernandez