Repository navigation
feat(anki): send LWT reviews to Anki, tested against real Anki (#264) - #328
Merged
Merged
Conversation
Step 2 of the sync build order. After pulling Anki's reviews, the sync page asks POST /api/v1/anki/push-plan what Anki lacks (AnkiPushPlan): LWT reviews missing from each card's revlog, shaped as the .apkg writer shapes them, and the card's due date, interval, reps and lapses. The browser writes them with insertReviews, setDueDate and setSpecificValueOfCard. A sync right after changes nothing either way. Measured against Anki 26.9.3 with AnkiConnect, FSRS on and off: insertReviews only appends history and Anki never replays it, so the schedule is set explicitly; AnkiConnect refuses to write FSRS memory state, so with FSRS on Anki's estimate catches up on reoptimising; setDueDate adds a grade-less revlog row, which the pull ignores. scripts/anki/container builds that Anki headless from first-party sources (PyPI, AnkiWeb with a pinned hash), with npm run anki:build / anki:up / anki:down and ANKI_FSRS to choose the scheduler. cypress/e2e/24-anki-live.cy.ts runs the whole loop against it (export, import, answer in Anki, sync, answer in LWT, sync, check Anki) and skips itself when no Anki answers, so CI is unaffected. Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 2 of the sync build order, plus a real Anki to test against. The sync page now works both ways, and the whole loop is verified against Anki 26.9.3 with AnkiConnect, with FSRS on and off.
Anki in a container:
scripts/anki/containeroffscreen) with AnkiConnect, built from first-party sources only. Anki comes from PyPI (aqt[qt6]==26.9.3, published by Ankitects); AnkiConnect comes from AnkiWeb, checked against a pinned SHA-256.ProfileManager, so no first-run dialog blocks.ANKI_FSRS=1or0chooses the scheduler.npm run anki:build,anki:upandanki:down, all with Podman. The exchange foldercypress/anki-exchange/is git-ignored.Step 2: LWT → Anki
After the pull (step 1), the page sends each card's revlog to
POST /api/v1/anki/push-plan.AnkiPushPlananswers with:insertReviewsrows for LWT reviews the card's revlog lacks, shaped exactly likeApkgWriter's rows. Ids clashing with Anki's are stepped past, because one clash fails the whole batch.setDueDate), plus interval, reps and lapses (setSpecificValueOfCardwithwarning_check, batched throughmulti, checking each reply).Cards Anki already has everything for get no action, so a sync right after another changes nothing either way.
What real Anki showed
Measured with a twin-card experiment, and in AnkiConnect's source:
insertReviewsonly appends history. The card's interval, due date, reps, lapses and FSRS stability are untouched. Anki's next answer is identical to that of a twin card without the insert, so the schedule has to be set explicitly.setDueDateadds a grade-less "rescheduled" revlog row, which the pull already ignores.These answer the spike's open questions. The doc is updated, with a "Testing against real Anki" section.
Tests
24-anki-live.cy.ts: export terms from LWT,importPackageinto Anki,answerCards(Good, Again, Easy), sync, answer one term in LWT, sync again. It then checks Anki has both answers and LWT's interval and reps on the card, and that a third sync does nothing in either direction.AnkiPushPlanTest(7): row shape, card schedule, only missing reviews, an up-to-date card, an id collision, skips, a never-reviewed term.anki_sync.test.ts: the push order and grouping, a refused card value, and the batched plan.composer test:no-coverage(9220),npm test(4440), Psalm (no errors), phpcs, lint,build:allanddocs:buildall pass.21to23still pass, andcheck-localesreports 100% for all 11 locales (the page text changed from "pull" to "sync").Step 3 (fields, tags, flags, existence through the sync base) is not in this PR, so #264 stays open.
🤖 Generated with Claude Code