Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/loopover-miner/lib/pr-outcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ export function readPrOutcomes(eventLedger, filter = {}) {
if (typeof event.repoFullName !== "string" || !event.repoFullName.trim()) continue;
const normalized = normalizePrOutcomePayload(event.payload);
if (!normalized) continue;
latest.set(`${event.repoFullName}:${normalized.prNumber}`, { ...normalized, repoFullName: event.repoFullName });
// Re-key on every event so Map iteration order tracks most-recently-UPDATED last, not first-seen (#7222). A
// bare Map.set() on an existing key updates the value but leaves the key frozen at its original position, so a
// later outcome for the same PR (e.g. closed-without-merge, then reopened + merged) stayed at its old slot --
// breaking recency-ordered consumers like loop-reentry.js's countConsecutiveDisengagements. Deleting first
// moves the freshly-updated entry to the end, matching this reducer's own "a later event supersedes" contract.
const key = `${event.repoFullName}:${normalized.prNumber}`;
latest.delete(key);
latest.set(key, { ...normalized, repoFullName: event.repoFullName });
}
return latest;
}
12 changes: 12 additions & 0 deletions test/unit/miner-loop-reentry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ describe("attemptLoopReentry (#2338)", () => {
expect(countConsecutiveDisengagements(eventLedger, "acme/widgets")).toBe(0);
});

it("orders by true event recency: a later merged outcome for an EARLIER PR number resets the streak (#7222)", () => {
const eventLedger = tempEventLedger();
// PR 1 closed, PR 2 closed, then PR 1 is reopened and MERGED — a second, later outcome for the same PR number.
recordPrOutcomeSnapshot({ repoFullName: "acme/widgets", prNumber: 1, decision: "closed", closedAt: new Date().toISOString(), reason: "stale" }, { eventLedger });
recordPrOutcomeSnapshot({ repoFullName: "acme/widgets", prNumber: 2, decision: "closed", closedAt: new Date().toISOString(), reason: "stale" }, { eventLedger });
recordPrOutcomeSnapshot({ repoFullName: "acme/widgets", prNumber: 1, decision: "merged", closedAt: new Date().toISOString() }, { eventLedger });

// The most recent event is PR 1's merge, so the consecutive-disengagement streak is 0. Before #7222, the
// superseded PR 1 stayed frozen at its first-seen Map slot, so the backward walk mis-counted it as 1.
expect(countConsecutiveDisengagements(eventLedger, "acme/widgets")).toBe(0);
});

it("the hourly rate cap suppresses re-entry independent of the per-repo circuit breaker, and does not move the run-state or dequeue", () => {
const eventLedger = tempEventLedger();
const portfolioQueue = tempPortfolioQueue();
Expand Down