Anki-android: Card is shown twice when answering "hard" after editing

Created on 26 Jun 2020  路  11Comments  路  Source: ankidroid/Anki-Android

Reproduction Steps
  1. review a card
  2. menu > edit note
  3. make a change to a random field > save
  4. answer card with "hard" (or "again")
Expected Result

the card's new interval/due time will be set according to the "hard" button and the card is not shown again in the current session

Actual Result

the hard button doesn't seem to have an effect. The card will be shown again later on with the same interval on the "hard" button.

NOTE: this happens every day since maybe 2 weeks, perhaps since around 2.12alpha10, I can't say for sure. Before that it never happened.
BUT: it only seems to happen during a longer review session (at least 10 minutes or at least 20 cards) because when I quickly try to reproduce the bug, everything works as expected. Maybe the bug is only triggered after a certain number of cards or after the "learn ahead limit" or such :-(

As a side note, I read in the comments of pull request https://github.com/ankidroid/Anki-Android/pull/6026#issuecomment-649893262 about cases when a card is shown twice. So the bug described here would be another case where a card is shown twice.

Debug info

AnkiDroid Version = 2.12alpha17

Android Version = 9

ACRA UUID = 1f29f610-893a-403f-83d5-25a26ba97fe0

Research

Enter an [x] character to confirm the points below:

  • [x ] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid
  • [x ] I have checked the manual and the FAQ and could not find a solution to my issue
  • [ x] I have searched for similar existing issues here and on the user forum
  • [x ] (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
2.12.x Bug Priority-Medium

All 11 comments

Thank you for searching so much that you even find PR.

I've had similar trouble recently. I've not reported it because I didn't know for sure whether it was a problem with my code or with master. Since I can't run master code anymore (because of https://github.com/ankidroid/Anki-Android/issues/6524 ) I've not tried to check which case it was.

I believe that your bug is entirely unrelated to the remark in #6026.
Can you please tell me, when you close the editor, do you see the result of the change you made in the editor ? E.g. if you correct a typo, is the card in the reviewer corrected or not ? I would expect that you don't see the correction in the reviewer.

What should occurs is that:

  1. Review a card with id id. It is represented in the reviewer by an object reviewer_card
  2. when you open the editor, you create a new card object editor_card with the same id
  3. when you close the editor, it states that editor_card should be saved in the database
  4. once this saving is done, the reviewer reload in order to get the new value from the database and change reviewer_card to a copy of editor_card
  5. when you review the card, you save the card to the database with the fields of editor_card and the new due value

What really occurs is that:

  1. Review a card with id id. It is represented in the reviewer by an object reviewer_card
  2. when you open the editor, you create a new card object editor_card with the same id
  3. when you close the editor, it states that editor_card should be saved in the database
  4. when you review the card quickly, you save the card to the database with the previous fields, as it is in reviewer_card and the new due value
  5. The editor finally save the editor_card; the trouble being that this card has no information about the new due date; so the scheduler believes the card has not been reviewed, and it shows it to review again

I know that's not exactly what occurs, because fields are in notes and not in cards, but the main idea should be correct. I.e. there is some card flushing that should occur at the end of editing and that actually occurs later

@Arthur-Milchior I just reproduced the bug and it's like that: after closing the editor, I can see the changes in card card. Pressing hard will show the next card, without setting the new due date for card. After a few more reviews card card will be shown again. The previous changes I made are still there. The interval shown on the hard button is still the same as before.

One more thing related to this bug: pressing hard the first time card is shown will lower the number of due reviews -1 in the counter. But then card is shown again and the counter will be lowered another -1. Result: when the counter reaches 0, we're taken back to the deck list, and there the counter shows 1 due review for that deck, because the remaining card wasn't shown during reviews.

I'm not sure, but this bug might have serious effects on scheduling. So I'd recommend to not edit cards AND answer them with hard until the cause of this bug is found.

Thank you for your answer. I guess my intuition here were bad if you see the change you made in the reviewer. I won't investigate more right now; mostly because I can't run master on my phone anymore

@Anthropos888 are you on v1 or v2 scheduler? Thanks for the repro steps, should be possible to track this down...

@mikehardy Scheduler V2

I could also reproduce it with pressing again. In my case, again is set to 5h. When pressing again after editing the note, the card will be shown again after just a few minutes. The red number in the top right is underlined, so the card obviously is recognized as incorrect answered. That means, when pressing again for the first time, the card state (is:learn) was set correctly, but the new due time not.

I reproduced the bug again, and actually it's a bit different than described in the first post:

  • it occurs generally after editing a note during reviews, no matter which answer button is pressed.
  • when pressing the answer button for the first time, the new interval/due time according to the answer button is saved to the card.
  • but then, the card is shown again during the same reviews session due to the bug. A new interval is shown on the answer button (as if the card would be shown after the previously set interval)
  • that means, pressing one of the answer buttons again will seriously interfere with scheduling. It's like pressing good/hard/again twice.

I'll switch to the stable version and check if it happens there as well.

I'm going to guess: dff3614215a5a11da63a6747b4148a832a5b86b0 (#6496) @mikehardy

This causes the following lines to be executed:

https://github.com/ankidroid/Anki-Android/blob/7d68b87a7e2f37a99dabdfabc6225d614a540146/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java#L1084-L1087

BUT... updateNote is called afterwards:

https://github.com/ankidroid/Anki-Android/blob/7d68b87a7e2f37a99dabdfabc6225d614a540146/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java#L1090-L1095

OnCompletion of AnswerCard(0):

https://github.com/ankidroid/Anki-Android/blob/7d68b87a7e2f37a99dabdfabc6225d614a540146/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java#L575-L596

OnCompletion of updateNote:

  • Sets the current card to the card returned from the procedure

https://github.com/ankidroid/Anki-Android/blob/7d68b87a7e2f37a99dabdfabc6225d614a540146/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java#L510-L546

Since the next card from the scheduler may not be the card we edited, this means that we may see the same card twice.

Thanks @david-allison-1 - I'll look into this one

6584 will address the regression that made this much more visible but it will likely still happen, per discussion on the related PR

Changing the card type or deck will lead to a reloadRequired, and I believe that will also trigger the bug.

So this will auto-close when I merge the PR but I will either reopen it or if I forget it should be re-opened

The scheduler has changed a lot! Also this was detected in 2.12.x which means it is not a regression created in the 2.13-alpha series and shouldn't block release. It should be retested once 2.13.x is out, and hopefully all the scheduler work + testing fixed this one

Hello 馃憢, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like _still searching for solutions_ and if you found one, please open a pull request! You have 7 days until this gets closed automatically

Was this page helpful?
0 / 5 - 0 ratings