Repository navigation
fix: keep the client working when the evaluation storage fails - #359
Open
duyhungtnn wants to merge 4 commits into
Open
duyhungtnn wants to merge 4 commits into
duyhungtnn wants to merge 4 commits into
Conversation
At init, EvaluationStorage.initialize() loads the saved evaluations from storage into memory. If this read failed, the cache was never loaded and every later read threw, so initializeBKTClient() rejected and the client was removed. A failed save at init (in updateFeatureTag()) had the same result. When the cache cannot be loaded, create default data in memory and keep going: - a failed read logs the error and starts with the default (empty) data, the same as a first launch - a failed save logs the error and continues; memory is already updated The client stays registered, flags return the app's default value until a fetch succeeds, and init rejects only because of the init fetch.
duyhungtnn
force-pushed
the
fix/keep-client-on-storage-failure
branch
from
November 13, 2026 03:40
ca885dc to
aa55898
Compare
Add tests for a failing storage write in update(), setUserAttributesUpdated() and clearUserAttributesUpdated(), and check that updateUserAttributes() now resolves and reconnects streaming in that case. Also fix the comment in initialize(): a full storage fails a save, not a read.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change that preserves SDK usability when evaluation storage fails.
No open issues 🎉
What changed in this PR
This PR keeps the SDK usable when evaluation storage reads or writes fail by falling back to an in-memory cache instead of failing initialization.
Changes:
- Initialize an empty cache after storage read errors and preserve in-memory updates after save errors.
- Add regression tests for initialization, evaluation listeners, default values, and streaming reconnection when storage fails.
- Clarify initialization comments to distinguish recoverable storage errors from fatal failures.
| File | Description |
|---|---|
test/internal/evaluation/EvaluationStorage.spec.ts |
Tests in-memory fallback and updates after storage failures. |
test/BKTClient.spec.ts |
Tests client availability, fetch outcomes, listeners, and reconnection with failing storage. |
src/internal/evaluation/EvaluationStorage.ts |
Logs storage errors, retains usable memory state, and shares default entity creation. |
src/BKTClient.ts |
Updates comments describing initialization error handling; no runtime changes. |
Review effort: Balanced
duyhungtnn
marked this pull request as ready for review
November 13, 2026 07:21
Collaborator
Author
|
hi @cre8ivejp please help me to take a look |
duyhungtnn
marked this pull request as draft
November 17, 2026 06:45
duyhungtnn
marked this pull request as ready for review
November 19, 2026 09:03
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.
Note
Storage failures are rare, but when one happens at init, the client cannot recover for the whole session. This PR keeps the SDK working in that case.
Context
While working on #357 (evaluation sync status listener), a cache load failure at init needed its own sync status. This was a good time to decide how the client should handle this case. Both PRs touch this path in
initializeBKTClientInternal; whichever merges second will be adjusted.The new behavior matches the Android SDK: a failed cache load is ignored (code), and reads then return an empty list from memory (code).
Problem
When the evaluation storage fails at init, the client does not work at all.
If
EvaluationStorage.initialize()cannot read the saved evaluations, the cache is never loaded and every later read throwsCache Evaluation entity is not loaded.initializeBKTClient()then rejects and the client is removed:getBKTClient()returnsnull, and a retry fails the same way. A failed save at init (inupdateFeatureTag()) has the same result.Examples:
JSON.parse()throws); the app's ownstorageFactoryfails.storageFactoryfails.Solution
When the cache cannot be loaded, create default data in memory and keep going.
initialize(): log the error and start with the default (empty) data, like a first launch.saveAsync(): log the error and continue. Memory is already updated, so update listeners are still called.Same approach as the existing storage error handling in
fetchEvaluationsInternal(code).Result
initializeBKTClient()rejects only because of the init fetch (for example a timeout), as the docs describe.updateUserAttributes()no longer rejects when the save fails, and now reconnects streaming in that case.Not in this PR
track()can still fail when storage fails. A following PR may keep events in memory.initializeBKTClientInternalstays as a safety net for other failures (for example storage that throws when it is created).Tests
EvaluationStorage: a failed read gives default data; a secondinitialize()still throws; a failed save still updates memory in all five save methods.BKTClient: with failing storage, init resolves, the client stays registered, listeners are called, and values come from memory. A timed-out init fetch rejects withTimeoutExceptionand variations return the default value.updateUserAttributes()resolves and reconnects.