Repository navigation
fix: walk every sync chunk when polling for changes - #95
Conversation
Closes #61. checkForPollingChanges read a single 100-entry sync chunk and then set nextUpdateCount to the account-wide head regardless of how far that chunk actually reached. src/index.ts commits that as the new cursor, so every change past the first 100 in an interval was skipped permanently — a webhook that never fires. Walk the chunks instead, resuming from each chunk's chunkHighUSN and ending when it reaches that chunk's own updateCount. Using the chunk's head rather than the earlier getSyncState value matters twice: it is consistent with chunkHighUSN, and because the service advances chunkHighUSN across the whole scanned range — including objects this filter excludes, such as resources — a quiet account still costs exactly one call instead of an extra empty one on every ordinary poll. nextUpdateCount is now the USN the walk actually reached, never the account head. That makes the cap a pacing bound rather than a data-loss boundary: a burst larger than MAX_POLL_CHUNK_ITERATIONS (50) chunks drains over the following intervals instead of being dropped, so no synthetic "backlog truncated" change type is needed and webhook consumers see no contract change. The cap is deliberately well above note-cache's 10, whose cap-exceeded branch calls clear() — safe for a cache, where a dropped entry only forces a re-fetch, and wrong here. Two failure modes are handled explicitly: - A failure partway through the walk keeps the chunks already read and the cursor already reached. Resetting to lastUpdateCount would re-walk them next poll, so a backlog larger than one rate-limit window could never drain and would trip index.ts's five-strike poll error limit. - A chunk that does not advance the cursor returns an error rather than looping or skipping. The return happens before that chunk is appended and leaves the cursor where it was, so its changes are deferred to the next poll rather than lost or double-sent. Ten tests added. Four fail against the previous implementation: the multi-chunk walk, the partial-failure resume, the cap-exceeded partial cursor, and the non-advancing chunk. The rest pin behaviour that must not regress — exactly one call on a quiet account and when only excluded objects changed, a chunk with no chunkHighUSN treated as the end of the walk, a cursor that raced past the pre-walk sync state not being clamped back, a chunk omitting updateCount, and a high USN below the cursor. Blast radius is small regardless: polling only runs when EVERNOTE_POLLING_ENABLED is exactly "true", which is off by default, and the path only reads sync state and posts webhooks — it never writes to Evernote. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Babysit: ready. Verified green at
Local pre-PR review: Codex CLI Negative control: reverting No merge performed — that is yours. Merging this should also let release PR #94 Edited to remove a literal review-trigger token from the table above: it was read as a review request and bounced on environment setup. The 👍 clean review on |
|
To use Codex here, create an environment for this repo. |
Closes #61.
The bug
checkForPollingChangesread one 100-entry sync chunk and then returnednextUpdateCount: currentUpdateCount— the account-wide head from agetSyncStatetaken before the read.src/index.tscommits that as the pollingcursor, so every change past the first 100 in an interval was skipped
permanently. For a webhook consumer that is a notification that never fires.
Filed in July as a follow-up to #60, deferred once so the 2.0.0 release wasn't
held up further, and still present on
main.The fix
Walk the chunks: resume from each chunk's
chunkHighUSN, and stop when itreaches that chunk's own
updateCount.Using the chunk's head rather than the earlier
getSyncStatevalue matterstwice. It is self-consistent with
chunkHighUSN, and because the serviceadvances
chunkHighUSNacross the whole scanned range — including objects thisfilter excludes, resources among them — a quiet account still costs exactly
one call. Looping on the
getSyncStatevalue instead would add an emptysecond call to most ordinary polls: double the quota on the common path, not
just on backlogs. There's a test pinning that.
nextUpdateCountis now the USN the walk actually reached, never the accounthead. That turns the iteration cap from a data-loss boundary into a pacing
bound — a burst larger than
MAX_POLL_CHUNK_ITERATIONS(50) chunks drains overthe following intervals rather than being dropped. So this needs no synthetic
backlog_truncatedchange type, and webhook consumers see no contract change.The cap is deliberately well above
note-cache'sMAX_CHUNK_ITERATIONS = 10.That one's cap-exceeded branch calls
clear(), which is safe precisely becauseit is a cache — a dropped entry only forces a re-fetch. Here it would be wrong.
Two failure modes handled explicitly
A failure partway through keeps its progress. The likeliest failure is a
rate_limitedon chunk 2 from the shared queue added in #86.changesandcursorlive outside thetry, and thecatchreturns both along with theerror. Resetting to
lastUpdateCountwould re-walk the same chunks every poll,so a backlog bigger than one quota window could never drain — and would trip
index.ts's five-strike limit and stop polling altogether.A chunk that doesn't advance the cursor returns an error instead of looping
or skipping. The return happens before that chunk is appended and leaves the
cursor where it was, so its changes are deferred to the next poll — not lost,
not double-sent. Hitting the cap, by contrast, is not an error: that would
make a large import stop polling after five intervals.
Tests
Ten added, and the negative control matters more than the pass:
main?chunkHighUSNas the end of the walkupdateCountReverting
src/polling.tsalone and re-running gave 4 failed / 6 passed on thefirst six, so those four genuinely pin the bug rather than merely describing it.
The last four closed gaps the local review named — in particular the
excluded-only chunk, which is the case that would have exposed a doubled call on
the common path. The first existing test's mock gained
chunkHighUSN/updateCount, since real non-empty chunks carry both.Full suite: 449 tests, 38 suites, green. Lint and build clean.
Risk
Low. Polling runs only when
EVERNOTE_POLLING_ENABLEDis exactly"true",which is off by default, and the path only reads sync state and posts webhooks —
it never writes to Evernote. The one real behavioural change for anyone who does
poll is call volume: a backlog now costs up to 50 chunk calls against the
per-token hourly quota instead of 1, bounded by the cap and paced through #86's
shared queue.
chunkHighUSNneeded no new plumbing —evernote-api.tsalready returns theraw SDK chunk, and
note-cache.tsalready declares the field. This only widenspolling.ts's local interface.Implementation harness: Claude Code (Opus 5). Local pre-PR review: Codex CLI
gpt-6.1-sol/ medium.🤖 Generated with Claude Code