@@ -3847,6 +3847,7 @@ export class ExactReviewQueue {
38473847 new Set(snapshotBatchOwnership.itemKeys),
38483848 snapshotBatchOwnership.activeBatches,
38493849 this.freshPublicationItemKeysSync(snapshot, startedAt),
3850+ this.supersededPublicationItemKeysSync(snapshot),
38503851 );
38513852 let snapshotBatchCandidates = snapshotBatchDeparture?.due
38523853 ? this.publicationBatchCandidates(
@@ -3912,6 +3913,7 @@ export class ExactReviewQueue {
39123913 new Set(snapshotBatchOwnership.itemKeys),
39133914 snapshotBatchOwnership.activeBatches,
39143915 this.freshPublicationItemKeysSync(snapshot, recheckedAt),
3916+ this.supersededPublicationItemKeysSync(snapshot),
39153917 );
39163918 snapshotBatchCandidates = snapshotBatchDeparture?.due
39173919 ? this.publicationBatchCandidates(
@@ -5929,7 +5931,10 @@ export class ExactReviewQueue {
59295931 // shared helper counts candidate rows, so widen only its scan window by
59305932 // requestedSize; passing +1 here would silently collapse every batch to one.
59315933 const activePublishers = exactReviewQueueActivePublicationCount(state);
5932- const excludedItemKeys = new Set<string>(batchOwnership.itemKeys);
5934+ const excludedItemKeys = new Set<string>([
5935+ ...batchOwnership.itemKeys,
5936+ ...this.supersededPublicationItemKeysSync(state),
5937+ ]);
59335938 for (const item of Object.values(state.items)) {
59345939 // Direct receipts and terminal acknowledgement drivers must remain on
59355940 // the normal publisher. Exclude them before admission so they cannot
@@ -5940,13 +5945,6 @@ export class ExactReviewQueue {
59405945 if (exactReviewGithubCircuitBlocksItem(state, item, now)) {
59415946 excludedItemKeys.add(item.key);
59425947 }
5943- const revision = exactReviewPublicationRevision(item.decision);
5944- if (
5945- revision &&
5946- revision.sourceRevision < this.publicationHeadRevisionSync(revision.targetKey)
5947- ) {
5948- excludedItemKeys.add(item.key);
5949- }
59505948 }
59515949 const freshItemKeys = this.freshPublicationItemKeysSync(state, now);
59525950 const readyCandidates =
@@ -5968,14 +5966,7 @@ export class ExactReviewQueue {
59685966 // immutable lifecycle plan must return through the fenced legacy
59695967 // publisher, which is the only path that replays that plan.
59705968 .filter(exactReviewQueueIsBatchablePublication)
5971- .filter((item) => !item.terminalFinalization)
5972- .filter((item) => {
5973- const revision = exactReviewPublicationRevision(item.decision);
5974- return (
5975- !revision ||
5976- revision.sourceRevision >= this.publicationHeadRevisionSync(revision.targetKey)
5977- );
5978- });
5969+ .filter((item) => !item.terminalFinalization);
59795970 const selection = exactReviewPublicationBatchSelection(
59805971 readyCandidates,
59815972 freshItemKeys,
@@ -7858,6 +7849,20 @@ export class ExactReviewQueue {
78587849 return Number(row?.source_revision || 0);
78597850 }
78607851
7852+ private supersededPublicationItemKeysSync(state: ExactReviewQueueState) {
7853+ // Active batch ownership can preserve an older row after a newer head lands.
7854+ // Departure and claim must exclude that same row when ownership expires.
7855+ return new Set(
7856+ Object.values(state.items).flatMap((item) => {
7857+ const revision = exactReviewPublicationRevision(item.decision);
7858+ return revision &&
7859+ revision.sourceRevision < this.publicationHeadRevisionSync(revision.targetKey)
7860+ ? [item.key]
7861+ : [];
7862+ }),
7863+ );
7864+ }
7865+
78617866 private nextExactReviewItemRevisionSync(itemKey: string, minimumRevision = 1): number {
78627867 return Math.max(minimumRevision, this.publicationHeadRevisionSync(itemKey.toLowerCase()) + 1);
78637868 }
@@ -10859,6 +10864,7 @@ export class ExactReviewQueue {
1085910864 new Set(batchOwnership.itemKeys),
1086010865 batchOwnership.activeBatches,
1086110866 this.freshPublicationItemKeysSync(state, now),
10867+ this.supersededPublicationItemKeysSync(state),
1086210868 );
1086310869 const sourceAuthorityNext = await this.nextSourceAuthorityVerificationAt();
1086410870 const commandIntakeNext = this.commandIntakeStore.nextAttemptAt();
@@ -12964,6 +12970,7 @@ function exactReviewPublicationBatchDeparture(
1296412970 ownedItemKeys: ReadonlySet<string>,
1296512971 activeBatchCount: number,
1296612972 freshItemKeys: ReadonlySet<string> = new Set(),
12973+ supersededItemKeys: ReadonlySet<string> = new Set(),
1296712974) {
1296812975 if (
1296912976 !exactReviewPublicationBatchingEnabled(env) ||
@@ -12979,6 +12986,7 @@ function exactReviewPublicationBatchDeparture(
1297912986 item.state === "pending" &&
1298012987 !item.terminalFinalization &&
1298112988 !ownedItemKeys.has(item.key) &&
12989+ !supersededItemKeys.has(item.key) &&
1298212990 !exactReviewGithubCircuitBlocksItem(state, item, now),
1298312991 )
1298412992 .sort((left, right) => left.createdAt - right.createdAt || left.key.localeCompare(right.key)),
0 commit comments