Revert "fix: explain merged workspace cleanup and keep visible reviews fresh (#41200)"

This reverts commit 30fa6b4398.

(cherry picked from commit 0b93e1bde5)
This commit is contained in:
Jinjing
2026-11-13 21:09:02 -08:00
committed by Brennan Benson
parent 12a22b7507
commit 48a88010c2
17 changed files with 19 additions and 326 deletions
@@ -217,19 +217,6 @@ export function visibleCandidateAfterOutcome(
}
}
const SELECTED_VISIBLE_PRIORITY = 80
const LIST_VISIBLE_PRIORITY = 40
/** The selected workspace's follow-up wins the next list-budget slot; a deselected one rejoins list order. */
export function visibleFollowUpPriority(
candidate: GitHubPRRefreshCandidate,
priority: number
): number {
return candidate.isSelected === true
? Math.max(priority, SELECTED_VISIBLE_PRIORITY)
: Math.min(priority, LIST_VISIBLE_PRIORITY)
}
export function hasStaleHead(candidate: GitHubPRRefreshCandidate): boolean {
return (
candidate.currentHeadOid != null &&
@@ -7,13 +7,6 @@ const BACKGROUND_BUDGET_MAX = 20
const ACTIVE_BURST_WINDOW_MS = 30_000
const ACTIVE_BURST_MAX = 3
export function isSelectedBudgetedPRRefresh(entry: PRRefreshQueueEntry): boolean {
return (
entry.candidate.isSelected === true &&
(entry.reason === 'visible' || (entry.reason === 'swr' && entry.hosted !== undefined))
)
}
export function usesActiveRefreshPacing(entry: PRRefreshQueueEntry): boolean {
// Selected admission survives deselection while queued; periodic follow-ups clear the flag.
return (
@@ -26,7 +19,6 @@ export class PRRefreshPacing {
private readonly backgroundStarts: number[] = []
private readonly activeStartsByScope = new Map<string, number[]>()
private lastBackgroundStartAt = 0
private lastBudgetedStartWasSelected = false
clearActiveBurstWindow(windowId: number): void {
const windowPrefix = `${windowId}::`
@@ -37,8 +29,7 @@ export class PRRefreshPacing {
}
}
noteBackgroundStart(entry: PRRefreshQueueEntry): void {
this.lastBudgetedStartWasSelected = isSelectedBudgetedPRRefresh(entry)
noteBackgroundStart(): void {
const now = Date.now()
this.lastBackgroundStartAt = now
this.backgroundStarts.push(now)
@@ -59,11 +50,7 @@ export class PRRefreshPacing {
return Math.max(spacingDelay, windowDelay)
}
order(a: PRRefreshQueueEntry, b: PRRefreshQueueEntry): number {
const priority = this.priority(b) - this.priority(a)
if (priority !== 0) {
return priority
}
activeOrder(a: PRRefreshQueueEntry, b: PRRefreshQueueEntry): number {
if (!usesActiveRefreshPacing(a) || !usesActiveRefreshPacing(b)) {
return 0
}
@@ -73,15 +60,6 @@ export class PRRefreshPacing {
return b.queuedAt - a.queuedAt
}
private priority(entry: PRRefreshQueueEntry): number {
// Reserve the next budgeted slot for other ready reviews after a selected list read.
return this.lastBudgetedStartWasSelected &&
isSelectedBudgetedPRRefresh(entry) &&
entry.bypassBackgroundBudget !== true
? 0
: entry.priority
}
entryDelay(entry: PRRefreshQueueEntry): number {
const activeDelay = usesActiveRefreshPacing(entry) ? this.nextActiveBurstDelay(entry) : 0
if (activeDelay > 0) {
@@ -196,7 +196,7 @@ export class PRRefreshQueueDrainer {
next.bypassBackgroundBudget !== true &&
isBudgetedBackground(next.reason)
) {
this.pacing.noteBackgroundStart(next)
this.pacing.noteBackgroundStart()
this.watchJobs.noteBudgetedStart(next)
}
if (next.watch && usesActiveRefreshPacing(next)) {
@@ -9,8 +9,7 @@ import {
isBudgetedBackground,
isMergeabilityPendingOutcome,
sameAliasRequestIdentity,
visibleCandidateAfterOutcome,
visibleFollowUpPriority
visibleCandidateAfterOutcome
} from './pr-refresh-candidate-policy'
import type {
PreparedPRBranchRead,
@@ -110,7 +109,7 @@ export class PRRefreshQueueScheduler {
candidate: current,
aliases: new Map(aliases.map((alias) => [alias.cacheKey, alias])),
reason: 'visible',
priority: visibleFollowUpPriority(current, priority),
priority,
dueAt,
queuedAt: this.queue.nextOrder(),
followUp: !foreground,
@@ -250,7 +249,7 @@ export class PRRefreshQueueScheduler {
candidate: followUpCandidate,
aliases: new Map(aliases.map((alias) => [alias.cacheKey, alias])),
reason: 'visible',
priority: visibleFollowUpPriority(followUpCandidate, priority),
priority,
dueAt,
queuedAt: this.queue.nextOrder(),
bypassBackgroundBudget: pendingDueAt !== null,
@@ -262,7 +261,7 @@ export class PRRefreshQueueScheduler {
ordered(): PRRefreshQueueEntry[] {
this.watchJobs.age(this.queue.values(), Date.now())
return this.queue.ordered((a, b) => this.pacing.order(a, b))
return this.queue.ordered((a, b) => this.pacing.activeOrder(a, b))
}
nextQueuedWakeDelay(excludedKey: string): number | null {
@@ -13,8 +13,7 @@ import {
POST_PUSH_DELAY_MS,
refreshKey,
sameAliasRequestIdentity,
shouldSkipFresh,
visibleFollowUpPriority
shouldSkipFresh
} from './pr-refresh-candidate-policy'
export type PRRefreshQueueEntry = {
@@ -123,7 +122,6 @@ export class PRRefreshQueue {
continue
}
entry.candidate = candidateFor(entry.key, entry.candidate)
entry.priority = visibleFollowUpPriority(entry.candidate, entry.priority)
entry.dueAt = Math.max(
freshRetryAt(entry.candidate) ?? Date.now(),
this.backgroundNotBefore.get(entry.key)?.until ?? 0
@@ -277,14 +275,14 @@ export class PRRefreshQueue {
}
ordered(
pacingOrder: (a: PRRefreshQueueEntry, b: PRRefreshQueueEntry) => number
activeOrder: (a: PRRefreshQueueEntry, b: PRRefreshQueueEntry) => number
): PRRefreshQueueEntry[] {
const now = Date.now()
return Array.from(this.entries.values()).sort((a, b) => {
const aReady = a.dueAt <= now
const bReady = b.dueAt <= now
if (aReady && bReady) {
return pacingOrder(a, b) || b.priority - a.priority || a.dueAt - b.dueAt
return b.priority - a.priority || activeOrder(a, b) || a.dueAt - b.dueAt
}
if (aReady !== bReady) {
return aReady ? -1 : 1
@@ -53,7 +53,7 @@ export function admitPreparedPRRead(
}
if (!next.watch && isBackground(next.reason) && !joinedRead) {
if (next.bypassBackgroundBudget !== true && isBudgetedBackground(next.reason)) {
pacing.noteBackgroundStart(next)
pacing.noteBackgroundStart()
watchJobs.noteBudgetedStart(next)
}
if (usesActiveRefreshPacing(next)) {
@@ -6,7 +6,6 @@ import { prChecksDone } from '../../../../shared/github/pull-requests/refresh/pr
export { prChecksDone } from '../../../../shared/github/pull-requests/refresh/pr-quiet-refresh'
import { reviewRefreshIntervalMs } from '../../../../shared/review-refresh-policy'
import type { PRRefreshQueue, PRRefreshQueueEntry } from './pr-refresh-queue'
import { isSelectedBudgetedPRRefresh } from './pr-refresh-pacing'
import type { PRRefreshRetryState } from './pr-refresh-retry-state'
export type PRWatchJob = NonNullable<PRRefreshQueueEntry['watch']>
@@ -97,10 +96,7 @@ export class PRWatchJobRunner {
}
noteBudgetedStart(entry: PRRefreshQueueEntry): void {
// Selected list reads have their own reserved turn; preserve the watch/list alternation.
if (!isSelectedBudgetedPRRefresh(entry)) {
this.lastBudgetedStartWasWatch = entry.watch !== undefined
}
this.lastBudgetedStartWasWatch = entry.watch !== undefined
}
/** Re-ranks watch entries before each pick, so aging needs no change to the queue's order. */