Skip to content

Commit 65c2e53

Browse files
committed
fix(web): keep wake state when merge settling is off
1 parent 57ffa7e commit 65c2e53

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
type EnvironmentConnectionPresentation,
2828
} from "@t3tools/client-runtime/connection";
2929
import {
30+
changeRequestAutoSettles,
3031
effectiveSettled,
3132
effectiveSnoozed,
3233
threadWokeAt,
@@ -4059,15 +4060,14 @@ function ChatViewContent(props: ChatViewProps) {
40594060
if (activeThreadRef === null || activeThreadWokeAt === null) return;
40604061
markThreadVisited(scopedThreadKey(activeThreadRef), activeThreadWokeAt);
40614062
}, [activeThreadRef, activeThreadWokeAt, markThreadVisited]);
4062-
// Mirror of the sidebar's Woke pill for the open thread: same visit
4063-
// comparison, same merged/closed-PR suppression (finished work needs no
4064-
// wake-up call). Drives the dismissible composer banner below.
4063+
// Mirror of the sidebar's Woke pill for the open thread. It uses the same
4064+
// visit comparison and change request settle rule.
40654065
const activeThreadLastVisitedAt = useUiStateStore((store) =>
40664066
activeThreadKey === null ? undefined : store.threadLastVisitedAtById[activeThreadKey],
40674067
);
40684068
const activeThreadWokeVisible = useMemo(() => {
40694069
if (activeThreadWokeAt === null) return false;
4070-
if (activeThreadPr?.state === "merged" || activeThreadPr?.state === "closed") return false;
4070+
if (changeRequestAutoSettles(activeThreadPr?.state, autoSettleOnMerge)) return false;
40714071
const wokeAtMs = Date.parse(activeThreadWokeAt);
40724072
if (Number.isNaN(wokeAtMs)) return false;
40734073
// Having the thread open counts as a visit at completedAt (the effect
@@ -4089,6 +4089,7 @@ function ChatViewContent(props: ChatViewProps) {
40894089
activeThreadLastVisitedAt,
40904090
activeThreadPr?.state,
40914091
activeThreadWokeAt,
4092+
autoSettleOnMerge,
40924093
]);
40934094
const activeThreadSettled = useMemo(() => {
40944095
if (activeThreadShell === null || !supportsSettlement) return false;

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { restrictToFirstScrollableAncestor, restrictToVerticalAxis } from "@dnd-
1818
import { CSS } from "@dnd-kit/utilities";
1919
import {
2020
canSnooze,
21+
changeRequestAutoSettles,
2122
effectiveSettled,
2223
effectiveSnoozed,
2324
threadWokeAt,
@@ -649,6 +650,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
649650
// False on environments whose server predates thread.settle/unsettle:
650651
// the lifecycle affordances hide entirely rather than fail on click.
651652
settlementSupported: boolean;
653+
autoSettleOnMerge: boolean;
652654
// Same contract for thread.snooze/unsnooze.
653655
snoozeSupported: boolean;
654656
// Renders the pin glyph. Pinned cards keep the full settle/snooze quick
@@ -755,17 +757,15 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
755757
// deliberately static), so the pill has to carry the weight. Snoozing is
756758
// an explicit act, so the pill clears only when the user re-engages:
757759
// reading a completion-triggered wake, clicking the pill, sending a
758-
// message, settling, archiving — or finishing the work outright (merged
759-
// or closed PR). Timer wakes survive a mere visit. An unparseable visit
760-
// timestamp counts as never-visited — corrupt local data must not eat
761-
// the wake signal.
760+
// message, settling, archiving, or a change request state that settles the
761+
// thread. Timer wakes survive a mere visit. An unparseable visit timestamp
762+
// counts as never-visited, so corrupt local data cannot eat the wake signal.
762763
const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);
763764
const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);
764765
const isWoke =
765766
wokeAtDate !== null &&
766767
(lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&
767-
prState !== "merged" &&
768-
prState !== "closed";
768+
!changeRequestAutoSettles(prState, props.autoSettleOnMerge);
769769
// In-flight rows (working, or waiting on approval/input) fade as a whole:
770770
// there is nothing for the user to do yet, so prominence is reserved for
771771
// rows that need a human — done (unread), read-but-unsettled, failed, and
@@ -3448,6 +3448,7 @@ export default function Sidebar() {
34483448
serverConfigs.get(thread.environmentId)?.environment.capabilities
34493449
.threadSettlement === true
34503450
}
3451+
autoSettleOnMerge={autoSettleOnMerge}
34513452
snoozeSupported={
34523453
serverConfigs.get(thread.environmentId)?.environment.capabilities
34533454
.threadSnooze === true

‎packages/client-runtime/src/state/threadSettled.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { describe, expect, it } from "vite-plus/test";
99

1010
import {
1111
canSettle,
12+
changeRequestAutoSettles,
1213
effectiveSettled,
1314
hasQueuedTurnStart,
1415
threadLastActivityAt,
@@ -19,6 +20,18 @@ const NOW = "2026-04-10T00:00:00.000Z";
1920
const FRESH = "2026-04-09T00:00:00.000Z";
2021
const STALE = "2026-04-06T23:59:59.999Z";
2122

23+
describe("changeRequestAutoSettles", () => {
24+
it.each([
25+
["open", true, false],
26+
["merged", true, true],
27+
["merged", false, false],
28+
["closed", false, true],
29+
[null, false, false],
30+
] as const)("state=%s autoSettleOnMerge=%s returns %s", (state, autoSettleOnMerge, expected) => {
31+
expect(changeRequestAutoSettles(state, autoSettleOnMerge)).toBe(expected);
32+
});
33+
});
34+
2235
function makeShell(input: {
2336
readonly settledOverride?: "settled" | "active" | null;
2437
readonly activityAt: string | null;

‎packages/client-runtime/src/state/threadSettled.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import type { OrchestrationThreadShell } from "@t3tools/contracts";
33

44
export type ChangeRequestStateLike = "open" | "closed" | "merged";
55

6+
/** Returns whether the change request state settles the thread immediately. */
7+
export function changeRequestAutoSettles(
8+
state: ChangeRequestStateLike | null | undefined,
9+
autoSettleOnMerge = true,
10+
): boolean {
11+
return state === "closed" || (state === "merged" && autoSettleOnMerge);
12+
}
13+
614
const DAY_MS = 24 * 60 * 60 * 1_000;
715

816
export function threadLastActivityAt(shell: OrchestrationThreadShell): string | null {
@@ -259,8 +267,9 @@ export function effectiveSettled(
259267
// "active" is the explicit keep-active pin: it suppresses auto-settle
260268
// until real activity clears it server-side.
261269
if (shell.settledOverride === "active") return false;
262-
if (options.changeRequestState === "closed") return true;
263-
if (options.changeRequestState === "merged" && options.autoSettleOnMerge !== false) return true;
270+
if (changeRequestAutoSettles(options.changeRequestState, options.autoSettleOnMerge !== false)) {
271+
return true;
272+
}
264273
// An open PR is unfinished business regardless of how long the thread has
265274
// been quiet: review can take days, and hiding the thread would bury the
266275
// work waiting on it. A configured merge, a close, or an explicit user

0 commit comments

Comments
 (0)