Anki-Connect (new 26.10 rewrite): [Errno 22] on Windows for learning cards in filtered decks — breaks getDecks / cardsInfo

Environment

  • Anki 26.08.1 (39e4b0b4), Python 3.13.13, Qt 6.11.0, Windows 11 x64
  • Anki-Connect (2055492159) auto-updated on 2026-10-13 to the new JSON-RPC/v1 rewrite (a build from before 26.10.12.2)

Problem

Any request that serializes certain cards fails with [Errno 22] Invalid argument. In my case the legacy getDecks call fails, so a full Logseq → Anki sync (logseq-anki-sync 7.0.6) aborts every time.

Cause

In services.py, state_record() does:

elif card.queue in (1, 4) or (card.queue < 0 and card.type in (1, 3) and card.due > 1000000000):
    due = {'kind': 'timestamp', 'at': timestamp(card.due)}

When a learning card (queue = 1) is inside a filtered deck, Anki stores a negative ordering value in due (e.g. -99921, i.e. -100000 + position), not an epoch timestamp. timestamp() in protocol.py calls datetime.fromtimestamp(seconds, timezone.utc), which raises OSError: [Errno 22] Invalid argument on Windows for negative values.

In my collection exactly 5 cards matched queue IN (1,4) AND due < 0; all had odid != 0 and were in the same filtered deck. Emptying that filtered deck made the sync succeed immediately.

Steps to reproduce (Windows)

  1. Build a filtered deck and answer a card in it with Again so it stays in intraday learning (queue = 1).
  2. Call getDecks (or cardsInfo) with that card’s ID.
  3. The call returns [Errno 22] Invalid argument.

Workaround

Empty the filtered deck, run the request, then rebuild the deck.

Suggested fix

Don’t treat due as a timestamp when card.odid != 0 and due < 0 (report it as a position instead), or guard timestamp() against negative / out-of-range values.

(I checked the latest commits on git.sr.ht/~foosoft/anki-connect up to 26.10.12.2 — the search-snapshot fix is there, but state_record() is unchanged, so this still seems to apply.)