fix(sdk): recover an install the server no longer has instead of refusing its events - #62
Merged
Merged
Conversation
…sing its events An event whose installId is not in install_events was answered with a 404 and dropped. The id lives in the app's storage for the life of the install, so that is not a transient failure: every event that device will ever send refers to an id the server cannot resolve, and the SDK has no way back. A deployment that prunes analytics on a retention window reaches this state the moment an install outlives the window, which is the common case rather than an edge one, and the failure is invisible — the 404 goes to a mobile client that ignores it. The install is now recorded again under the id the client sent and the event is stored against it. The recovered row claims nothing it cannot know: marked `recovered`, with no link, click or confidence score, so it can never be read as a fresh attributed install, and a marker fingerprint that cannot collide with a real one. Creating a row from a client-supplied id adds no exposure that /api/sdk/v1/install does not already have, since that endpoint is unauthenticated and creates install rows for any caller. The 404 that remains — recovery itself could not complete — now carries code INSTALL_NOT_FOUND and action reregister, so a client can tell it from a transport error. The earlier test for the old behaviour is replaced by cases covering recovery, the concurrent-request race, and that path.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
POST /api/sdk/v1/eventanswered404 Install event not foundwhen theinstallIdwas not ininstall_events, and dropped the event. That is permanent from the device's side: the id lives in the app's storage for the life of the install, so every event it will ever send refers to an id the server cannot resolve. There is no code path back.Any deployment that prunes analytics on a retention window reaches this the moment an install outlives the window. It is also silent — the 404 goes to a mobile client that ignores it, so it appears in edge logs and nowhere else.
Now: an unknown install is recorded again under the id the client sent, and the event is stored against it.
The recovered row claims nothing it cannot know:
attribution_method = 'recovered', nolink_id, noclick_id, noconfidence_score— it can never be read as a fresh attributed install.fingerprint_hash = 'recovered:<id>', a marker that cannot equal a real hash, so it cannot match a click by accident.sdk_name/sdk_versionfrom the event, so the row says which client it came from.ON CONFLICT (id) DO NOTHINGplus a re-read, so concurrent events for the same install cannot collide.Creating a row from a client-supplied id adds no exposure that
POST /api/sdk/v1/installdoes not already have: that endpoint is unauthenticated and creates an install row for anyone who calls it. The only difference is who picked the UUID, and it is still only ever their own row.The 404 that remains (recovery itself could not complete) now carries
code: "INSTALL_NOT_FOUND"andaction: "reregister"so a client can tell it from a transport error and register a fresh install instead of retrying forever.Verification
npx tsc --noEmit,npm run build,npx vitest run— 20 files, 397 tests pass.src/routes/sdk.event.test.tsgains five cases: the install is recorded again and the event stored; no attribution is claimed; a concurrent request's row is used rather than failing; the remaining 404 carries the code and action; a known install is untouched (two queries, no recovery insert). The earlier "unknown install returns 404" case is replaced — that was the behaviour being fixed.200 acknowledged, row created as{"attribution_method":"recovered","link_id":null,"click_id":null,"confidence_score":null,"fingerprint_hash":"recovered:9f1c…"}; the device's next event →200, still one install row, two events stored; attributed count0.Note for multi-tenant hosts
A recovered install is a device that already existed, not a new one. A host that counts install rows as new installs in customer-facing analytics should exclude
attribution_method = 'recovered'before adopting this release, or a fleet of recovered devices will read as a spike of installs on the day they recover.