Skip to content

Send /assign's decisionPoint from the Python client lib - #3429

Open
bcb37 wants to merge 2 commits into
devfrom
wip/python-client-lib-assign-decision-point
Open

bcb37 wants to merge 2 commits into
devfrom
wip/python-client-lib-assign-decision-point

Conversation

@bcb37

@bcb37 bcb37 commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Brings the Python client lib into parity with the JS (#3425) and Java client libs for the optional decisionPoint in the /assign body.

Changes

get_decision_point_assignment (async and _sync)

  • Answered from the cache, with no request, if get_all_experiment_conditions already fetched the full context, or an earlier call fetched this decision point.
  • Otherwise sends /assign with decisionPoint: {site, target} (a None target is sent as ""), so the server evaluates only that decision point, and caches the response for it.
  • A decision point with no assignment isn't cached, so a later lookup asks again (same as JS).
  • An older server that ignores decisionPoint returns the full context. That still answers the lookup but isn't treated as the full context.

get_all_experiment_conditions only returns a cache that a full-context fetch filled. If the cache holds only single decision points, it fetches the full context.

⚠️ Behavior change: mark_decision_point no longer fetches assignments. Previously, marking with a cold cache fetched the full context first so the mark could carry the cached experimentId/condition id. JS and Java never fetch on mark, so Python now matches them: a decision point that was never looked up is marked without those ids, and the server selects the experiment itself. Callers who look the decision point up before marking (the README pattern) are unaffected.

Docs: the README method table and Caching section are updated, and the Python cell of the /assign decisionPoint row in CLIENT_API_COVERAGE.md is now ✅.

The second commit is layout-only ruff format on 5 files that were already failing ruff format --check on dev. Review the first commit on its own to skip it.

Testing

  • 261 tests pass (21 new: client, ApiService, DataService and request types). ruff check, ruff format --check and mypy are clean.

🤖 Generated with Claude Code

bcb37 and others added 2 commits November 23, 2026 15:49
get_decision_point_assignment now asks /assign for just the decision
point it was given when the cache can't answer, and caches the result
for that decision point, matching the JS and Java client libs.

- DataService tracks whether a full-context response filled the cache.
  get_all_experiment_conditions only returns a full-context cache, so a
  cache holding single decision points makes it fetch the full context.
- A decision point with no assignment isn't cached, so it's asked again.
- mark_decision_point no longer fetches assignments when the cache is
  cold. It sends the cached assignment's ids, so a decision point that
  was never looked up is marked without them (same as JS and Java).
- README and CLIENT_API_COVERAGE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Layout-only: ruff format --check was already failing on these files on
dev. No code changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:51
@bcb37
bcb37 requested a review from danoswaltCL November 23, 2026 20:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Focused Thompson Sampling lookups can cache conflicting conditions for the same experiment, allowing exposure and reward attribution to disagree with persisted enrollment.

1 open issue
What changed in this PR

Adds optional /assign decision-point support to the Python client, aligning its focused lookup and mark behavior with the JS and Java clients.

Changes:

  • Sends focused assignment requests and distinguishes partial caches from full-context caches.
  • Removes automatic assignment fetching from mark_decision_point, while preserving cached IDs when available.
  • Adds request and cache tests, updates documentation, and applies formatting cleanup.
File Description
clientlibs/​python/​tests/​test_types.py Tests optional decision-point request fields.
clientlibs/​python/​tests/​test_data_service.py Tests partial-cache lifecycle and full-context replacement.
clientlibs/​python/​tests/​test_client.py Tests focused lookups, caching, older-server responses, and mark behavior.
clientlibs/​python/​tests/​test_api_service.py Tests decision-point serialization and target normalization.
clientlibs/​python/​src/​upgrade_client_lib/​types/​requests.py Adds optional decisionPoint to AssignRequest.
clientlibs/​python/​src/​upgrade_client_lib/​data_service.py Tracks partial versus full-context assignment caches.
clientlibs/​python/​src/​upgrade_client_lib/​client.py Implements focused lookups and removes fetching during marks.
clientlibs/​python/​src/​upgrade_client_lib/​assignment.py Formatting only; no behavior change.
clientlibs/​python/​src/​upgrade_client_lib/​api_service.py Builds focused /assign bodies for async and sync requests.
clientlibs/​python/​README.md Documents lookup, caching, and mark behavior changes.
clientlibs/​CLIENT_API_COVERAGE.md Marks Python decision-point support as implemented and tested.

Review effort: Balanced

Comment on lines +72 to +73
for a in assignments:
cached.setdefault(self._key(a.site, a.target), a)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same issue that we decided not to worry about in the ts pr - it's also apparently a thing in the java one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants