@delmaredigital/payload-experiments 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/dist/admin/blocks/model.js +2 -0
- package/dist/admin/copy/blocks.d.ts +1 -0
- package/dist/admin/copy/blocks.js +1 -0
- package/dist/admin/copy/status.d.ts +3 -0
- package/dist/admin/copy/status.js +3 -0
- package/dist/admin/placementStatus.model.js +3 -0
- package/dist/admin/status.model.d.ts +3 -2
- package/dist/admin/status.model.js +9 -3
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +31 -11
- package/dist/admin/surface/TestsSurface.js +4 -0
- package/dist/admin/surface/home.model.d.ts +11 -6
- package/dist/admin/surface/home.model.js +19 -8
- package/dist/admin/surface/newTest/PageWizard.js +13 -3
- package/dist/admin/surface/results/ResultsHeader.js +43 -9
- package/dist/admin/surface/test/TestPage.js +11 -1
- package/dist/admin/useLayerUsage.d.ts +1 -1
- package/dist/admin/views/buildSurfaceProps.js +3 -0
- package/dist/cohorts/build.d.ts +35 -0
- package/dist/cohorts/build.js +134 -0
- package/dist/cohorts/key.d.ts +12 -0
- package/dist/cohorts/key.js +15 -0
- package/dist/cohorts/maintenance.d.ts +10 -0
- package/dist/cohorts/maintenance.js +70 -0
- package/dist/cohorts/readiness.d.ts +30 -0
- package/dist/cohorts/readiness.js +54 -0
- package/dist/cohorts/readinessData.d.ts +29 -0
- package/dist/cohorts/readinessData.js +123 -0
- package/dist/cohorts/rule.d.ts +33 -0
- package/dist/cohorts/rule.js +50 -0
- package/dist/collections/cohortMembers.d.ts +4 -0
- package/dist/collections/cohortMembers.js +95 -0
- package/dist/collections/experiments/config.js +157 -7
- package/dist/collections/experiments/editability.js +10 -6
- package/dist/collections/experiments/lockHook.js +39 -20
- package/dist/collections/index.js +4 -1
- package/dist/collections/phases.js +4 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/db/adapter.d.ts +1 -1
- package/dist/db/adapter.js +14 -4
- package/dist/db/appends.js +1 -1
- package/dist/db/cohortMembership.d.ts +11 -0
- package/dist/db/cohortMembership.js +31 -0
- package/dist/db/cohortPool.d.ts +9 -0
- package/dist/db/cohortPool.js +53 -0
- package/dist/db/cohortTransactions.d.ts +3 -0
- package/dist/db/cohortTransactions.js +52 -0
- package/dist/db/cohorts.d.ts +72 -0
- package/dist/db/cohorts.js +280 -0
- package/dist/db/erase.d.ts +2 -0
- package/dist/db/erase.js +21 -2
- package/dist/db/events.d.ts +2 -0
- package/dist/db/events.js +8 -0
- package/dist/db/executor.d.ts +2 -0
- package/dist/db/executor.js +8 -0
- package/dist/db/locks.d.ts +7 -0
- package/dist/db/locks.js +13 -1
- package/dist/db/names.d.ts +95 -1
- package/dist/db/names.js +95 -1
- package/dist/db/occupancy.d.ts +21 -0
- package/dist/db/occupancy.js +46 -0
- package/dist/db/pageOccupancy.d.ts +4 -4
- package/dist/db/pageOccupancy.js +13 -10
- package/dist/db/pgExecutor.d.ts +4 -0
- package/dist/db/pgExecutor.js +1 -1
- package/dist/db/placements.js +1 -1
- package/dist/db/results.d.ts +5 -2
- package/dist/db/results.js +32 -5
- package/dist/db/slices.d.ts +9 -2
- package/dist/db/slices.js +15 -8
- package/dist/db/snapshots.d.ts +16 -1
- package/dist/db/snapshots.js +27 -2
- package/dist/db/sql.d.ts +2 -2
- package/dist/db/sql.js +1 -2
- package/dist/endpoints/cohortSources.d.ts +16 -0
- package/dist/endpoints/cohortSources.js +335 -0
- package/dist/endpoints/contentLocale.d.ts +1 -1
- package/dist/endpoints/events.js +82 -18
- package/dist/endpoints/index.js +45 -1
- package/dist/endpoints/pausedBy.d.ts +14 -0
- package/dist/endpoints/pausedBy.js +94 -0
- package/dist/endpoints/preflight.js +4 -1
- package/dist/endpoints/previewToken.js +2 -0
- package/dist/endpoints/results.d.ts +2 -2
- package/dist/endpoints/results.js +111 -3
- package/dist/endpoints/routeId.d.ts +2 -1
- package/dist/endpoints/routeId.js +6 -2
- package/dist/endpoints/summary.js +24 -1
- package/dist/endpoints/transitions.d.ts +7 -0
- package/dist/endpoints/transitions.js +50 -1
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +5 -3
- package/dist/exports/index.d.ts +2 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/runtimeProxy.d.ts +1 -0
- package/dist/exports/runtimeProxy.js +1 -0
- package/dist/hooks/blockRemovalRule.js +7 -4
- package/dist/hooks/pageGuard.js +1 -1
- package/dist/labels/status.d.ts +15 -0
- package/dist/labels/status.js +12 -0
- package/dist/manifest/compile.d.ts +15 -4
- package/dist/manifest/compile.js +91 -3
- package/dist/onInit.js +4 -1
- package/dist/options.d.ts +1 -0
- package/dist/options.js +10 -0
- package/dist/proxy/consentFallback.d.ts +1 -1
- package/dist/proxy/consentFallback.js +4 -4
- package/dist/proxy/control.d.ts +1 -1
- package/dist/proxy/control.js +2 -2
- package/dist/proxy/pageRewrite.d.ts +1 -1
- package/dist/proxy/pageRewrite.js +3 -2
- package/dist/proxy/resolve.js +76 -17
- package/dist/puck/ExperimentPicker.js +2 -1
- package/dist/puck/copy.d.ts +6 -5
- package/dist/puck/copy.js +3 -7
- package/dist/puck/editor/ExperimentSlotEditor.js +16 -5
- package/dist/puck/editor/QuickTestActions.js +7 -1
- package/dist/puck/editor/armWrites.js +6 -1
- package/dist/puck/editor/copy.d.ts +3 -0
- package/dist/puck/editor/copy.js +3 -0
- package/dist/puck/editor/editor.css +2 -1
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +2 -0
- package/dist/puck/editor/placementsCache.d.ts +1 -1
- package/dist/puck/editor/placementsCache.js +6 -3
- package/dist/results/analyse.d.ts +3 -1
- package/dist/results/analyse.js +20 -3
- package/dist/results/health.d.ts +11 -0
- package/dist/results/health.js +38 -0
- package/dist/results/power.d.ts +1 -1
- package/dist/results/power.js +1 -1
- package/dist/results/snapshot.d.ts +8 -2
- package/dist/results/snapshot.js +23 -1
- package/dist/results/unitValues.d.ts +48 -0
- package/dist/results/unitValues.js +166 -0
- package/dist/runtime/assign.d.ts +7 -3
- package/dist/runtime/assign.js +12 -4
- package/dist/runtime/cohortCookie.d.ts +15 -0
- package/dist/runtime/cohortCookie.js +72 -0
- package/dist/runtime/cohortLookup.d.ts +9 -0
- package/dist/runtime/cohortLookup.js +25 -0
- package/dist/runtime/eligibility.d.ts +11 -5
- package/dist/runtime/eligibility.js +33 -7
- package/dist/runtime/header.d.ts +1 -0
- package/dist/runtime/header.js +1 -1
- package/dist/runtime/proxyRuntime.js +5 -1
- package/dist/runtime/targeting.d.ts +3 -2
- package/dist/runtime/targeting.js +2 -1
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +41 -4
- package/dist/schedule/activeTime.d.ts +28 -0
- package/dist/schedule/activeTime.js +322 -0
- package/dist/schedule/ranges.d.ts +13 -0
- package/dist/schedule/ranges.js +11 -0
- package/dist/schedule/roundTime.d.ts +10 -0
- package/dist/schedule/roundTime.js +45 -0
- package/dist/schedule/types.d.ts +29 -0
- package/dist/schedule/types.js +1 -0
- package/dist/server/cohortLookup.d.ts +3 -0
- package/dist/server/cohortLookup.js +7 -0
- package/dist/server/eraseUser.d.ts +1 -0
- package/dist/server/getAssignments.js +63 -40
- package/dist/server/previewDraft.d.ts +1 -1
- package/dist/server/previewDraft.js +3 -2
- package/dist/server/recordExposures.js +4 -2
- package/dist/server/runResults.js +97 -150
- package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
- package/dist/testSurface/actions/LifecycleAction.js +15 -5
- package/dist/testSurface/actions/actions.model.d.ts +13 -2
- package/dist/testSurface/actions/actions.model.js +38 -5
- package/dist/testSurface/api.d.ts +13 -1
- package/dist/testSurface/api.js +19 -0
- package/dist/testSurface/copy/actions.d.ts +13 -0
- package/dist/testSurface/copy/actions.js +13 -0
- package/dist/testSurface/copy/cohorts.d.ts +68 -0
- package/dist/testSurface/copy/cohorts.js +81 -0
- package/dist/testSurface/copy/common.d.ts +2 -3
- package/dist/testSurface/copy/common.js +4 -4
- package/dist/testSurface/copy/inputs.d.ts +3 -0
- package/dist/testSurface/copy/inputs.js +3 -0
- package/dist/testSurface/copy/readiness.d.ts +20 -6
- package/dist/testSurface/copy/readiness.js +42 -9
- package/dist/testSurface/copy/results.d.ts +1 -0
- package/dist/testSurface/copy/results.js +1 -0
- package/dist/testSurface/copy/schedule.d.ts +58 -0
- package/dist/testSurface/copy/schedule.js +150 -0
- package/dist/testSurface/copy/surface.d.ts +2 -0
- package/dist/testSurface/copy/surface.js +2 -0
- package/dist/testSurface/copy/testPage.d.ts +12 -2
- package/dist/testSurface/copy/testPage.js +17 -2
- package/dist/testSurface/format/roundProgress.d.ts +13 -1
- package/dist/testSurface/format/roundProgress.js +34 -5
- package/dist/testSurface/format/scheduleStatus.d.ts +34 -0
- package/dist/testSurface/format/scheduleStatus.js +93 -0
- package/dist/testSurface/format/useScheduleClock.d.ts +3 -0
- package/dist/testSurface/format/useScheduleClock.js +20 -0
- package/dist/testSurface/labels.d.ts +4 -9
- package/dist/testSurface/labels.js +2 -7
- package/dist/testSurface/lockedNotice.model.d.ts +2 -2
- package/dist/testSurface/lockedNotice.model.js +16 -3
- package/dist/testSurface/readPreflight.d.ts +3 -0
- package/dist/testSurface/readPreflight.js +14 -0
- package/dist/testSurface/readinessRead.d.ts +2 -2
- package/dist/testSurface/results/DataQualityPanel.js +7 -7
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +34 -6
- package/dist/testSurface/review/cohortEstimate.d.ts +11 -0
- package/dist/testSurface/review/cohortEstimate.js +32 -0
- package/dist/testSurface/surface/contracts.d.ts +2 -1
- package/dist/testSurface/surface/contracts.js +1 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +1 -0
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +3 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +121 -32
- package/dist/testSurface/surface/readiness/Banner.js +29 -11
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -2
- package/dist/testSurface/surface/readiness/readiness.model.js +35 -5
- package/dist/testSurface/surface/readiness/useTransition.js +17 -5
- package/dist/testSurface/surface/results/ResultsBody.js +44 -8
- package/dist/testSurface/surface/results/useResults.d.ts +16 -1
- package/dist/testSurface/surface/results/useResults.js +17 -6
- package/dist/testSurface/surface/test/CohortRuleEditor.d.ts +16 -0
- package/dist/testSurface/surface/test/CohortRuleEditor.js +492 -0
- package/dist/testSurface/surface/test/LengthSection.js +26 -6
- package/dist/testSurface/surface/test/ScheduleDateInput.d.ts +4 -0
- package/dist/testSurface/surface/test/ScheduleDateInput.js +15 -0
- package/dist/testSurface/surface/test/ScheduleSection.d.ts +2 -0
- package/dist/testSurface/surface/test/ScheduleSection.js +322 -0
- package/dist/testSurface/surface/test/Section.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +306 -182
- package/dist/testSurface/surface/test/TestSurface.js +9 -0
- package/dist/testSurface/surface/test/fields.d.ts +2 -1
- package/dist/testSurface/surface/test/fields.js +3 -3
- package/dist/testSurface/surface/test/jumpToSection.d.ts +1 -1
- package/dist/testSurface/surface/test/jumpToSection.js +4 -4
- package/dist/testSurface/surface/test/testPage.css +26 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +12 -1
- package/dist/testSurface/surface/testDocument.model.js +2 -1
- package/dist/testSurface/surface/useTestDocument.js +11 -4
- package/dist/testSurface/targeting/targeting.model.d.ts +2 -1
- package/dist/testSurface/targeting/targeting.model.js +1 -1
- package/dist/testSurface/useApi.d.ts +12 -0
- package/dist/transitions/addMetric.js +5 -2
- package/dist/transitions/allocate.js +6 -1
- package/dist/transitions/assertNoOverlap.d.ts +9 -0
- package/dist/transitions/assertNoOverlap.js +24 -0
- package/dist/transitions/buildCohorts.d.ts +10 -0
- package/dist/transitions/buildCohorts.js +68 -0
- package/dist/transitions/cancelSchedule.d.ts +4 -0
- package/dist/transitions/cancelSchedule.js +42 -0
- package/dist/transitions/checkStart.d.ts +17 -3
- package/dist/transitions/checkStart.js +20 -7
- package/dist/transitions/decide.js +35 -11
- package/dist/transitions/kernel.d.ts +3 -1
- package/dist/transitions/kernel.js +5 -2
- package/dist/transitions/pause.d.ts +4 -0
- package/dist/transitions/pause.js +35 -0
- package/dist/transitions/phaseRecord.d.ts +19 -2
- package/dist/transitions/phaseRecord.js +50 -11
- package/dist/transitions/placementInteractions.js +1 -1
- package/dist/transitions/preflightData.d.ts +11 -3
- package/dist/transitions/preflightData.js +134 -81
- package/dist/transitions/reschedule.d.ts +4 -0
- package/dist/transitions/reschedule.js +58 -0
- package/dist/transitions/resume.d.ts +4 -0
- package/dist/transitions/resume.js +32 -0
- package/dist/transitions/scheduledRound.d.ts +18 -0
- package/dist/transitions/scheduledRound.js +42 -0
- package/dist/transitions/start.d.ts +4 -0
- package/dist/transitions/start.js +136 -55
- package/dist/transitions/startReads.d.ts +14 -0
- package/dist/transitions/startReads.js +27 -0
- package/dist/transitions/stop.d.ts +10 -0
- package/dist/transitions/stop.js +35 -22
- package/dist/types/admin.d.ts +1 -1
- package/dist/types/contracts.d.ts +7 -1
- package/dist/types/endpoints.d.ts +72 -3
- package/dist/types/manifest.d.ts +9 -0
- package/dist/types/runtime.d.ts +5 -0
- package/dist/types/snapshot.d.ts +10 -0
- package/dist/types/status.d.ts +1 -0
- package/dist/types/status.js +1 -0
- package/dist/types/surface.d.ts +1 -0
- package/dist/ui/Feedback.d.ts +9 -6
- package/dist/ui/Feedback.js +10 -9
- package/dist/ui/SelectControl.js +1 -1
- package/dist/ui/ui.css +2 -1
- package/package.json +2 -2
|
@@ -2,7 +2,8 @@ import { cache } from 'react';
|
|
|
2
2
|
import { headers } from 'next/headers.js';
|
|
3
3
|
import { XP_HEADER } from '../constants.js';
|
|
4
4
|
import { assign, fillFlagPoints } from '../runtime/assign.js';
|
|
5
|
-
import {
|
|
5
|
+
import { cohortKeysToResolve, isEntryActive } from '../runtime/eligibility.js';
|
|
6
|
+
import { readSignedUnit } from '../runtime/cookie.js';
|
|
6
7
|
import { decodeAssignmentsHeader } from '../runtime/header.js';
|
|
7
8
|
import { verifyPreviewToken } from '../runtime/previewToken.js';
|
|
8
9
|
import { isBot } from '../runtime/bot.js';
|
|
@@ -13,6 +14,7 @@ import { emptyManifest, rememberManifest, serverManifest, suppressExposure } fro
|
|
|
13
14
|
import { serverRequest } from './request.js';
|
|
14
15
|
import { previewDraft } from './previewDraft.js';
|
|
15
16
|
import { verifiedHeaderRevision } from './headerRevision.js';
|
|
17
|
+
import { resolveServerCohorts } from './cohortLookup.js';
|
|
16
18
|
// The mutable cell lives in React's request cache, never a process-wide user cache.
|
|
17
19
|
const requestCell = cache((_runtime, _userId)=>({
|
|
18
20
|
value: undefined
|
|
@@ -25,8 +27,10 @@ export async function getAssignments(serverRuntime, opts) {
|
|
|
25
27
|
async function readAssignments(runtime, suppliedUser) {
|
|
26
28
|
const requestHeaders = new Headers(await headers());
|
|
27
29
|
const proxy = runtime.proxyRuntime;
|
|
30
|
+
const clock = proxy.now ?? (()=>new Date());
|
|
31
|
+
let now = clock();
|
|
28
32
|
const { request, hasContext, consent } = serverRequest(requestHeaders, proxy.secrets);
|
|
29
|
-
const visitorId = consent === false ? undefined :
|
|
33
|
+
const visitorId = consent === false ? undefined : readSignedUnit(requestHeaders, proxy, now.getTime())?.unitId;
|
|
30
34
|
let payload;
|
|
31
35
|
let payloadFailed = false;
|
|
32
36
|
try {
|
|
@@ -92,7 +96,8 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
92
96
|
secrets: proxy.secrets,
|
|
93
97
|
visitorId,
|
|
94
98
|
userId: headerUserId,
|
|
95
|
-
manifest
|
|
99
|
+
manifest,
|
|
100
|
+
now
|
|
96
101
|
}) : null;
|
|
97
102
|
const mustResolveStaff = Boolean(options?.attributeKeys?.staff && (decoded?.sessionUnknown || unit.sessionUnknown));
|
|
98
103
|
const needsUser = !decoded || decoded.deferred.length > 0 || mustResolveStaff || suppliedUser !== undefined;
|
|
@@ -110,7 +115,7 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
const userId = canAssignUser ? user === undefined ? unit.userId : user ? runtime.userIdOf(user) : undefined : undefined;
|
|
113
|
-
const token = hasContext ? verifyPreviewToken(request.nextUrl.searchParams.get('xp_preview') ?? '', proxy.secrets) : null;
|
|
118
|
+
const token = hasContext ? verifyPreviewToken(request.nextUrl.searchParams.get('xp_preview') ?? '', proxy.secrets, Math.floor(now.getTime() / 1000)) : null;
|
|
114
119
|
const context = {
|
|
115
120
|
visitorId,
|
|
116
121
|
userId,
|
|
@@ -134,20 +139,44 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
134
139
|
return result;
|
|
135
140
|
};
|
|
136
141
|
const lastResort = ()=>rememberManifest(fillHostDefaults(emptyAssignments(context)), emptyManifest());
|
|
142
|
+
const recompute = async (subset)=>{
|
|
143
|
+
const unit = {
|
|
144
|
+
visitorId,
|
|
145
|
+
userId,
|
|
146
|
+
sessionUnknown: context.sessionUnknown
|
|
147
|
+
};
|
|
148
|
+
const opts = {
|
|
149
|
+
...context,
|
|
150
|
+
now
|
|
151
|
+
};
|
|
152
|
+
const keys = cohortKeysToResolve(subset, unit, attributes, opts);
|
|
153
|
+
const pending = resolveServerCohorts(payload, {
|
|
154
|
+
keys,
|
|
155
|
+
visitorId,
|
|
156
|
+
userId
|
|
157
|
+
});
|
|
158
|
+
const cohorts = pending && await pending;
|
|
159
|
+
if (pending) now = clock();
|
|
160
|
+
return assign(subset, unit, attributes, {
|
|
161
|
+
...opts,
|
|
162
|
+
now,
|
|
163
|
+
cohorts
|
|
164
|
+
});
|
|
165
|
+
};
|
|
137
166
|
let result;
|
|
138
167
|
if (payloadFailed) {
|
|
139
168
|
try {
|
|
140
|
-
result = controlAssignments(manifest, context);
|
|
169
|
+
result = controlAssignments(manifest, context, now);
|
|
141
170
|
} catch {
|
|
142
171
|
return lastResort();
|
|
143
172
|
}
|
|
144
173
|
} else if (consent === false && !decoded) {
|
|
145
174
|
try {
|
|
146
|
-
result = consentFallback(manifest, attributes, context);
|
|
175
|
+
result = consentFallback(manifest, attributes, context, now);
|
|
147
176
|
} catch {
|
|
148
177
|
console.error('[payload-experiments] consent fallback failed; serving non-exposable control');
|
|
149
178
|
try {
|
|
150
|
-
result = controlAssignments(manifest, context);
|
|
179
|
+
result = controlAssignments(manifest, context, now);
|
|
151
180
|
} catch {
|
|
152
181
|
return lastResort();
|
|
153
182
|
}
|
|
@@ -162,62 +191,56 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
162
191
|
};
|
|
163
192
|
const slugs = new Set(hasContext ? decoded.deferred : []);
|
|
164
193
|
if (canAssignUser && user !== undefined && userId !== headerUserId) {
|
|
165
|
-
|
|
194
|
+
// Visitor cohort membership can also depend on the user resolved by the server.
|
|
195
|
+
// A signed page assignment already selected the path served by the proxy.
|
|
196
|
+
for (const e of manifest.experiments)if (e.unitType === 'user' || e.kind !== 'page' && e.cohorts?.length) slugs.add(e.slug);
|
|
166
197
|
}
|
|
167
198
|
if (slugs.size && canResolveUser && !userFailed) {
|
|
168
199
|
try {
|
|
169
|
-
const resolved =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
sessionUnknown: context.sessionUnknown
|
|
173
|
-
}, attributes, {
|
|
174
|
-
...context,
|
|
175
|
-
now: Math.floor(Date.now() / 1000)
|
|
200
|
+
const resolved = await recompute({
|
|
201
|
+
...manifest,
|
|
202
|
+
experiments: manifest.experiments.filter((e)=>slugs.has(e.slug))
|
|
176
203
|
});
|
|
177
204
|
for (const slug of slugs){
|
|
178
|
-
result.bySlug[slug] = resolved.bySlug[slug] ?? controlAssignments(manifest, context).bySlug[slug];
|
|
205
|
+
result.bySlug[slug] = resolved.bySlug[slug] ?? controlAssignments(manifest, context, now).bySlug[slug];
|
|
179
206
|
}
|
|
180
207
|
} catch {
|
|
181
208
|
userFailed = true;
|
|
182
209
|
}
|
|
183
210
|
}
|
|
184
|
-
} else if (!visitorId && !userId || !hasContext) result = controlAssignments(manifest, context);
|
|
211
|
+
} else if (!visitorId && !userId || !hasContext) result = controlAssignments(manifest, context, now);
|
|
185
212
|
else {
|
|
186
213
|
try {
|
|
187
|
-
result =
|
|
188
|
-
visitorId,
|
|
189
|
-
userId,
|
|
190
|
-
sessionUnknown: context.sessionUnknown
|
|
191
|
-
}, attributes, {
|
|
192
|
-
...context,
|
|
193
|
-
now: Math.floor(Date.now() / 1000)
|
|
194
|
-
});
|
|
214
|
+
result = await recompute(manifest);
|
|
195
215
|
} catch {
|
|
196
216
|
console.error('[payload-experiments] assign failed; serving non-exposable control');
|
|
197
|
-
result = controlAssignments(manifest, context);
|
|
217
|
+
result = controlAssignments(manifest, context, now);
|
|
198
218
|
}
|
|
199
219
|
}
|
|
200
|
-
//
|
|
201
|
-
|
|
220
|
+
// A signed assignment can cross a schedule boundary before the server renders.
|
|
221
|
+
// Missing users left deferred by assign also need an explicit control.
|
|
222
|
+
const controls = controlAssignments(manifest, context, now);
|
|
202
223
|
for (const experiment of manifest.experiments){
|
|
203
|
-
if (!result.bySlug[experiment.slug]) result.bySlug[experiment.slug] = controls.bySlug[experiment.slug];
|
|
224
|
+
if (!result.bySlug[experiment.slug] || !isEntryActive(experiment, now)) result.bySlug[experiment.slug] = controls.bySlug[experiment.slug];
|
|
204
225
|
}
|
|
205
|
-
fillFlagPoints(result, manifest);
|
|
226
|
+
fillFlagPoints(result, manifest, now);
|
|
206
227
|
fillHostDefaults(result);
|
|
207
228
|
if (token && visitorId && payload) {
|
|
208
229
|
const live = manifest.experiments.find((e)=>e.id === token.e && e.phase === token.p && e.arms.some((a)=>a.key === token.a));
|
|
209
230
|
if (live) {
|
|
210
231
|
result.preview = true;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
if (isEntryActive(live, now)) {
|
|
233
|
+
result.bySlug[live.slug] = {
|
|
234
|
+
slug: live.slug,
|
|
235
|
+
experimentId: live.id,
|
|
236
|
+
arm: token.a,
|
|
237
|
+
phase: token.p,
|
|
238
|
+
policy: live.exposurePolicy,
|
|
239
|
+
exposable: false,
|
|
240
|
+
source: 'preview'
|
|
241
|
+
};
|
|
242
|
+
fillFlagPoints(result, manifest, now);
|
|
243
|
+
}
|
|
221
244
|
} else await previewDraft(payload, await resolveUser(), token, result, requestHeaders);
|
|
222
245
|
}
|
|
223
246
|
if (suppressExposure(result) || !hasContext || payloadFailed || userFailed || mustResolveStaff && !runtime.getUser && suppliedUser === undefined) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Payload } from 'payload';
|
|
2
2
|
import type { PreviewToken } from '../runtime/previewToken.js';
|
|
3
3
|
import type { Assignments } from '../types/assignments.js';
|
|
4
|
-
/**
|
|
4
|
+
/** Previews outside the manifest use the authenticated manager's normal collection access. */
|
|
5
5
|
export declare function previewDraft(payload: Payload, user: {
|
|
6
6
|
id: string | number;
|
|
7
7
|
} | null, token: PreviewToken, assignments: Assignments, headers: Headers): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Previews outside the manifest use the authenticated manager's normal collection access. */ export async function previewDraft(payload, user, token, assignments, headers) {
|
|
2
2
|
if (!user) return;
|
|
3
3
|
try {
|
|
4
4
|
const doc = await payload.findByID({
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
headers
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
if (doc.status !== 'draft' && doc.status !== 'stopped' || doc.phase !== token.p || typeof doc.slug !== 'string' || !Array.isArray(doc.arms)) return;
|
|
15
|
+
if (doc.status !== 'draft' && doc.status !== 'stopped' && doc.status !== 'paused' || doc.phase !== token.p || typeof doc.slug !== 'string' || !Array.isArray(doc.arms)) return;
|
|
16
16
|
const arm = doc.arms.find((a)=>a.key === token.a);
|
|
17
17
|
if (!arm || ![
|
|
18
18
|
'render',
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
'manual'
|
|
22
22
|
].includes(doc.exposurePolicy)) return;
|
|
23
23
|
assignments.preview = true;
|
|
24
|
+
if (doc.status === 'paused') return;
|
|
24
25
|
assignments.bySlug[doc.slug] = {
|
|
25
26
|
slug: doc.slug,
|
|
26
27
|
experimentId: doc.id,
|
|
@@ -4,6 +4,7 @@ import { insertEvents } from '../db/events.js';
|
|
|
4
4
|
import { exposureDimensions } from '../events/dimensions.js';
|
|
5
5
|
import { requestAttributesOf } from './context.js';
|
|
6
6
|
import { readManifestRow } from '../db/manifest.js';
|
|
7
|
+
import { isEntryActive } from '../runtime/eligibility.js';
|
|
7
8
|
export async function recordExposures(serverRuntime, rendered, ctx) {
|
|
8
9
|
let payload;
|
|
9
10
|
try {
|
|
@@ -18,7 +19,8 @@ export async function recordExposures(serverRuntime, rendered, ctx) {
|
|
|
18
19
|
});
|
|
19
20
|
if (!candidates.length) return;
|
|
20
21
|
const { visitorId, userId } = ctx;
|
|
21
|
-
const
|
|
22
|
+
const now = serverRuntime.proxyRuntime?.now?.() ?? new Date();
|
|
23
|
+
const ts = now.toISOString();
|
|
22
24
|
payload = await serverRuntime.getPayload();
|
|
23
25
|
const options = payload.config?.custom?.xp;
|
|
24
26
|
const dimensions = exposureDimensions(requestAttributesOf(ctx), options?.events?.dimensions);
|
|
@@ -27,7 +29,7 @@ export async function recordExposures(serverRuntime, rendered, ctx) {
|
|
|
27
29
|
const manifest = await readManifestRow(exec);
|
|
28
30
|
const rows = candidates.flatMap((assignment)=>{
|
|
29
31
|
const experiment = manifest?.manifest.experiments.find((exp)=>exp.id === assignment.experimentId && exp.slug === assignment.slug);
|
|
30
|
-
if (!experiment) return [];
|
|
32
|
+
if (!experiment || !isEntryActive(experiment, now)) return [];
|
|
31
33
|
const unitId = experiment.unitType === 'visitor' ? visitorId : userId;
|
|
32
34
|
if (!unitId) return [];
|
|
33
35
|
return [
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { refreshCohorts, sweepCohorts } from '../cohorts/maintenance.js';
|
|
2
|
+
import { isCohortRule } from '../cohorts/rule.js';
|
|
3
|
+
import { cohortExitedUnits } from '../db/cohorts.js';
|
|
4
|
+
import { withCohortExitDefault } from '../results/snapshot.js';
|
|
5
|
+
import { metricUnitValues, readUnitMetricEvents, unitValueContext } from '../results/unitValues.js';
|
|
1
6
|
import { asymmetricGoal, goalContent, goalPlacementDetail, LEGACY_FAIRNESS } from '../goals/fairness.js';
|
|
2
7
|
import { XpAnalysisError } from '../errors.js';
|
|
3
|
-
import { canonicalHealth, mergePageHealth, rapidBrowserEvents } from '../results/health.js';
|
|
8
|
+
import { canonicalHealth, cohortNoExposures, mergePageHealth, rapidBrowserEvents } from '../results/health.js';
|
|
4
9
|
import { safeError } from '../log.js';
|
|
5
10
|
import { createLocalReq } from 'payload';
|
|
6
|
-
import { resultsCandidates, resultsExecutor, writeSnapshots } from '../db/snapshots.js';
|
|
11
|
+
import { dueScheduledStops, resultsCandidates, resultsExecutor, writeSnapshots } from '../db/snapshots.js';
|
|
12
|
+
import { DAY_MS } from '../schedule/roundTime.js';
|
|
7
13
|
import { sweepEvents } from '../db/sweep.js';
|
|
8
|
-
import { armMismatchCount,
|
|
14
|
+
import { armMismatchCount, phaseExposureRows, rolloutExposureRows } from '../db/results.js';
|
|
9
15
|
import { raceDeadline, ResultsBudgetError, RESULTS_TIMEOUT_MARGIN_MS } from '../db/executor.js';
|
|
10
16
|
import { analysePhase } from '../results/analyse.js';
|
|
11
17
|
import { firstExposures, perUnitValues, timestampMs } from '../results/aggregate.js';
|
|
12
18
|
import { rolloutAnalysisUnits } from '../results/rolloutUnits.js';
|
|
13
|
-
import {
|
|
19
|
+
import { eligibleIdentityLinks } from '../results/identityCredit.js';
|
|
20
|
+
import { stopScheduledExperiment } from '../transitions/stop.js';
|
|
14
21
|
function* convertingUnits(units, values, ages) {
|
|
15
22
|
for (const [id, value] of values){
|
|
16
23
|
if (value > 0) yield {
|
|
@@ -30,11 +37,14 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
30
37
|
weight: arm.kind === 'holdout' ? candidate.testArms.at(-1).weight : 100 - candidate.testArms.at(-1).weight
|
|
31
38
|
}))
|
|
32
39
|
} : phase;
|
|
33
|
-
const to = new Date(Math.min(+now, phase.endedAt == null ? Infinity : timestampMs(phase.endedAt)));
|
|
40
|
+
const to = new Date(Math.min(+now, phase.endedAt == null ? Infinity : timestampMs(phase.endedAt), phase.schedule?.endAt ? timestampMs(phase.schedule.endAt) : Infinity));
|
|
34
41
|
const query = {
|
|
35
42
|
experimentId: phase.experiment,
|
|
36
43
|
phase: phase.phase,
|
|
37
|
-
|
|
44
|
+
startedAt: phase.startedAt,
|
|
45
|
+
endedAt: to,
|
|
46
|
+
schedule: phase.schedule,
|
|
47
|
+
pauses: phase.pauses
|
|
38
48
|
};
|
|
39
49
|
const exposed = firstExposures(await phaseExposureRows(exec, query), {
|
|
40
50
|
endedAt: to
|
|
@@ -43,8 +53,9 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
43
53
|
if (phase.phaseKind === 'rollout') {
|
|
44
54
|
const eligible = rolloutAnalysisUnits({
|
|
45
55
|
exposuresAllPhases: await rolloutExposureRows(exec, {
|
|
46
|
-
|
|
47
|
-
respectPhaseEnds: true
|
|
56
|
+
experimentId: phase.experiment,
|
|
57
|
+
respectPhaseEnds: true,
|
|
58
|
+
now: to
|
|
48
59
|
}),
|
|
49
60
|
rolloutPhase: phase.phase,
|
|
50
61
|
seed: phase.seed,
|
|
@@ -65,110 +76,29 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
65
76
|
// An age on an exposure is only written by browser ingestion, including
|
|
66
77
|
// browser-side manual exposures. Server-recorded exposures have unknown age.
|
|
67
78
|
let rapidActivity = rapidBrowserEvents(comparedArms, units.values());
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
];
|
|
71
|
-
const identities = candidate.unitType === 'visitor' ? await identityRows(exec, {
|
|
72
|
-
anonymousIds: ids
|
|
73
|
-
}) : [];
|
|
74
|
-
const userIds = [
|
|
75
|
-
...new Set(identities.map((identity)=>identity.userId))
|
|
76
|
-
];
|
|
77
|
-
const linked = new Set(userIds);
|
|
78
|
-
const identityConflicts = new Set();
|
|
79
|
-
const userByVisitor = new Map(identities.map((identity)=>[
|
|
80
|
-
identity.anonymousId,
|
|
81
|
-
identity.userId
|
|
82
|
-
]));
|
|
83
|
-
const linksByUser = new Map();
|
|
84
|
-
for (const identity of identities){
|
|
85
|
-
const links = linksByUser.get(identity.userId) ?? [];
|
|
86
|
-
links.push(identity);
|
|
87
|
-
linksByUser.set(identity.userId, links);
|
|
88
|
-
}
|
|
89
|
-
// Last arm credited per user: enough to detect that a user's credited events span arms (a conflict).
|
|
90
|
-
const creditedArms = new Map();
|
|
91
|
-
const noteCredit = (userId, unitId)=>{
|
|
92
|
-
const arm = units.get(unitId)?.arm;
|
|
93
|
-
if (arm === undefined) return;
|
|
94
|
-
const previous = creditedArms.get(userId);
|
|
95
|
-
if (previous !== undefined && previous !== arm) identityConflicts.add(userId);
|
|
96
|
-
creditedArms.set(userId, arm);
|
|
97
|
-
};
|
|
98
|
-
const credit = (events, userKeyed)=>{
|
|
99
|
-
if (candidate.unitType === 'user') return events.map((event)=>({
|
|
100
|
-
...event,
|
|
101
|
-
unitId: event.userId ?? event.unitId
|
|
102
|
-
}));
|
|
103
|
-
// §8.3's earliest exposed linked visitor applies only when the event has no
|
|
104
|
-
// exposed unit of its own. A visitor-keyed event stays on its own exposed
|
|
105
|
-
// browser even if an earlier linked browser saw another arm or is ineligible.
|
|
106
|
-
const direct = userKeyed ? [] : events.filter((event)=>units.has(event.unitId) || event.userId == null || !linked.has(event.userId));
|
|
107
|
-
const userEvents = events.filter((event)=>userKeyed || !units.has(event.unitId) && event.userId != null && linked.has(event.userId)).map((event)=>({
|
|
108
|
-
...event,
|
|
109
|
-
userId: String(event.userId ?? event.unitId)
|
|
110
|
-
}));
|
|
111
|
-
const credited = creditUserEvents(units, identities, userEvents, (userId)=>identityConflicts.add(userId)).events;
|
|
112
|
-
for (const event of direct)if (event.userId != null && linked.has(event.userId)) {
|
|
113
|
-
noteCredit(event.userId, event.unitId);
|
|
114
|
-
// Keep the eligible-link diagnostic when direct credit bypasses the helper.
|
|
115
|
-
const arms = new Set(eligibleIdentityLinks(linksByUser.get(event.userId), event.ts).map((link)=>units.get(link.anonymousId).arm));
|
|
116
|
-
arms.add(units.get(event.unitId).arm);
|
|
117
|
-
if (arms.size > 1) identityConflicts.add(event.userId);
|
|
118
|
-
}
|
|
119
|
-
for (const event of credited)noteCredit(userByVisitor.get(event.unitId), event.unitId);
|
|
120
|
-
return [
|
|
121
|
-
...direct,
|
|
122
|
-
...credited
|
|
123
|
-
];
|
|
124
|
-
};
|
|
79
|
+
const context = await unitValueContext(exec, candidate.unitType, units);
|
|
80
|
+
const { identities, userIds, identityConflicts } = context;
|
|
125
81
|
const metricData = [];
|
|
126
82
|
for (const definition of phase.metricDefinitions){
|
|
127
83
|
try {
|
|
128
84
|
if (Date.now() >= deadline) throw new ResultsBudgetError();
|
|
129
|
-
const kind = definition.kind;
|
|
130
|
-
const windowHours = phase.analysis.attributionWindowHours ?? definition.attributionWindowHours ?? 168;
|
|
131
|
-
const from = new Date([
|
|
132
|
-
...units.values()
|
|
133
|
-
].reduce((earliest, unit)=>Math.min(earliest, +unit.firstTs), timestampMs(phase.startedAt)));
|
|
134
|
-
const preFrom = new Date(+from - 14 * 86_400_000);
|
|
135
85
|
const storedEvents = definition.source.startsWith('events:') || definition.source.startsWith('click:');
|
|
136
86
|
const readAge = storedEvents && definition.role === 'primary' && !rapidActivity;
|
|
137
|
-
|
|
87
|
+
const input = await readUnitMetricEvents(exec, {
|
|
88
|
+
phase,
|
|
89
|
+
unitType: candidate.unitType,
|
|
90
|
+
units,
|
|
91
|
+
context,
|
|
92
|
+
definition,
|
|
93
|
+
options,
|
|
94
|
+
to,
|
|
95
|
+
deadline,
|
|
96
|
+
readAge,
|
|
97
|
+
includePrePeriod: phase.analysis.cuped === 'auto'
|
|
98
|
+
});
|
|
99
|
+
const { events, source, userKeyed, kind } = input;
|
|
100
|
+
let covariates;
|
|
138
101
|
if (storedEvents) {
|
|
139
|
-
const eventName = definition.source.startsWith('click:') ? definition.source : definition.source.slice(7);
|
|
140
|
-
if (!definition.source.startsWith('click:') && !options.eventSources?.some((source)=>source.name === eventName)) throw new XpAnalysisError('source-unavailable');
|
|
141
|
-
const read = async (start)=>{
|
|
142
|
-
if (candidate.unitType === 'user') return metricEventRows(exec, {
|
|
143
|
-
eventName,
|
|
144
|
-
userIds: ids,
|
|
145
|
-
from: start,
|
|
146
|
-
to,
|
|
147
|
-
readAge
|
|
148
|
-
});
|
|
149
|
-
const direct = await metricEventRows(exec, {
|
|
150
|
-
eventName,
|
|
151
|
-
unitIds: ids,
|
|
152
|
-
from: start,
|
|
153
|
-
to,
|
|
154
|
-
readAge,
|
|
155
|
-
forVisitors: true
|
|
156
|
-
});
|
|
157
|
-
const signedIn = await metricEventRows(exec, {
|
|
158
|
-
eventName,
|
|
159
|
-
userIds,
|
|
160
|
-
from: start,
|
|
161
|
-
to,
|
|
162
|
-
readAge,
|
|
163
|
-
forVisitors: true
|
|
164
|
-
});
|
|
165
|
-
// The two lookups overlap when a linked user's own browser was exposed.
|
|
166
|
-
return [
|
|
167
|
-
...direct,
|
|
168
|
-
...signedIn.filter((event)=>!units.has(event.unitId))
|
|
169
|
-
];
|
|
170
|
-
};
|
|
171
|
-
events = credit(await read(phase.analysis.cuped === 'auto' ? preFrom : from), false);
|
|
172
102
|
if (phase.analysis.cuped === 'auto') {
|
|
173
103
|
const preUnits = new Map([
|
|
174
104
|
...units
|
|
@@ -176,7 +106,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
176
106
|
id,
|
|
177
107
|
{
|
|
178
108
|
arm: unit.arm,
|
|
179
|
-
firstTs: new Date(+unit.firstTs - 14 *
|
|
109
|
+
firstTs: new Date(+unit.firstTs - 14 * DAY_MS)
|
|
180
110
|
}
|
|
181
111
|
]));
|
|
182
112
|
covariates = perUnitValues(preUnits, events, {
|
|
@@ -185,17 +115,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
185
115
|
});
|
|
186
116
|
}
|
|
187
117
|
} else {
|
|
188
|
-
|
|
189
|
-
if (!source || source.kind !== kind || definition.keyedBy && source.keyedBy !== definition.keyedBy) throw new XpAnalysisError('source-unavailable');
|
|
190
|
-
const userKeyed = source.keyedBy === 'user' && candidate.unitType === 'visitor';
|
|
191
|
-
if (candidate.unitType === 'user' && source.keyedBy !== 'user') throw new XpAnalysisError('unit-type-unavailable');
|
|
192
|
-
const sourceIds = userKeyed ? userIds : ids;
|
|
193
|
-
events = credit(await raceDeadline(deadline, ()=>source.query({
|
|
194
|
-
from,
|
|
195
|
-
to,
|
|
196
|
-
unitIds: sourceIds
|
|
197
|
-
})), userKeyed);
|
|
198
|
-
if (phase.analysis.cuped === 'auto' && source.covariate) {
|
|
118
|
+
if (phase.analysis.cuped === 'auto' && source?.covariate) {
|
|
199
119
|
const userUnits = new Map();
|
|
200
120
|
if (userKeyed) for (const link of identities){
|
|
201
121
|
const unit = units.get(link.anonymousId);
|
|
@@ -240,26 +160,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
240
160
|
}));
|
|
241
161
|
}
|
|
242
162
|
}
|
|
243
|
-
|
|
244
|
-
// The click-goal delta supersedes whole-phase attribution for mid-test adds.
|
|
245
|
-
// Retain pre-period events for CUPED above; exclude them from the outcome.
|
|
246
|
-
const outcomeEvents = definition.source.startsWith('click:') && definition.addedAt ? events.filter((event)=>timestampMs(event.ts) >= timestampMs(definition.addedAt)) : events;
|
|
247
|
-
const ages = new Map();
|
|
248
|
-
const values = perUnitValues(units, outcomeEvents, {
|
|
249
|
-
kind,
|
|
250
|
-
windowHours,
|
|
251
|
-
endedAt: to,
|
|
252
|
-
onAttributed: readAge ? (event, ts)=>{
|
|
253
|
-
if (event.unitAgeMs === undefined) return;
|
|
254
|
-
const previous = ages.get(event.unitId);
|
|
255
|
-
if (!previous || ts < previous.ts || ts === previous.ts && event.unitAgeMs > previous.unitAgeMs) {
|
|
256
|
-
ages.set(event.unitId, {
|
|
257
|
-
ts,
|
|
258
|
-
unitAgeMs: event.unitAgeMs
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
} : undefined
|
|
262
|
-
});
|
|
163
|
+
const { values, ages } = metricUnitValues(units, definition, input, to, readAge);
|
|
263
164
|
if (ages.size) rapidActivity = rapidBrowserEvents(comparedArms, convertingUnits(units, values, ages));
|
|
264
165
|
metricData.push({
|
|
265
166
|
metricId: definition.metricId,
|
|
@@ -299,7 +200,14 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
299
200
|
if (error instanceof ResultsBudgetError || Date.now() >= deadline) throw new ResultsBudgetError();
|
|
300
201
|
}
|
|
301
202
|
}
|
|
302
|
-
const
|
|
203
|
+
const currentStatus = candidate.status === 'paused' ? 'running' : candidate.status // 0.5 T3/T8 refines
|
|
204
|
+
;
|
|
205
|
+
const status = phase.endedAt != null || currentStatus === 'archived' ? 'stopped' : currentStatus;
|
|
206
|
+
const exits = new Set();
|
|
207
|
+
if (phase.phaseKind === 'test') for (const rule of phase.targeting ?? []){
|
|
208
|
+
if (!isCohortRule(rule) || !('key' in rule)) continue;
|
|
209
|
+
for (const id of (await cohortExitedUnits(exec, rule, candidate.unitType, units)))exits.add(id);
|
|
210
|
+
}
|
|
303
211
|
const snapshot = analysePhase({
|
|
304
212
|
phase: analysisPhase,
|
|
305
213
|
now,
|
|
@@ -312,6 +220,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
312
220
|
metricId
|
|
313
221
|
}, 'Experiment metric analysis failed'),
|
|
314
222
|
excludedMultiArm: exposed.excludedMultiArm,
|
|
223
|
+
cohortExits: exits.size,
|
|
315
224
|
armMismatch: await armMismatchCount(exec, query),
|
|
316
225
|
identityConflictShare: userIds.length ? identityConflicts.size / userIds.length : 0,
|
|
317
226
|
...phase.phaseKind === 'rollout' ? {
|
|
@@ -319,16 +228,16 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
319
228
|
controlLabel: candidate.testArms.find((arm)=>arm.kind === 'control')?.label
|
|
320
229
|
} : {}
|
|
321
230
|
});
|
|
322
|
-
if (rapidActivity) snapshot.health
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
];
|
|
231
|
+
if (rapidActivity) (snapshot.health ??= []).push({
|
|
232
|
+
code: 'rapid-browser-events'
|
|
233
|
+
});
|
|
234
|
+
const cohortHealth = phase.phaseKind === 'test' && phase.endedAt == null ? cohortNoExposures(phase, candidate.status, now, exposed.units.size + exposed.excludedMultiArm) : undefined;
|
|
235
|
+
if (cohortHealth) (snapshot.health ??= []).push(cohortHealth);
|
|
327
236
|
return snapshot;
|
|
328
237
|
}
|
|
329
238
|
export async function runResults(payload, { budgetMs = 20_000, experimentId, sweep = true } = {}) {
|
|
330
239
|
if (!Number.isFinite(budgetMs) || budgetMs < 0) throw new RangeError('budgetMs must be finite and nonnegative');
|
|
331
|
-
const started = Date.now(), deadline = started + budgetMs
|
|
240
|
+
const started = Date.now(), deadline = started + budgetMs;
|
|
332
241
|
const summary = {
|
|
333
242
|
ran: 0,
|
|
334
243
|
skipped: 0,
|
|
@@ -344,15 +253,44 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
344
253
|
budgetExhausted: true
|
|
345
254
|
};
|
|
346
255
|
const options = payload.config.custom?.xp;
|
|
256
|
+
const now = options.runtime?.proxyRuntime.now?.() ?? new Date(started);
|
|
347
257
|
const retentionDays = options.events?.retentionDays ?? 180;
|
|
348
258
|
// Reserve up to one second (25% of short runs) for retention, even when host
|
|
349
259
|
// code never settles. The safety margin also leaves time to return the summary.
|
|
350
260
|
const analysisDeadline = deadline - (sweep ? Math.min(1000, budgetMs / 4) : 0) - RESULTS_TIMEOUT_MARGIN_MS;
|
|
351
261
|
const exec = resultsExecutor(payload, ()=>analysisDeadline - Date.now());
|
|
352
262
|
let candidates = [];
|
|
263
|
+
const failedStops = new Set();
|
|
353
264
|
try {
|
|
265
|
+
const due = await dueScheduledStops(exec, now.toISOString(), experimentId);
|
|
266
|
+
for (const { id, phase } of due){
|
|
267
|
+
if (Date.now() >= analysisDeadline) throw new ResultsBudgetError();
|
|
268
|
+
try {
|
|
269
|
+
const req = await raceDeadline(analysisDeadline, ()=>createLocalReq({}, payload));
|
|
270
|
+
await stopScheduledExperiment(req, {
|
|
271
|
+
experimentId: id,
|
|
272
|
+
phase,
|
|
273
|
+
dueBy: now,
|
|
274
|
+
deadline: analysisDeadline
|
|
275
|
+
});
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error instanceof ResultsBudgetError) throw error;
|
|
278
|
+
// Leave this round out until its exact cutoff can be committed.
|
|
279
|
+
failedStops.add(String(id));
|
|
280
|
+
summary.skipped++;
|
|
281
|
+
summary.failed++;
|
|
282
|
+
payload.logger.error({
|
|
283
|
+
err: safeError(error),
|
|
284
|
+
experimentId: id
|
|
285
|
+
}, 'Scheduled experiment stop failed');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (experimentId === undefined) await refreshCohorts(payload, {
|
|
289
|
+
now,
|
|
290
|
+
budgetMs: Math.max(0, Math.min(budgetMs / 4, analysisDeadline - Date.now()))
|
|
291
|
+
});
|
|
354
292
|
candidates = await resultsCandidates(exec, {
|
|
355
|
-
cutoff: new Date(
|
|
293
|
+
cutoff: new Date(+now - retentionDays * DAY_MS).toISOString(),
|
|
356
294
|
experimentId
|
|
357
295
|
});
|
|
358
296
|
} catch (error) {
|
|
@@ -369,26 +307,30 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
369
307
|
const experiments = new Map();
|
|
370
308
|
for (const candidate of candidates){
|
|
371
309
|
const id = candidate.phase.experiment;
|
|
310
|
+
// A scheduled round can still be canceled and must have no results before go-live.
|
|
311
|
+
if (failedStops.has(String(id)) || timestampMs(candidate.phase.startedAt) > +now) continue;
|
|
372
312
|
experiments.set(id, [
|
|
373
313
|
...experiments.get(id) ?? [],
|
|
374
314
|
candidate
|
|
375
315
|
]);
|
|
376
316
|
}
|
|
317
|
+
let remaining = experiments.size;
|
|
377
318
|
for (const [id, phases] of experiments){
|
|
378
319
|
if (Date.now() >= analysisDeadline) {
|
|
379
320
|
summary.budgetExhausted = true;
|
|
380
|
-
summary.skipped +=
|
|
321
|
+
summary.skipped += remaining;
|
|
381
322
|
break;
|
|
382
323
|
}
|
|
324
|
+
remaining--;
|
|
383
325
|
try {
|
|
384
326
|
const snapshots = [];
|
|
385
327
|
for (const phase of phases){
|
|
386
328
|
if (Date.now() >= analysisDeadline) throw new ResultsBudgetError();
|
|
387
329
|
// Health refreshes must not reopen inference after the late-beacon grace.
|
|
388
|
-
snapshots.push(phase.frozenSnapshot ? {
|
|
330
|
+
snapshots.push(phase.frozenSnapshot ? withCohortExitDefault({
|
|
389
331
|
...phase.frozenSnapshot,
|
|
390
332
|
computedAt: now.toISOString()
|
|
391
|
-
} : await analyseCandidate(exec, phase, options, now, analysisDeadline, summary.unavailableMetrics, payload.logger));
|
|
333
|
+
}) : await analyseCandidate(exec, phase, options, now, analysisDeadline, summary.unavailableMetrics, payload.logger));
|
|
392
334
|
}
|
|
393
335
|
if (Date.now() >= analysisDeadline) throw new ResultsBudgetError();
|
|
394
336
|
const current = phases.find((candidate)=>candidate.phase.phase === candidate.currentPhase && (candidate.status === 'running' || candidate.status === 'decided'));
|
|
@@ -444,12 +386,12 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
444
386
|
for (const [index, snapshot] of snapshots.entries()){
|
|
445
387
|
const previous = phases[index].previousHealth ?? phases[index].frozenSnapshot?.health ?? [];
|
|
446
388
|
const unjudged = previous.filter((row)=>row.code === 'goal-in-some-versions' && content && content.unchecked.length > 0 && clicks.some((metric)=>metric.metricId === row.metricId && !asymmetricGoal(content, metric.source, arms)));
|
|
447
|
-
const
|
|
389
|
+
const roundHealth = snapshot.health?.filter((row)=>row.code !== 'placement-unchecked' && row.code !== 'goal-in-some-versions' && row.code !== 'version-page-unchecked' && row.code !== 'version-page-unavailable') ?? [];
|
|
448
390
|
snapshot.health = mergePageHealth(unjudged, [
|
|
449
391
|
...health,
|
|
450
392
|
...goals,
|
|
451
393
|
...unchecked,
|
|
452
|
-
...
|
|
394
|
+
...roundHealth
|
|
453
395
|
]);
|
|
454
396
|
if (content?.skipped && current.kind === 'block') snapshot.goalFairnessNotice = LEGACY_FAIRNESS;
|
|
455
397
|
else delete snapshot.goalFairnessNotice;
|
|
@@ -495,6 +437,11 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
495
437
|
const sweepDeadline = deadline - RESULTS_TIMEOUT_MARGIN_MS;
|
|
496
438
|
try {
|
|
497
439
|
const sweepExec = resultsExecutor(payload, ()=>sweepDeadline - Date.now());
|
|
440
|
+
await sweepCohorts(payload, {
|
|
441
|
+
now,
|
|
442
|
+
retentionDays,
|
|
443
|
+
deadline: Date.now() + Math.max(0, (sweepDeadline - Date.now()) / 2)
|
|
444
|
+
});
|
|
498
445
|
summary.swept = await sweepEvents(sweepExec, {
|
|
499
446
|
now,
|
|
500
447
|
retentionDays,
|
|
@@ -9,9 +9,10 @@ export declare function LifecycleButton({ action, reason, showReason, disabled,
|
|
|
9
9
|
busy?: boolean;
|
|
10
10
|
onClick: () => void;
|
|
11
11
|
}): import("react").JSX.Element;
|
|
12
|
-
export declare function LifecycleDialog({ action, test, surface, onClose }: {
|
|
12
|
+
export declare function LifecycleDialog({ action, test, surface, onClose, onSuccess }: {
|
|
13
13
|
action: ExperimentAction;
|
|
14
14
|
test: ActionTestApi;
|
|
15
15
|
surface: SurfaceProps;
|
|
16
16
|
onClose: () => void;
|
|
17
|
+
onSuccess?: () => void;
|
|
17
18
|
}): import("react").JSX.Element;
|