fix(sync): stop firing a full Atlas sync on every message#61
Merged
Conversation
getSession() rebuilt the session object with only api_key/user_id/ device_name, dropping cached_v and last_check_ts. refreshIfStale() reads both, so its TTL gate and version dedupe were dead code: every CLI invocation and every processor iteration fired a /api/cli/sync/version probe plus a full background /api/cli/sync, each rewriting synced-env and session files. updateSession (getSession + spread + save) also erased whichever bookkeeping field it wasn't patching. Carry the two fields through getSession so the 10s probe TTL and the version dedupe work as designed.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Fixes #52.
getSession()rebuilt the session object with onlyapi_key/user_id/device_name, dropping the two fieldsrefreshIfStale()depends on:last_check_ts(probe TTL) andcached_v(version dedupe). So the TTL gate never passed and the version always looked changed — every message fired a/api/cli/sync/versionprobe plus a full background/api/cli/sync, each rewritingsynced-env.json,openscience-synced.json, and the session file, and invalidating provider state.updateSession(getSession + spread + save) also erased whichever bookkeeping field it wasn't patching, which is why the probe's own timestamp never stuck.The fix carries
cached_vandlast_check_tsthroughgetSession(), which restores both the 10-second probe TTL and the version dedupe, and makesupdateSessionmerges lossless.Beyond the request storm itself, this shrinks the attack surface for #55 (a transient 403 during sync silently signs the user out): fewer syncs, fewer chances to trip it.
Regression test writes a session file with both fields and asserts
getSessionreturns them; it fails on main and passes here. Full backend suite: 829 pass / 0 fail. Typecheck clean.