Repository navigation
Wip/format assign response once - #3401
Closed
danoswaltCL wants to merge 3 commits into
Closed
danoswaltCL wants to merge 3 commits into
danoswaltCL wants to merge 3 commits into
Conversation
formattingConditionPayload and formattingPayload rebuilt the same output from the same cached experiment graph on every /assign. Their results are now kept in WeakMaps keyed by the experiment object they were formatted from, so each experiment is formatted once per cache fill; a refresh stores new objects and the old entries drop away. Preview users and caching-off reads get fresh objects every time and format per request as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the per-cache-fill formatting: a cached experiment is formatted once across repeated requests, a refresh with new objects (same ids) is formatted again rather than served stale, and the cached-graph mutation tests now also check the shared formatted copies are left unchanged by a request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mapDecisionPoints (and withInSubjectTypeFromPrecomputed for within-subjects)
now produce only the fields clients read, with payloads as { type, value } or
null, so the separate formatAssignments pass over every assignment is gone
and formatAssignments is removed. Within-subjects factors are shaped once per
experiment instead of once per decision point. The JSON sent is unchanged.
Four ExperimentAssignmentService unit tests still assert the old in-between
shape (assignedFactor null instead of undefined, and an empty level payload
as { type: 'string', value: null } instead of null) and fail until updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Existing assignment tests still expect the old intermediate response shape and need updating for the normalized service output.
1 open issue
What changed in this PR
This PR reduces repeated formatting on the backend assignment path by caching formatted experiment data and building assignments directly in the client response shape.
Changes:
- Cache formatted experiment data by object identity.
- Normalize condition and factor payloads during assignment construction, removing the separate formatting pass.
- Add cache-reuse, refresh, and formatted-data immutability checks.
| File | Description |
|---|---|
packages/backend/test/unit/services/ExperimentAssignmentService.test.ts |
Adds formatting-cache and immutability checks. |
packages/backend/src/api/services/ExperimentAssignmentService.ts |
Caches formatted data and constructs normalized assignments. |
packages/backend/src/api/controllers/ExperimentClientController.v6.ts |
Returns service assignments without another formatting pass. |
packages/backend/src/api/Algorithms.ts |
Adds payload-formatting helpers and normalizes within-subject assignments. |
Review effort: Balanced
| ], | ||
| assignedFactor: assignedFactors ? [assignedFactors] : null, | ||
| experimentType: experiment.type, | ||
| assignedFactor: assignedFactors ? [toAssignmentFactor(assignedFactors)] : undefined, |
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.

No description provided.