Repository navigation
fix(sdk): the Android SDK sends the user's attributes when it evaluates a flag - #2074
Open
amarkanday wants to merge 3 commits into
Open
amarkanday wants to merge 3 commits into
amarkanday wants to merge 3 commits into
Conversation
…es a flag Part of #438. evaluateFlag sent only user_id, so a flag rule on attributes could not match from Android. It now sends user.attributes as context, after user_id, written as compact JSON with the keys of every map sorted and percent-encoded by OkHttp's addQueryParameter, the encoder user_id already uses. With no attributes or an empty map the request is the one sent before. - ResultCache's entry remembers the context it was answered for; the new get(key, context) returns it only for the same context, and the old get and set are unchanged. Flag evaluation always passes its context ("" for none). - The offline store key stays user + flag. - A NaN or an infinite number at any depth throws IllegalArgumentException ("user.attributes cannot be sent as JSON") before the cache, the store and the request. Any other value is written as the assignment writes it. - HttpClient's network error message is cut at the request's query, and its cause is kept only when no message in its chain repeats the query. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV Signed-off-by: amarkanday <a.markanday@gmail.com>
…tributes Part of #438. The Android SDK page and README replace the "sends only the user id" note and add the cache, offline and unencodable sentences (the offline paragraph from the 404 change gains "whatever attributes it was asked with"). The shared pages, their claims units and video 4's description name Flutter as the only native SDK that still sends the user id alone. - test_documented_limits.py: Android moves from DOES_NOT_SEND to SENDS with its marker and leaves NATIVE_SDKS. - test_deferred_sdk_pages.py: Android leaves SENDS_NO_CONTEXT; nine sentences are pinned to the JUnit tests that hold them, and the old note must be gone. - test_site_walkthroughs.py and videos.json: the description ends "; Flutter sends only the user id to flags." and the row opens "Flutter sends only the user id on flag evaluation, so rules on attributes do not match". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV Signed-off-by: amarkanday <a.markanday@gmail.com>
Part of #438. HttpClient now treats the request's query and its context value, each encoded and decoded, as one list. withoutQuery cuts every form from the SDK's own network error message, and repeatsQuery drops the cause when any message in its chain repeats one of them (the encoded context value alone included). Empty forms are left out so nothing matches everything. A new test injects transport messages that carry the decoded query, the decoded context value and the encoded context value alone; the SDK message holds no canary, "context=" or "%7B", and the cause is dropped. The android.md cache paragraph is re-wrapped. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV Signed-off-by: amarkanday <a.markanday@gmail.com>
This branch has not been deployed
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.
Part of #438
What changed
The Android SDK now sends the user's attributes when it evaluates a flag:
GET /api/v1/feature-flags/evaluate/{key}?user_id=...&context=<percent-encoded compact JSON>,contextafteruser_id. Before, the attributes were accepted and dropped, so a targeting rule on a user attribute never matched. A call with no attributes sends the same bytes as before. The shared docs and claims now say only Flutter sends just the user id.It was built on the iOS change (#2045) and the #1747 fix (#2046), which have both merged. Its three commits are
b88ec5b1(SDK code and tests),8de12031(docs, claims registries, the backend gates, the video description) and91adb5da(the SDK's errors drop every form of the query). Their 18 files (924 insertions, 80 deletions) are:sdk/android/sdk/src/main/kotlin/com/controlvar/android/ExperimentationClient.kt,Cache.kt,HttpClient.ktsdk/android/sdk/src/test/kotlin/ExperimentationClientTest.ktdocs/sdk/android.md,sdk/android/README.mddocs/getting-started/limitations.md,docs/guides/guided-examples.md,demo/DEMO_GUIDE.md,demo/streampulse/README.md, and their fourdocs/_claims/**.tomlregistriesbackend/tests/unit/api/test_documented_limits.py,backend/tests/unit/docs/test_deferred_sdk_pages.py,backend/tests/unit/showcase/test_site_walkthroughs.pyfrontend/src/content/videos.json(video 4's description)OfflineStore.ktis untouched, and #1747's catch line and its 404 branch are unchanged. The choices, copied from the iOS pattern:user_idfirst, thencontext, inevaluateFlagPath; the context value goes through OkHttpaddQueryParameter(no new encoder).CacheEntrygainscontext(default"");get(key, context?)is a new signature beside the old one (null means no check; a mismatch keeps the entry), and so isset(key, value, context). Flag evaluation always passes its context. The oldgetandsetsignatures are kept. Android has no in-flight dedupe, so there is no dedupe key.org.jsonorder differs between the JVM test library and a device. The same attributes in another order share one cache slot and are sent once.IllegalArgumentException("user.attributes cannot be sent as JSON")before the cache, the store and the request. Any other value (aDate, say) goes as itstoString(), as it does for assignment.contextvalue alone); the underlying cause is kept unless some message in its chain repeats the query, in which case it is dropped.serverQuery(path)andserverContext(path)split on&, then on the first=, useURLDecoder.decode(s, UTF_8)(+is a space) and parse the JSON.How it was verified
On the three commits as replayed onto main: the 23 backend unit files that name Android, 1743 passed and 15 skipped;
python scripts/doc_claims.py check: problems 0; ruff clean; DCO: all 3 commits carry a matching sign-off; the secret scan over the diff: no findings. Putting android back in the "does not send" table failstest_every_sdk_directory_is_classified_by_whether_flag_evaluation_sends_attributes. In 16 of the 18 files the change is byte-identical to the reviewed commits' change. In the two backend test files it is the same change beside main's moves of the Ruby, PHP, Edge and Elixir SDKs (#2035, #2037, #2043, #2044): they had already left the same tables, and the Android section now follows the sections they added.Measured on the reviewed commits before that replay, with the same SDK code:
sdk/android/jvm,./mvnw clean test, JDK 21): 109 tests, 0 failures (base 81 including Android SDK: a stored offline answer is still served after the flag is deleted (404) #1747's three, so +28).test_documented_limits.py,test_deferred_sdk_pages.pyandbackend/tests/unit/showcase: 2212 passed.python scripts/doc_claims.py check: problems 0.mkdocs build --strict: exit 0. The secret scan overorigin/main..HEAD: no findings. DCO: every commit carried a matching sign-off.test_docs_only_gate.py47 passed; ruff clean on the three touched Python files; the frozen check (nomodules/path, nopyproject.toml) holds. Name-only diff againstbackend/ modules/ frontend/ pyproject.tomllists exactly the three backend test files andvideos.json.ExperimentationClient.ktandHttpClient.kt, the newCache.ktkept so the newgetandsetcompile), on the docs commit: 108 run, 13 failures and 2 errors (the reviewer's run: the same).+left raw fails 3;&left raw fails 3 and 1 error (reviewer); the error-form plants forwithoutQueryandrepeatsQueryeach fail the new test in the third commit; the claims, cache, offline, sorting and unencodable plants each fail at least one test (on the docs commit). Video 4: the iOS wording put back failstest_video_4s_native_sdk_sentence_is_the_documented_limitation(1 failed, 57 passed).pytest backend/tests/unit backend/tests/smoke) was started on the docs commit but its result was not kept, so no classification is claimed here. On the other branches the same sweep gave 168 PostgreSQL errors and the 2 pep440 failures, identical on main.Checklist:
make lintclean: not run as a whole; ruff clean on the touched Python files; CI'sFrontend Testsmust show success at the final head before mergeNot verified: the Gradle
:sdk:testDebugUnitTestleg (CI only); a device'sorg.json(insertion order,\/); the real server route; failure messages beyond the five measured (refused, dropped, unknown host, timeout, bad URL), for example TLS and proxy; a self-containing attribute map (assignment has the same limit); the frontend suite.Regression test
sdk/android/sdk/src/test/kotlin/ExperimentationClientTest.kt--regression 438 - evaluateFlag sends the attributes as context after user_idandregression 438 - a targeting rule on attributes matches(both@Tag("regression"))On the base
ExperimentationClient.ktthe first fails with expected...?user_id=u1&context=%7B%22plan%22%3A%22pro%22%7Dbut was...?user_id=u1, the second with "the rule plan == pro must match" (expected true, was false) (measured on the docs commit).Risk and rollback
This changes the SDK's request to the public flag-evaluation route for callers that pass attributes; callers that pass none send the same request as before. It also changes what Android's network errors say (the query is cut). If it is wrong, flag calls with attributes answer from the wrong context or fail; revert this PR to undo it. Nothing changes on the server, and no release is cut here. It also edits public docs and video 4's description, which go with the revert.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn