Skip to content

Wip/format assign response once - #3401

Closed
danoswaltCL wants to merge 3 commits into
devfrom
wip/format-assign-response-once
Closed

danoswaltCL wants to merge 3 commits into
devfrom
wip/format-assign-response-once

Conversation

@danoswaltCL

Copy link
Copy Markdown
Collaborator

No description provided.

danoswaltCL and others added 3 commits October 26, 2026 13:38
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>

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

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,
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