@@ -7710,7 +7710,8 @@ export class ExactReviewQueue {
77107710 }
77117711
77127712 private refreshPublicationControlSync(state: ExactReviewQueueState, now: number) {
7713- const current = this.publicationControlSync();
7713+ const stored = this.storage.kv.get(EXACT_REVIEW_PUBLICATION_CONTROL_KEY);
7714+ const current = exactReviewPublicationControl(this.env, stored);
77147715 const publications = Object.values(state.items).filter(exactReviewQueueIsPublication);
77157716 const pending = publications.filter((item) => item.state === "pending");
77167717 const oldestPendingAt = pending.reduce<number | null>(
@@ -7724,7 +7725,7 @@ export class ExactReviewQueue {
77247725 oldestPendingAgeMs: oldestPendingAt === null ? 0 : Math.max(0, now - oldestPendingAt),
77257726 netDrainRatePerHour: flow.net_drain_rate_per_hour,
77267727 });
7727- if (stableJson(next) !== stableJson(current )) {
7728+ if (stableJson(next) !== stableJson(objectValue(stored) )) {
77287729 this.storage.kv.put(EXACT_REVIEW_PUBLICATION_CONTROL_KEY, next);
77297730 }
77307731 return next;
@@ -11819,19 +11820,31 @@ function exactReviewPublicationControl(env, value: unknown): ExactReviewPublicat
1181911820 const control = objectValue(value);
1182011821 const maximum = exactReviewPublicationMaximum(env);
1182111822 const minimum = exactReviewPublicationMinimum(env, maximum);
11823+ const base = exactReviewPublicationBase(env, maximum);
1182211824 const rawCeiling = Number(control.capacityCeiling);
1182311825 const rawDemandCapacity = Number(control.demandCapacity);
1182411826 const rawCooldown = Number(control.cooldownUntil);
1182511827 const rawRecoverySuccesses = Number(control.recoverySuccesses);
1182611828 const rawLastFailureAt = Number(control.lastFailureAt);
1182711829 const lastFailureKind = exactReviewPublicationFailureKind(control.lastFailureKind);
11830+ // A fixed higher-capacity policy persists both values above a later policy's
11831+ // maximum (for example the temporary 50/50/50 override). On downgrade, the
11832+ // ceiling may retain the new maximum, but demand must restart at the new base
11833+ // instead of turning the old fixed target into a permanent maximum target.
11834+ const fixedPolicyDowngrade =
11835+ Number.isSafeInteger(rawCeiling) &&
11836+ Number.isSafeInteger(rawDemandCapacity) &&
11837+ rawCeiling > maximum &&
11838+ rawDemandCapacity > maximum;
1182811839 return {
1182911840 capacityCeiling: Number.isSafeInteger(rawCeiling)
1183011841 ? Math.max(minimum, Math.min(maximum, rawCeiling))
1183111842 : maximum,
11832- demandCapacity: Number.isSafeInteger(rawDemandCapacity)
11833- ? Math.max(minimum, Math.min(maximum, rawDemandCapacity))
11834- : exactReviewPublicationBase(env, maximum),
11843+ demandCapacity: fixedPolicyDowngrade
11844+ ? base
11845+ : Number.isSafeInteger(rawDemandCapacity)
11846+ ? Math.max(minimum, Math.min(maximum, rawDemandCapacity))
11847+ : base,
1183511848 cooldownUntil: Number.isSafeInteger(rawCooldown) && rawCooldown > 0 ? rawCooldown : 0,
1183611849 recoverySuccesses:
1183711850 Number.isSafeInteger(rawRecoverySuccesses) && rawRecoverySuccesses > 0
0 commit comments