Skip to content

fix(application): make review-state edits of the read their save is conditional on - #1012

Merged
ixuz merged 2 commits into
mainfrom
review-state-edits
Nov 24, 2026
Merged

ixuz merged 2 commits into
mainfrom
review-state-edits

Conversation

@ixuz

@ixuz ixuz commented Nov 24, 2026

Copy link
Copy Markdown
Member

What and why

Every write of a deck's reviews document except a grade was made from one read and saved If-Match another. A use case read the review states and made its change of them. The adapter then read the document again and saved If-Match that second read. So a grade made on another device between the two reads was in the version the save was conditional on, and got written over. In the Studio, setting a card's due day wrote the card's old interval and ease over a grade made meanwhile, while the grade's answer stayed in the log. This is the defect #997 fixed for instance metadata, the catalog and the deck entry, here for review states.

Two commits:

  • Writes of the reviews document alone. Setting a card's due day, forgetting its progress, and resetting the day now go through a new port, editReviewStates, built on editDocument like writeFsrsStates. It gives the change the states as read, saves If-Match that same read, and on a 412 reads the document again and makes the change again. The day reset still removes the day's answers from the log first. applyReviewChanges, now used only to undo an answer, is the same edit with a change made beforehand, so it also retries after a 412.
  • Writes of both documents. A bulk card edit and a card transfer read the review states with their version (readReviewStatesSince) and pass it to prepareReviewChanges, as they already did for the cards document. If the reviews document is no longer at that version, nothing is sent and the edit is planned again. If it changes after the cards document was sent, the reviews' changes (states added or removed by card) are made again from a fresh read, since the edit can no longer be planned again. writeCardEditReviews and the library upgrade's retry wrapper are gone. The transfer's comment that each write goes "If-Match the read it was made from" now holds for its reviews too.

Tests

  • The adapter is tested for an edit made of the read, the retry after a 412, the version check before anything is sent, and the re-make when the document changes after the cards were sent.
  • The use-case tests check that a reschedule keeps a grade made meanwhile, and that a day reset resets one along with the rest of the day.
  • A new end-to-end test in reviewStateEdits.integration.test.ts has the phone grade a card right after the Studio reads the states, then checks the card keeps that grade, due on the day set. Run against main's code, it fails with the Studio's stale interval. It passes on css-7 and css-acp, and skips on css-6, nss-6 and nss-5, as the cardEdits concurrency tests do: those servers ignore If-Match or keep an ETag across edits in the same second.

data-model.md, srs.md and studio.md describe the new behavior. npm run check passes on each commit.

Closes: #1011

ixuz added 2 commits November 24, 2026 20:59
…s as the write reads them

rescheduleCards, resetCards and resetStudyDay read the deck's review
states, made the change of them, and handed it to applyReviewChanges,
whose adapter read the reviews document again and saved If-Match that
second read. A grade made on another device between the two reads was
in the document the save was conditional on, so a reschedule wrote the
card's old interval and ease over it, due on the day set, while the
grade's answer stayed in the log.

editReviewStates, a new port on editDocument like writeFsrsStates,
gives the change the states as read and saves it If-Match that same
read, made again of a fresh read on a 412. The three use cases now make
their changes in it; a day's reset still removes the day's answers from
the log first. applyReviewChanges, left to an answer undone, which
writes its state back whatever the document holds, is the same edit
with a change made beforehand, so it is tried again on a 412 too.

Refs: #1011
…ersion they were planned from

A bulk edit of cards and a transfer read the review states with no
version, planned their changes, then had prepareReviewChanges read the
reviews document again and send If-Match that second read: the
transfer's comment said each write went If-Match the read it was made
from, which was true of the cards document only. writeCardEditReviews
and the library upgrade each wrote their own retry, sending the same
changes again on a 412.

prepareReviewChanges now takes the version the changes were made from
(readReviewStatesSince), as prepareCardChanges does: a document no
longer at it refuses them before anything is sent, so the edit or the
transfer is planned again. One that changes once a cards document was
sent can't be: its changes, states added or removed by card, are made
of it read afresh (editReviewStates). The use cases' own retries go.

Closes: #1011
@ixuz ixuz added bug Something isn't working enhancement New feature or request labels Nov 24, 2026
@ixuz
ixuz enabled auto-merge November 24, 2026 20:01
@ixuz
ixuz added this pull request to the merge queue Nov 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
@ixuz
ixuz added this pull request to the merge queue Nov 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
ixuz added a commit that referenced this pull request Nov 24, 2026
…ot under coverage

The test that the shape check of a release lets the page do its work
between subjects with many values validates a release of 32 cards of
1,024 values each, three times over, beside smaller ones. It was in
shaclShapeValidator.test.ts, so CI's check job ran it under coverage,
with every package's tests at once on two cores: 167 s of its 180 s
timeout on #1012's own run, and past it in both of its merge queue
runs, failing them. Without coverage it takes about 34 s in CI.

Like every test that times CPU work as a ratio of two runs, it now
lives in a growth test file, shaclShapeValidator.growth.test.ts, which
the growth job runs without coverage and npm test leaves out. Its input
and its limit are as they were, and so is the package's coverage.

Closes: #1016
@ixuz
ixuz added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 7479bdb Nov 24, 2026
55 checks passed
@ixuz
ixuz deleted the review-state-edits branch November 24, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review-state edits are made from one read and saved If-Match another, so rescheduling a card can undo a grade made meanwhile

1 participant