Skip to content

Commit 6f9e629

Browse files
maria-rcksclaude
andcommitted
fix(web): let a stalled title regeneration be retried
A pending thread.titleRegeneration is only ever cleared by the server's completion event, so when that completion is lost the sidebar row stays dimmed and "Regenerate title" reads "Regenerating…" and stays disabled forever. Bound the pending state to a 5 minute grace window (providers cap their own text generation at 180s) so the action becomes clickable again and the retry can clear the flag. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent b7b3ef1 commit 6f9e629

4 files changed

Lines changed: 74 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { CSS } from "@dnd-kit/utilities";
2121
import {
2222
canSnooze,
2323
effectiveSnoozed,
24+
isTitleRegenerationPending,
2425
threadWokeAt,
2526
} from "@t3tools/client-runtime/state/thread-settled";
2627
import { resolveSettledThreadTimestamp } from "@t3tools/client-runtime/state/thread-sort";
@@ -1035,7 +1036,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
10351036
);
10361037
const threadKey = scopedThreadKey(threadRef);
10371038
const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(props.isActive);
1038-
const isRegeneratingTitle = thread.titleRegeneration != null;
1039+
const isRegeneratingTitle = isTitleRegenerationPending(thread, {
1040+
now: new Date().toISOString(),
1041+
});
10391042
const lastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);
10401043
const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey));
10411044
const openPrLink = useOpenPrLink();
@@ -3750,7 +3753,7 @@ export default function Sidebar() {
37503753
.threadTitleRegeneration === true,
37513754
);
37523755
const regeneratableTitleThreads = titleRegenerationThreads.filter(
3753-
(thread) => thread.titleRegeneration == null,
3756+
(thread) => !isTitleRegenerationPending(thread, { now: selectionNow.toISOString() }),
37543757
);
37553758
const titleRegenerationMenuItem = buildBulkTitleRegenerationContextMenuItem({
37563759
supportedCount: titleRegenerationThreads.length,
@@ -3993,7 +3996,9 @@ export default function Sidebar() {
39933996
const supportsTitleRegeneration =
39943997
serverConfigs.get(thread.environmentId)?.environment.capabilities
39953998
.threadTitleRegeneration === true;
3996-
const isRegeneratingTitle = thread.titleRegeneration != null;
3999+
const isRegeneratingTitle = isTitleRegenerationPending(thread, {
4000+
now: new Date().toISOString(),
4001+
});
39974002
const isSettled = settledThreadKeysRef.current.has(threadKey);
39984003
const isSnoozed = snoozedThreadKeysRef.current.has(threadKey);
39994004
const isPinned = thread.pinnedAt != null;

‎apps/web/src/hooks/useThreadActionMenu.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
settlePromise,
66
squashAtomCommandFailure,
77
} from "@t3tools/client-runtime/state/runtime";
8-
import { canSnooze, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
8+
import {
9+
canSnooze,
10+
effectiveSnoozed,
11+
isTitleRegenerationPending,
12+
} from "@t3tools/client-runtime/state/thread-settled";
913
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
1014
import { useRouter } from "@tanstack/react-router";
1115
import { useCallback, useMemo } from "react";
@@ -135,7 +139,9 @@ export function useThreadActionMenu(input: {
135139
pinning: readEnvironmentSupportsPinning(threadRef.environmentId),
136140
titleRegeneration: readEnvironmentSupportsTitleRegeneration(threadRef.environmentId),
137141
};
138-
const isRegeneratingTitle = thread.titleRegeneration != null;
142+
const isRegeneratingTitle = isTitleRegenerationPending(thread, {
143+
now: now.toISOString(),
144+
});
139145
const snoozePresets = resolveSnoozePresets(now, timestampFormat);
140146
const items = buildThreadActionMenuItems({
141147
branch: thread.branch ?? null,

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,38 @@ import type { OrchestrationThreadShell } from "@t3tools/contracts";
99
* such threads would be permanently unsettleable.
1010
*/
1111
export const QUEUED_TURN_START_GRACE_MS = 2 * 60 * 1_000;
12+
13+
/**
14+
* A title regeneration request lives for at most this long: every text
15+
* generation provider bounds its own call at 180s, so a request still
16+
* pending after this window means the server's completion was never
17+
* dispatched or never reached this client. Without the bound the pending
18+
* flag is a one-way door — the menu entry reads "Regenerating…" and stays
19+
* disabled forever, so the retry that would clear it can never be sent.
20+
*/
21+
export const TITLE_REGENERATION_GRACE_MS = 5 * 60 * 1_000;
1222
const DAY_MS = 24 * 60 * 60 * 1_000;
1323

24+
/**
25+
* Whether a title regeneration is still plausibly in flight. Server events
26+
* clear `titleRegeneration` on completion; this only decides how long the
27+
* UI keeps trusting a pending request that never completed.
28+
*/
29+
export function isTitleRegenerationPending(
30+
shell: Pick<OrchestrationThreadShell, "titleRegeneration">,
31+
options: { readonly now: string },
32+
): boolean {
33+
const startedAt = shell.titleRegeneration?.startedAt;
34+
if (startedAt == null) return false;
35+
const startedAtMs = Date.parse(startedAt);
36+
if (Number.isNaN(startedAtMs)) return false;
37+
const nowMs = Date.parse(options.now);
38+
if (Number.isNaN(nowMs)) return false;
39+
// Bounded on both sides like hasQueuedTurnStart: startedAt is stamped by
40+
// the environment's server, whose clock can run ahead of this device's.
41+
return Math.abs(nowMs - startedAtMs) <= TITLE_REGENERATION_GRACE_MS;
42+
}
43+
1444
/**
1545
* A user message no turn has picked up yet: the turn.start command was
1646
* dispatched (message-sent + turn-start-requested) but no session has

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// @effect-diagnostics globalDate:off -- Tests exercise local calendar snooze boundaries.
2-
import { ThreadId } from "@t3tools/contracts";
2+
import { CommandId, ThreadId } from "@t3tools/contracts";
33
import { TurnId } from "@t3tools/contracts";
44
import { describe, expect, it } from "vite-plus/test";
55

66
import {
77
canSnooze,
88
effectiveSnoozed,
99
hasQueuedTurnStart,
10+
isTitleRegenerationPending,
1011
resolveSnoozePresets,
1112
snoozeWakeLabel,
1213
threadRaisedHandWhileSnoozed,
@@ -371,3 +372,29 @@ describe("resolveSnoozePresets", () => {
371372
expect(tomorrow.getDay()).toBe(1);
372373
});
373374
});
375+
376+
describe("isTitleRegenerationPending", () => {
377+
const startedAt = "2026-04-10T11:58:00.000Z";
378+
379+
it("stays pending while the request is within the grace window", () => {
380+
expect(
381+
isTitleRegenerationPending(
382+
{ titleRegeneration: { requestId: CommandId.make("cmd-1"), startedAt } },
383+
{ now: NOW },
384+
),
385+
).toBe(true);
386+
});
387+
388+
it("stops pending once the request outlives the grace window, so it can be retried", () => {
389+
expect(
390+
isTitleRegenerationPending(
391+
{ titleRegeneration: { requestId: CommandId.make("cmd-1"), startedAt } },
392+
{ now: "2026-04-10T12:10:00.000Z" },
393+
),
394+
).toBe(false);
395+
});
396+
397+
it("is never pending without a request", () => {
398+
expect(isTitleRegenerationPending({ titleRegeneration: null }, { now: NOW })).toBe(false);
399+
});
400+
});

0 commit comments

Comments
 (0)