Settle merged PR threads immediately (#4704)
This commit is contained in:
1 parent
e00781a661
commit
9cf9fc9c5c
2 files changed
+17
-57
No files matched your search
@@ -163,32 +163,11 @@ describe("effectiveSettled", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not re-settle a warm thread on the merge signal: a message sent in a settled thread keeps it active until idle", () => {
|
||||
// The merge signal never clears, so without the idle guard a follow-up
|
||||
// message would un-settle the row only until its turn completed, then
|
||||
// snap straight back into the settled tail.
|
||||
const justActive = makeShell({ activityAt: "2026-04-09T23:30:00.000Z" });
|
||||
// The idle gate is strict: activity exactly one hour old is still warm.
|
||||
const boundary = makeShell({ activityAt: "2026-04-09T23:00:00.000Z" });
|
||||
const idle = makeShell({ activityAt: "2026-04-09T22:59:59.999Z" });
|
||||
|
||||
it("settles immediately when a change request merges or closes", () => {
|
||||
const recentlyActive = makeShell({ activityAt: "2026-04-09T23:59:59.999Z" });
|
||||
for (const changeRequestState of ["merged", "closed"] as const) {
|
||||
expect(
|
||||
effectiveSettled(justActive, {
|
||||
now: NOW,
|
||||
autoSettleAfterDays: null,
|
||||
changeRequestState,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
effectiveSettled(boundary, {
|
||||
now: NOW,
|
||||
autoSettleAfterDays: null,
|
||||
changeRequestState,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
effectiveSettled(idle, {
|
||||
effectiveSettled(recentlyActive, {
|
||||
now: NOW,
|
||||
autoSettleAfterDays: null,
|
||||
changeRequestState,
|
||||
@@ -197,14 +176,18 @@ describe("effectiveSettled", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("re-settles a merged-PR thread once the follow-up burst goes idle", () => {
|
||||
// Same shell, advancing clock: active while warm, settled again after
|
||||
// the idle window passes — the burst cools and the merge signal wins.
|
||||
const shell = makeShell({ activityAt: "2026-04-09T23:30:00.000Z" });
|
||||
const options = { autoSettleAfterDays: null, changeRequestState: "merged" as const };
|
||||
|
||||
expect(effectiveSettled(shell, { ...options, now: NOW })).toBe(false);
|
||||
expect(effectiveSettled(shell, { ...options, now: "2026-04-10T00:30:00.001Z" })).toBe(true);
|
||||
it("keeps an explicitly un-settled merged-PR thread active", () => {
|
||||
const shell = makeShell({
|
||||
settledOverride: "active",
|
||||
activityAt: "2026-04-09T23:59:59.999Z",
|
||||
});
|
||||
expect(
|
||||
effectiveSettled(shell, {
|
||||
now: NOW,
|
||||
autoSettleAfterDays: null,
|
||||
changeRequestState: "merged",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("never settles a starting session, even with a settled override", () => {
|
||||
|
||||
@@ -214,20 +214,6 @@ export function threadWokeAt(
|
||||
return wakeAtMs <= Date.parse(options.now) ? shell.snoozedUntil : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A merged/closed change request settles its thread only once the thread has
|
||||
* been idle this long. Without the idle guard the merge signal is permanent:
|
||||
* sending a message to a merged-PR thread would un-settle the row only until
|
||||
* its turn completed, then the still-merged PR would snap it straight back
|
||||
* into the settled tail. An hour keeps the follow-up conversation visible
|
||||
* while it is warm; once the burst goes stale the merge signal settles it
|
||||
* again. Activity timestamps can originate on another device while `now` is
|
||||
* this caller's clock: skew shortens or stretches the window by its size,
|
||||
* the same exposure the inactivity auto-settle already accepts — worst case
|
||||
* is a row changing lists early or late, never lost work.
|
||||
*/
|
||||
export const CHANGE_REQUEST_SETTLE_IDLE_MS = 60 * 60 * 1_000;
|
||||
|
||||
/**
|
||||
* Settled resolution over the server-backed settled lifecycle. Activity
|
||||
* blockers (pending approval/user-input, a live session, an unadjudicated
|
||||
@@ -235,7 +221,7 @@ export const CHANGE_REQUEST_SETTLE_IDLE_MS = 60 * 60 * 1_000;
|
||||
* override. Past the blockers, the explicit user override (thread.settle /
|
||||
* thread.unsettle commands, projected into settledOverride + settledAt)
|
||||
* wins in both directions; without one, a thread auto-settles on a
|
||||
* merged/closed PR (once idle) or inactivity past the window. The server
|
||||
* merged/closed PR immediately or on inactivity past the window. The server
|
||||
* un-settles on real activity (user message, session start, approval/
|
||||
* user-input request), so an override never goes stale silently.
|
||||
*/
|
||||
@@ -271,16 +257,7 @@ export function effectiveSettled(
|
||||
// until real activity clears it server-side.
|
||||
if (shell.settledOverride === "active") return false;
|
||||
if (options.changeRequestState === "merged" || options.changeRequestState === "closed") {
|
||||
// Only an idle thread settles on the merge signal: the signal itself
|
||||
// never clears, so without this guard fresh activity (a message sent in
|
||||
// a settled thread) would re-settle the moment its turn completed.
|
||||
const lastActivityAt = threadLastActivityAt(shell);
|
||||
if (
|
||||
lastActivityAt === null ||
|
||||
Date.parse(lastActivityAt) < Date.parse(options.now) - CHANGE_REQUEST_SETTLE_IDLE_MS
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (options.autoSettleAfterDays === null) return false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user