Skip to content

Commit 50f90ea

Browse files
authored
fix(publication): contain retries and normalize canonical slugs (#1094)
* fix: contain publication retries and canonicalize slugs * fix: normalize downgraded publication demand
1 parent 2cc2c0d commit 50f90ea

4 files changed

Lines changed: 304 additions & 17 deletions

File tree

‎dashboard/exact-review-direct-publication.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,13 +1403,14 @@ export async function validateCanonicalRecordTupleMutation(
14031403
) {
14041404
throw new Error("invalid canonical tuple delivery id");
14051405
}
1406-
const key = String(mutation.key || "").trim();
1407-
const keyMatch = /^([A-Za-z0-9][A-Za-z0-9_.-]{0,199})\/([1-9]\d*)$/.exec(key);
1408-
const repoSlug = validateRepoSlug(keyMatch?.[1]);
1406+
const inputKey = String(mutation.key || "").trim();
1407+
const keyMatch = /^([A-Za-z0-9][A-Za-z0-9_.-]{0,199})\/([1-9]\d*)$/.exec(inputKey);
1408+
const repoSlug = validateRepoSlug(keyMatch?.[1])?.toLowerCase() ?? null;
14091409
const itemId = Number(keyMatch?.[2]);
14101410
if (!repoSlug || !Number.isSafeInteger(itemId) || itemId < 1) {
14111411
throw new Error("invalid canonical tuple key");
14121412
}
1413+
const key = `${repoSlug}/${itemId}`;
14131414
if (!Array.isArray(mutation.operations) || mutation.operations.length !== 4) {
14141415
throw new Error("canonical tuple publication must include all four record sections");
14151416
}
@@ -1586,7 +1587,7 @@ export async function validateDirectPublicationPlan(
15861587
if (plan.operations.length > EXACT_REVIEW_DIRECT_PUBLICATION_MAX_FILES) {
15871588
throw new Error("a direct publication plan exceeds the exact-review tuple file limit");
15881589
}
1589-
const repoSlug = `${itemIdentity[1]}-${itemIdentity[2]}`;
1590+
const repoSlug = `${itemIdentity[1]}-${itemIdentity[2]}`.toLowerCase();
15901591
const itemId = Number(itemIdentity[3]);
15911592
const paths = new Set<string>();
15921593
let totalBytes = 0;

‎dashboard/exact-review-queue.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎dashboard/wrangler.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ CACHE_TTL_SECONDS = "20"
5555
INCLUDE_CI_STATUS = "1"
5656
EXACT_REVIEW_QUEUE_MAX_CONCURRENT = "128"
5757
EXACT_REVIEW_TARGET_MAX_CONCURRENT = "120"
58-
EXACT_REVIEW_PUBLICATION_MIN_CONCURRENT = "50"
59-
EXACT_REVIEW_PUBLICATION_BASE_CONCURRENT = "50"
60-
EXACT_REVIEW_PUBLICATION_MAX_CONCURRENT = "50"
58+
EXACT_REVIEW_PUBLICATION_MIN_CONCURRENT = "8"
59+
EXACT_REVIEW_PUBLICATION_BASE_CONCURRENT = "32"
60+
EXACT_REVIEW_PUBLICATION_MAX_CONCURRENT = "40"
6161
EXACT_REVIEW_DISPATCH_LEASE_MS = "360000"
6262
EXACT_REVIEW_EXECUTION_LEASE_MS = "7800000"
6363
EXACT_REVIEW_HEARTBEAT_GRACE_MS = "1200000"

0 commit comments

Comments
 (0)