A single free place with a queued backlog starts no run until a second
place frees up; the condition alone was not pinned by the latency test.
Refs #178
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of PR #184: when the budget freed up one place at a time (requests
spread by network latency), every place went to a pull-only run with
pushBatches = 0, so a queued backlog was never sent while the device spent
6 GETs a minute. The scheduler now waits for two free places.
Tests: a fake server with 300 ms per request (9-batch queue empties within
4 min, no run without a POST place), the 600 s Retry-After bound, and source
guards for the `more` signal of pushChanges and the budget of initialMerge.
Refs #178
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every sync now goes through one scheduler (src/services/syncSchedule.ts,
pure and import-free): one sync at a time, a request during a sync gives a
single relaunch, a sliding budget of 6 real HTTP requests per 60 s (each
POST batch and each GET counted, initialMerge and initialReset included),
pushChanges sends the batches the budget allows (MAX_PUSH_BATCHES becomes a
ceiling) and the rest of the queue follows once the window frees, a 429
suspends the scheduler until Retry-After, and no sync starts during
initialMerge / initialReset.
The repositories call requestSync() (src/services/syncTrigger.ts, 2 s
debounce, single subscriber registered by _layout.tsx) after each outbox
write and after the Inbox repair transaction; outbox.ts and syncClient.ts
never do. _layout.tsx syncs on launch, every 30 s in the foreground, on
return to the foreground and on write through scheduleSync(); the Settings
button too. REVIEW.md and scripts/review-levels.py list the two new files
in the Sync row.
test: reproduces #178 (tests/syncSchedule.test.mjs, smoke guards)
Refs #178
Refs #167
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>