Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix: threads with open PRs no longer auto-settle (#5151)

Theo Browne491219bf1f4d
diff --git a/packages/client-runtime/src/state/threadSettled.test.ts b/packages/client-runtime/src/state/threadSettled.test.ts
index 99d906c00..a7dd4b1ea 100644
--- a/packages/client-runtime/src/state/threadSettled.test.ts
+++ b/packages/client-runtime/src/state/threadSettled.test.ts
@@ -115,13 +115,15 @@ describe("effectiveSettled", () => {
// Settled iff nothing blocks (pending work / live session) AND
// the override says settled, or (with no override) a merged PR
// or staleness auto-settles. The "active" pin suppresses both
- // auto signals.
+ // auto signals, and an open PR suppresses the inactivity path:
+ // a thread with a PR out for review is never done, however quiet.
expected:
pending === undefined &&
!running &&
(settledOverride === "settled" ||
(settledOverride === null &&
- (changeRequestState === "merged" || inactivity === "stale"))),
+ (changeRequestState === "merged" ||
+ (changeRequestState !== "open" && inactivity === "stale")))),
})),
),
),
@@ -176,6 +178,26 @@ describe("effectiveSettled", () => {
}
});
+ it("never auto-settles a stale thread with an open change request", () => {
+ const stale = makeShell({ activityAt: STALE });
+ expect(
+ effectiveSettled(stale, {
+ now: NOW,
+ autoSettleAfterDays: 3,
+ changeRequestState: "open",
+ }),
+ ).toBe(false);
+ // An explicit user settle still wins: open PR only blocks the auto path.
+ const settled = makeShell({ settledOverride: "settled", activityAt: STALE });
+ expect(
+ effectiveSettled(settled, {
+ now: NOW,
+ autoSettleAfterDays: 3,
+ changeRequestState: "open",
+ }),
+ ).toBe(true);
+ });
+
it("keeps an explicitly un-settled merged-PR thread active", () => {
const shell = makeShell({
settledOverride: "active",
diff --git a/packages/client-runtime/src/state/threadSettled.ts b/packages/client-runtime/src/state/threadSettled.ts
index 51a823396..595b1303b 100644
--- a/packages/client-runtime/src/state/threadSettled.ts
+++ b/packages/client-runtime/src/state/threadSettled.ts
@@ -222,7 +222,8 @@ export function threadWokeAt(
* 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 immediately or on inactivity past the window. The server
+ * merged/closed PR immediately or on inactivity past the window — except
+ * that an open PR blocks the inactivity path entirely. The server
* un-settles on real activity (user message, session start, approval/
* user-input request), so an override never goes stale silently.
*/
@@ -260,6 +261,11 @@ export function effectiveSettled(
if (options.changeRequestState === "merged" || options.changeRequestState === "closed") {
return true;
}
+ // An open PR is unfinished business regardless of how long the thread has
+ // been quiet: review can take days, and hiding the thread would bury the
+ // work waiting on it. Only merge/close (above) or an explicit user settle
+ // resolves it.
+ if (options.changeRequestState === "open") return false;
if (options.autoSettleAfterDays === null) return false;
const lastActivityAt = threadLastActivityAt(shell);