The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(chat): show one usage-limit recovery notice (#29292)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Nov 6, 2026 at 06:38 UTC
c7537d026492d42c2fb9fd400577f88767e8d774
10 files changed
+322
-100
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+21
-6
@@ -62,6 +62,7 @@ import {
62
BACKGROUND_WORK_STOP_RETRY_AFTER_MS,
63
type BackgroundWorkStopRequest,
64
isBackgroundWorkStopPending,
65
+ limitRecoveryOwnsSnooze,
66
presentPendingBackgroundWork,
67
presentProviderGoal,
68
} from "@t3tools/client-runtime/state/thread-execution";
@@ -642,6 +643,19 @@ function ThreadDetailBody(
643
return () => clearTimeout(timer);
644
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Re-arm if timer clamping fires before the wake time.
645
}, [snoozed, snoozedUntil, lifecycleNow]);
646
+ // The usage-limit recovery card shows this snooze and its Wake now.
647
+ const lifecycleSnoozed =
648
+ snoozed &&
649
+ !limitRecoveryOwnsSnooze({
650
+ runId:
651
+ props.selectedThread.runtime?.status === "failed" &&
652
+ props.selectedThread.runtime.lastErrorClass === "usage_limit"
653
+ ? props.selectedThread.latestRun?.runId
654
+ : null,
655
+ resetAt: props.selectedThread.runtime?.usageLimitResetAt,
656
+ recovery: props.selectedThread.limitRecovery,
657
+ snoozedUntil,
658
+ });
659
const settled = configLoaded && props.selectedThread.settledOverride === "settled";
660
const wokeAt = configLoaded ? threadWokeAt(props.selectedThread, { now: lifecycleNow }) : null;
661
const woke = isThreadWokeUnseen({
@@ -809,22 +823,22 @@ function ThreadDetailBody(
823
},
824
};
825
}
812
- if (contentPresentationKind === "ready" && (snoozed || settled || woke)) {
813
- const state = snoozed ? "snoozed" : settled ? "settled" : "woke";
826
+ if (contentPresentationKind === "ready" && (lifecycleSnoozed || settled || woke)) {
827
+ const state = lifecycleSnoozed ? "snoozed" : settled ? "settled" : "woke";
828
const label =
815
- snoozed && snoozedUntil !== null
829
+ lifecycleSnoozed && snoozedUntil !== null
830
? `Snoozed, wakes in ${snoozeWakeLabel(snoozedUntil, { now: lifecycleNow })}`
831
: settled
832
? "Settled"
833
: "Woke from snooze";
820
- const actionLabel = snoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
834
+ const actionLabel = lifecycleSnoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
835
return {
836
kind: "lifecycle",
837
state,
838
label,
839
action: {
840
label: statusPending
827
- ? snoozed
841
+ ? lifecycleSnoozed
842
? "Waking..."
843
: settled
844
? "Un-settling..."
@@ -832,7 +846,8 @@ function ThreadDetailBody(
846
: actionLabel,
847
accessibilityLabel: actionLabel,
848
disabled: !props.canOperateThread || statusPending,
835
- onPress: () => void runStatusAction(snoozed ? "wake" : settled ? "unsettle" : "dismiss"),
849
+ onPress: () =>
850
+ void runStatusAction(lifecycleSnoozed ? "wake" : settled ? "unsettle" : "dismiss"),
851
},
852
};
853
}
apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx
+93
-52
@@ -1,7 +1,7 @@
1
-import { Button } from "../../components/ui/Button";
1
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
2
import { AsyncResult } from "effect/reactivity";
3
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
4
+import { limitRecoveryOwnsSnooze } from "@t3tools/client-runtime/state/thread-execution";
5
import type { EnvironmentId } from "@t3tools/contracts";
6
import {
7
CHATGPT_USAGE_LIMIT_CODE,
@@ -9,7 +9,6 @@ import {
9
CHATGPT_WORKSPACE_ADMIN_REQUEST,
10
CHATGPT_WORKSPACE_USAGE_LIMIT_CODE,
11
} from "@t3tools/shared/usageLimits";
12
-import * as DateTime from "effect/DateTime";
12
import * as Clipboard from "expo-clipboard";
13
import { useState } from "react";
14
import { Linking, Pressable, View } from "react-native";
@@ -31,6 +30,7 @@ export function UsageLimitRecoveryCard({
30
const [error, setError] = useState<string | null>(null);
31
const resetAt = thread.runtime?.usageLimitResetAt ?? null;
32
const canSchedule =
33
+ thread.settledOverride !== "settled" &&
34
resetAt !== null &&
35
Date.parse(resetAt) > Date.parse(thread.latestRun?.completedAt ?? thread.updatedAt);
36
const resetPassed = useDeadlinePassed(resetAt === null ? null : Date.parse(resetAt));
@@ -38,6 +38,14 @@ export function UsageLimitRecoveryCard({
38
const recovery = thread.limitRecovery;
39
const scheduled =
40
recovery?.runId === runId && recovery?.resetAt === resetAt && recovery?.autoResume;
41
+ const displayAt =
42
+ canSchedule &&
43
+ scheduled &&
44
+ resetAt &&
45
+ thread.snoozedUntil &&
46
+ Date.parse(thread.snoozedUntil) > Date.parse(resetAt)
47
+ ? thread.snoozedUntil
48
+ : resetAt;
49
const [copied, setCopied] = useState(false);
50
const [actionPending, setActionPending] = useState(false);
51
const code = thread.runtime?.lastErrorCode;
@@ -51,16 +59,19 @@ export function UsageLimitRecoveryCard({
59
!runId
60
)
61
return null;
54
- const resetText = resetAt
55
- ? `Usage limit resets ${DateTime.toDateUtc(DateTime.makeUnsafe(resetAt)).toLocaleString()}.`
62
+ const resetText = displayAt
63
+ ? `${canSchedule && scheduled ? "Resumes" : "Resets"} ${new Date(displayAt).toLocaleString(
64
+ undefined,
65
+ { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" },
66
+ )}.`
67
: null;
68
const snoozed =
58
- recovery?.snooze === true &&
59
- recovery.runId === runId &&
60
- recovery.resetAt === resetAt &&
61
- resetAt !== null &&
62
- thread.snoozedUntil !== null &&
63
- Date.parse(thread.snoozedUntil) === Date.parse(resetAt);
69
+ limitRecoveryOwnsSnooze({
70
+ runId,
71
+ resetAt,
72
+ recovery,
73
+ snoozedUntil: thread.snoozedUntil,
74
+ }) && !resetPassed;
75
async function toggle(action: "resume" | "snooze") {
76
if (!resetAt || !runId || !canSchedule) return;
77
if (action === "snooze" && !snoozed && Date.parse(resetAt) <= Date.now()) {
@@ -123,50 +134,52 @@ export function UsageLimitRecoveryCard({
134
<ProviderIcon provider="codex" size={16} />
135
</View>
136
) : null}
126
- <View className="min-w-0 flex-1 gap-2">
137
+ <View className="min-w-0 flex-1 gap-1">
138
{chatGptLimit ? (
128
- <View className="gap-1">
129
- <Text className="text-sm font-t3-medium text-foreground">
130
- ChatGPT usage limit reached
131
- </Text>
132
- <Text className="text-sm text-foreground-muted">
133
- {workspaceLimit
134
- ? copied
135
- ? "Request copied. Send it to your workspace admin."
136
- : "You've reached your workspace's limit for using your ChatGPT plan in other apps. Copy a request to ask your workspace admin for increased usage limits."
137
- : (resetText ?? "Review your usage settings in ChatGPT.")}
138
- </Text>
139
- <Pressable
140
- accessibilityRole={action.role}
141
- accessibilityState={{ disabled: actionPending }}
142
- disabled={actionPending}
143
- hitSlop={14}
144
- className="mt-1 self-start active:opacity-70"
145
- onPress={action.run}
146
- >
147
- <Text className="text-sm font-t3-medium text-primary">{action.label}</Text>
148
- </Pressable>
149
- </View>
150
- ) : (
151
- <Text className="text-sm text-warning-foreground">
152
- {resetText ??
153
- "The provider did not report a reset time. Retry manually when your limit is available."}
139
+ <Text className="text-sm font-t3-medium text-foreground">
140
+ ChatGPT usage limit reached
141
</Text>
155
- )}
156
- {canSchedule ? (
157
- <View className="flex-row flex-wrap gap-2">
158
- <Button
159
- label={scheduled ? "Cancel auto-resume" : "Resume at reset"}
160
- tone="secondary"
161
- disabled={pending}
162
- onPress={() => void toggle("resume")}
163
- />
164
- <Button
165
- label={snoozed ? "Wake now" : "Snooze until reset"}
166
- tone="secondary"
167
- disabled={pending || (!snoozed && resetPassed)}
168
- onPress={() => void toggle("snooze")}
169
- />
142
+ ) : null}
143
+ <Text
144
+ className={
145
+ chatGptLimit ? "text-sm text-foreground-muted" : "text-sm text-warning-foreground"
146
+ }
147
+ >
148
+ {workspaceLimit
149
+ ? copied
150
+ ? "Request copied. Send it to your workspace admin."
151
+ : "You've reached your workspace's limit for using your ChatGPT plan in other apps. Copy a request to ask your workspace admin for increased usage limits."
152
+ : chatGptLimit
153
+ ? (resetText ?? "Review your usage settings in ChatGPT.")
154
+ : resetText
155
+ ? `Usage limit reached. ${resetText}`
156
+ : "Usage limit reached. The provider did not report a reset time. Retry manually when your limit is available."}
157
+ </Text>
158
+ {chatGptLimit || canSchedule ? (
159
+ // The margins cancel the 44pt touch height so the links sit 8pt under the text.
160
+ <View className="-mb-3 -mt-2 flex-row flex-wrap gap-x-4">
161
+ {chatGptLimit ? (
162
+ <RecoveryAction
163
+ label={action.label}
164
+ role={action.role}
165
+ disabled={actionPending}
166
+ onPress={action.run}
167
+ />
168
+ ) : null}
169
+ {canSchedule ? (
170
+ <>
171
+ <RecoveryAction
172
+ label={scheduled ? "Cancel auto-resume" : "Resume at reset"}
173
+ disabled={pending}
174
+ onPress={() => void toggle("resume")}
175
+ />
176
+ <RecoveryAction
177
+ label={snoozed ? "Wake now" : "Snooze until reset"}
178
+ disabled={pending || (!snoozed && resetPassed)}
179
+ onPress={() => void toggle("snooze")}
180
+ />
181
+ </>
182
+ ) : null}
183
</View>
184
) : null}
185
{error ? (
@@ -178,3 +191,31 @@ export function UsageLimitRecoveryCard({
191
</View>
192
);
193
}
194
+
195
+function RecoveryAction(props: {
196
+ readonly label: string;
197
+ readonly role?: "button" | "link";
198
+ readonly disabled: boolean;
199
+ readonly onPress: () => void;
200
+}) {
201
+ return (
202
+ <Pressable
203
+ accessibilityRole={props.role ?? "button"}
204
+ accessibilityState={{ disabled: props.disabled }}
205
+ disabled={props.disabled}
206
+ hitSlop={{ left: 8, right: 8 }}
207
+ onPress={props.onPress}
208
+ className="min-h-11 justify-center active:opacity-70"
209
+ >
210
+ <Text
211
+ className={
212
+ props.disabled
213
+ ? "text-sm font-t3-medium text-foreground-muted"
214
+ : "text-sm font-t3-medium text-primary"
215
+ }
216
+ >
217
+ {props.label}
218
+ </Text>
219
+ </Pressable>
220
+ );
221
+}
apps/web/src/components/ChatView.tsx
+21
-11
@@ -82,6 +82,7 @@ import {
82
deriveThreadActivityRun,
83
deriveLatestThreadRun,
84
deriveThreadStructureRuntime,
85
+ limitRecoveryOwnsSnooze,
86
} from "@t3tools/client-runtime/state/thread-execution";
87
import {
88
resolveWorkflowOpening,
@@ -983,11 +984,19 @@ export default function ChatView(props: ChatViewProps) {
984
);
985
const browserAvailable = isPreviewSupportedInRuntime() || activeEnvironmentServerBrowser;
986
const activeThreadShell = serverThread;
987
+ const limitRecoveryRun =
988
+ serverRuntime?.status === "failed" && serverRuntime.lastErrorClass === "usage_limit"
989
+ ? (activeThreadShell?.latestRun ?? null)
990
+ : null;
991
+ // The recovery banner offers Wake now for a snooze it set.
992
+ const limitRecoveryHoldsSnooze = limitRecoveryOwnsSnooze({
993
+ runId: limitRecoveryRun?.runId,
994
+ resetAt: serverRuntime?.usageLimitResetAt,
995
+ recovery: activeThreadShell?.limitRecovery,
996
+ snoozedUntil: activeThreadShell?.snoozedUntil,
997
+ });
998
const timelineThreadError =
987
- serverRuntime?.status === "failed" &&
988
- serverRuntime.lastErrorClass === "usage_limit" &&
989
- activeThreadShell?.latestRun &&
990
- visibleThreadError === serverRuntime.lastError
999
+ limitRecoveryRun !== null && visibleThreadError === serverRuntime?.lastError
1000
? null
1001
: visibleThreadError;
1002
@@ -2414,6 +2423,7 @@ export default function ChatView(props: ChatViewProps) {
2423
activeThreadKey,
2424
activeThreadShell,
2425
activeLatestRun,
2426
+ limitRecoveryHoldsSnooze,
2427
activeProjectCwd,
2428
serverConfig,
2429
runtimeMode,
@@ -2542,14 +2552,14 @@ export default function ChatView(props: ChatViewProps) {
2552
return item ? [item] : [];
2553
});
2554
const limitRecoveryBanner =
2545
- serverRuntime?.status === "failed" &&
2546
- serverRuntime.lastErrorClass === "usage_limit" &&
2547
- activeThreadShell?.latestRun
2555
+ limitRecoveryRun !== null && activeThreadShell !== null
2556
? usageLimitRecoveryBannerItem({
2549
- runId: activeThreadShell.latestRun.runId,
2550
- errorCode: serverRuntime.lastErrorCode ?? null,
2551
- resetAt: serverRuntime.usageLimitResetAt ?? null,
2552
- stoppedAt: activeThreadShell.latestRun.completedAt ?? activeThreadShell.updatedAt,
2557
+ runId: limitRecoveryRun.runId,
2558
+ errorCode: serverRuntime?.lastErrorCode ?? null,
2559
+ resetAt: serverRuntime?.usageLimitResetAt ?? null,
2560
+ stoppedAt: limitRecoveryRun.completedAt ?? activeThreadShell.updatedAt,
2561
+ settled: activeThreadShell.settledOverride === "settled",
2562
+ requestPending: pendingApprovals.length > 0 || pendingUserInputs.length > 0,
2563
recovery: activeThreadShell.limitRecovery ?? null,
2564
snoozedUntil: activeThreadShell.snoozedUntil,
2565
timestampFormat,
apps/web/src/components/chat/UsageLimitRecoveryBanner.test.tsx
+2
@@ -12,6 +12,8 @@ function bannerDescription(resetAt: Date, timestampFormat: TimestampFormat) {
12
errorCode: null,
13
resetAt: resetAt.toISOString(),
14
stoppedAt: stoppedAt.toISOString(),
15
+ settled: false,
16
+ requestPending: false,
17
snoozedUntil: null,
18
recovery: null,
19
timestampFormat,
apps/web/src/components/chat/UsageLimitRecoveryBanner.tsx
+36
-20
@@ -5,6 +5,7 @@ import {
5
} from "@t3tools/contracts";
6
import { type TimestampFormat } from "@t3tools/contracts/settings";
7
import { deadlineStore } from "@t3tools/client-runtime/clock";
8
+import { limitRecoveryOwnsSnooze } from "@t3tools/client-runtime/state/thread-execution";
9
import {
10
CHATGPT_USAGE_LIMIT_CODE,
11
CHATGPT_WORKSPACE_USAGE_LIMIT_CODE,
@@ -14,7 +15,7 @@ import { useState } from "react";
15
import { useDeadlinePassed } from "../../hooks/useDeadline";
16
import { OpenAI } from "../Icons";
17
import { ChatGptUsageButton } from "../settings/ChatGptUsageButton";
17
-import { Button } from "../ui/button";
18
+import { Button, InlineButton } from "../ui/button";
19
import { formatUpcomingTimestamp } from "../../timestampFormat";
20
import { toastManager } from "../ui/toast";
21
import type { ComposerBannerStackItem } from "./ComposerBannerStack";
@@ -25,6 +26,8 @@ type RecoveryProps = {
26
errorCode: string | null;
27
resetAt: string | null;
28
stoppedAt: string;
29
+ settled: boolean;
30
+ requestPending: boolean;
31
snoozedUntil: string | null;
32
recovery: OrchestrationV2LimitRecovery | null;
33
timestampFormat: TimestampFormat;
@@ -32,20 +35,39 @@ type RecoveryProps = {
35
};
36
37
export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBannerStackItem {
35
- const { runId, errorCode, resetAt, stoppedAt, timestampFormat } = props;
36
- const canSchedule = resetAt !== null && Date.parse(resetAt) > Date.parse(stoppedAt);
38
+ const {
39
+ runId,
40
+ errorCode,
41
+ resetAt,
42
+ stoppedAt,
43
+ settled,
44
+ requestPending,
45
+ recovery,
46
+ snoozedUntil,
47
+ timestampFormat,
48
+ } = props;
49
+ // The server refuses recovery changes while a request is pending.
50
+ const canSchedule =
51
+ !settled && !requestPending && resetAt !== null && Date.parse(resetAt) > Date.parse(stoppedAt);
52
+ const resumes =
53
+ canSchedule && recovery?.runId === runId && recovery.resetAt === resetAt && recovery.autoResume;
54
const workspaceLimit = errorCode === CHATGPT_WORKSPACE_USAGE_LIMIT_CODE;
55
const chatGptLimit = workspaceLimit || errorCode === CHATGPT_USAGE_LIMIT_CODE;
56
const recoveryActions = canSchedule ? (
57
<RecoveryActions key={`${runId}:${resetAt}`} {...props} />
58
) : null;
42
- const resetDescription = resetAt
43
- ? `Resets ${formatUpcomingTimestamp(resetAt, timestampFormat)}`
59
+ const displayAt =
60
+ resumes && resetAt && snoozedUntil && Date.parse(snoozedUntil) > Date.parse(resetAt)
61
+ ? snoozedUntil
62
+ : resetAt;
63
+ const resetDescription = displayAt
64
+ ? `${resumes ? "Resumes" : "Resets"} ${formatUpcomingTimestamp(displayAt, timestampFormat)}`
65
: "Reset time unavailable; retry manually";
66
if (!chatGptLimit) {
67
return {
68
id: `usage-limit-recovery:${runId}`,
69
variant: "warning",
70
+ group: "environment",
71
icon: <GaugeIcon />,
72
title: "Usage limit reached",
73
description: resetDescription,
@@ -56,6 +78,7 @@ export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBann
78
return {
79
id: `usage-limit-recovery:${runId}`,
80
variant: "warning",
81
+ group: "environment",
82
icon: <OpenAI aria-hidden="true" />,
83
title: "ChatGPT usage limit reached",
84
description: workspaceLimit
@@ -85,13 +108,7 @@ function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: R
108
// so a snooze whose reset has passed is no longer active.
109
const resetPassed = useDeadlinePassed(resetAt === null ? null : Date.parse(resetAt));
110
const snoozed =
88
- recovery?.snooze === true &&
89
- recovery.runId === runId &&
90
- recovery.resetAt === resetAt &&
91
- resetAt !== null &&
92
- snoozedUntil !== null &&
93
- Date.parse(snoozedUntil) === Date.parse(resetAt) &&
94
- !resetPassed;
111
+ limitRecoveryOwnsSnooze({ runId, resetAt, recovery, snoozedUntil }) && !resetPassed;
112
async function toggle(action: "resume" | "snooze") {
113
if (resetAt === null) return;
114
if (action === "snooze" && !snoozed && Date.parse(resetAt) <= Date.now()) {
@@ -122,18 +139,17 @@ function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: R
139
}
140
// Inline errors would widen the actions column and crush the title.
141
return (
125
- <>
126
- <Button size="xs" variant="ghost" disabled={pending} onClick={() => void toggle("resume")}>
142
+ <span className="flex flex-wrap items-center gap-x-3 gap-y-1 px-1">
143
+ <InlineButton touchTarget="padded" disabled={pending} onClick={() => void toggle("resume")}>
144
{pending ? "Saving..." : scheduled ? "Cancel auto-resume" : "Resume at reset"}
128
- </Button>
129
- <Button
130
- size="xs"
131
- variant="ghost"
145
+ </InlineButton>
146
+ <InlineButton
147
+ touchTarget="padded"
148
disabled={pending || (!snoozed && resetPassed)}
149
onClick={() => void toggle("snooze")}
150
>
151
{pending ? "Saving..." : snoozed ? "Wake now" : "Snooze until reset"}
136
- </Button>
137
- </>
152
+ </InlineButton>
153
+ </span>
154
);
155
}
apps/web/src/components/chat/useThreadLifecycle.browser.test.tsx
+1
@@ -111,6 +111,7 @@ function RestoreBranchHarness(props: {
111
canOperateThread: true,
112
clientSettingsHydrated: true,
113
activeThreadShell: null,
114
+ limitRecoveryHoldsSnooze: false,
115
activeLatestRun: null as never,
116
activeProjectCwd: "/repo",
117
serverConfig: null,
apps/web/src/components/chat/useThreadLifecycle.tsx
+13
-8
@@ -98,6 +98,8 @@ interface ThreadLifecycleInput {
98
readonly threadDetailRef: ScopedThreadRef | null;
99
readonly activeThreadKey: string | null;
100
readonly activeThreadShell: EnvironmentThreadShell | null;
101
+ /** The usage-limit recovery banner shows this snooze and its Wake now. */
102
+ readonly limitRecoveryHoldsSnooze: boolean;
103
readonly activeLatestRun: EnvironmentThreadShell["latestRun"];
104
readonly activeProjectCwd: string | null;
105
readonly serverConfig: EnvironmentServerConfig | null;
@@ -150,6 +152,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
152
activeThreadKey,
153
activeThreadShell,
154
activeLatestRun,
155
+ limitRecoveryHoldsSnooze,
156
activeProjectCwd,
157
serverConfig,
158
runtimeMode,
@@ -610,14 +613,16 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
613
? snoozeWakeLabel(snoozedUntil, { now: `${nowMinute}:00.000Z` })
614
: null;
615
const threadStatusLine = activeThreadSnoozed ? (
613
- <ThreadStatusLine
614
- icon={<AlarmClockIcon />}
615
- label={snoozeWake && snoozeWake !== "now" ? `Snoozed, ${snoozeWake} left` : "Snoozed"}
616
- clockMinute={nowMinute}
617
- actionLabel={isUnsnoozing ? "Waking..." : "Wake now"}
618
- actionDisabled={!canOperateThread || isUnsnoozing}
619
- onAction={() => void handleUnsnoozeActiveThreadStable()}
620
- />
616
+ limitRecoveryHoldsSnooze ? null : (
617
+ <ThreadStatusLine
618
+ icon={<AlarmClockIcon />}
619
+ label={snoozeWake && snoozeWake !== "now" ? `Snoozed, ${snoozeWake} left` : "Snoozed"}
620
+ clockMinute={nowMinute}
621
+ actionLabel={isUnsnoozing ? "Waking..." : "Wake now"}
622
+ actionDisabled={!canOperateThread || isUnsnoozing}
623
+ onAction={() => void handleUnsnoozeActiveThreadStable()}
624
+ />
625
+ )
626
) : activeThreadSettled ? (
627
<ThreadStatusLine
628
icon={<CheckCircle2Icon />}
apps/web/src/components/ui/button.tsx
+5
-1
@@ -105,6 +105,9 @@ const inlineButtonVariants = cva(
105
{
106
defaultVariants: { tone: "default" },
107
variants: {
108
+ touchTarget: {
109
+ padded: "pointer-coarse:min-h-11 pointer-coarse:px-1.5",
110
+ },
111
tone: {
112
default: "text-foreground",
113
muted: "text-muted-foreground hover:text-foreground",
@@ -119,11 +122,12 @@ const inlineButtonVariants = cva(
122
export function InlineButton({
123
className,
124
tone,
125
+ touchTarget,
126
render,
127
...props
128
}: useRender.ComponentProps<"button"> & VariantProps<typeof inlineButtonVariants>) {
129
const defaultProps = {
126
- className: cn(inlineButtonVariants({ tone }), className),
130
+ className: cn(inlineButtonVariants({ tone, touchTarget }), className),
131
"data-slot": "inline-button",
132
type: render ? undefined : ("button" as const),
133
};
packages/client-runtime/src/state/threadDetail.ts
+34
-2
@@ -14,7 +14,13 @@ import {
14
type ThreadQueueWorkflowState,
15
} from "./threadWorkflows.ts";
16
import { deriveThreadTurnSubagents, type ThreadTurnSubagents } from "./threadSubagents.ts";
17
-import { presentRunStop, type RunStopPresentation } from "./threadExecution.ts";
17
+import {
18
+ deriveUsageLimitNoticeRows,
19
+ presentRunStop,
20
+ withoutUsageLimitNoticeRows,
21
+ type RunStopPresentation,
22
+ type UsageLimitNoticeRows,
23
+} from "./threadExecution.ts";
24
import {
25
deriveThreadCheckpointSummaries,
26
type ThreadCheckpointSummary,
@@ -298,11 +304,37 @@ export function createEnvironmentThreadDetailAtoms<E>(
304
}).pipe(Atom.setIdleTTL(0), Atom.withLabel(`environment-quiet-thread:${key}`));
305
});
306
307
+ // Read from the structure so streamed text does not rescan runs and turn items.
308
+ const usageLimitNoticeRowsAtomFamily = Atom.family((key: string) => {
309
+ let previous: EnvironmentThreadStructure | null = null;
310
+ let value: UsageLimitNoticeRows | null = null;
311
+ return Atom.make((get) => {
312
+ const thread = get(quietThreadAtomFamily(key));
313
+ if (thread !== previous) {
314
+ previous = thread;
315
+ value = thread === null ? null : deriveUsageLimitNoticeRows(thread.projection);
316
+ }
317
+ return value;
318
+ }).pipe(Atom.setIdleTTL(0), Atom.withLabel(`environment-thread-usage-limit-notice:${key}`));
319
+ });
320
+
321
+ // Presentation only: the projection keeps every row for other readers.
322
const visibleTurnItemsAtomFamily = Atom.family((key: string) => {
323
const projectQuestionHistory = createQuestionHistoryProjector();
324
+ let previousRows: OrchestrationV2ThreadProjection["visibleTurnItems"] | null = null;
325
+ let previousNotice: UsageLimitNoticeRows | null = null;
326
+ let previous = EMPTY_VISIBLE_TURN_ITEMS;
327
return Atom.make((get): OrchestrationV2ThreadProjection["visibleTurnItems"] => {
328
const projection = Option.getOrNull(get(threadStateValueAtomFamily(key)).data);
305
- return projection === null ? EMPTY_VISIBLE_TURN_ITEMS : projectQuestionHistory(projection);
329
+ if (projection === null) return EMPTY_VISIBLE_TURN_ITEMS;
330
+ const rows = projectQuestionHistory(projection);
331
+ const notice = get(usageLimitNoticeRowsAtomFamily(key));
332
+ if (rows !== previousRows || notice !== previousNotice) {
333
+ previousRows = rows;
334
+ previousNotice = notice;
335
+ previous = withoutUsageLimitNoticeRows(rows, notice);
336
+ }
337
+ return previous;
338
}).pipe(Atom.setIdleTTL(0), Atom.withLabel(`environment-thread-visible-turn-items:${key}`));
339
});
340
packages/client-runtime/src/state/threadExecution.ts
+96
@@ -16,6 +16,7 @@ import {
16
type ServerProvider,
17
type ServerProviderModel,
18
type OrchestrationV2ExecutionNode,
19
+ type OrchestrationV2LimitRecovery,
20
type OrchestrationV2ThreadProjection,
21
orchestrationV2RunWorkStartedAt,
22
type RunId,
@@ -41,6 +42,7 @@ import {
42
type ThreadRuntimeSummary,
43
type ThreadStructure,
44
type ThreadStructureRuntime,
45
+ type ThreadStructureTurnItem,
46
} from "./models.ts";
47
import { commandDisplayText } from "../work-log/commandLabel.ts";
48
import { formatSubagentDisplayTitle } from "./subagentDisplay.ts";
@@ -320,6 +322,100 @@ export function deriveThreadStructureRuntime(
322
};
323
}
324
325
+export interface UsageLimitNoticeRows {
326
+ readonly itemIds: ReadonlySet<ThreadStructureTurnItem["id"]>;
327
+ /** Hidden only when its text reads as the provider's limit message; see PROVIDER_LIMIT_NOTICE. */
328
+ readonly providerNoticeItemId: ThreadStructureTurnItem["id"] | null;
329
+}
330
+
331
+// Claude Code's own limit messages, such as "You've hit your 5-hour limit · resets 7:10am".
332
+const PROVIDER_LIMIT_NOTICE =
333
+ /^(?:You[’']ve hit your (?:(?:5-hour|session|weekly|usage) )?limit|You[’']re out of extra usage|Claude AI usage limit reached)(?: · resets (?:[1-9]|1[0-2])(?::[0-5]\d)?(?:am|pm)(?: \([A-Za-z0-9_+-]+(?:\/[A-Za-z0-9_+-]+)*\))?)?\.?$/i;
334
+
335
+/**
336
+ * The timeline rows that repeat a usage-limit pause while its recovery notice shows: the run's
337
+ * limit failure, Claude's pause notices, and the provider's own limit message. They return to
338
+ * history once another run executes.
339
+ */
340
+export function deriveUsageLimitNoticeRows(
341
+ projection: ThreadStructure,
342
+): UsageLimitNoticeRows | null {
343
+ const runtime = deriveThreadStructureRuntime(projection);
344
+ const run = presentedLatestRun(projection);
345
+ if (runtime?.status !== "failed" || runtime.lastErrorClass !== "usage_limit" || run === null) {
346
+ return null;
347
+ }
348
+ const failure = latestRootProviderFailure(run, projection.turnItems);
349
+ const itemIds = new Set<ThreadStructureTurnItem["id"]>();
350
+ let failedProviderTurnId: ThreadStructureTurnItem["providerTurnId"] = null;
351
+ for (const item of projection.turnItems) {
352
+ if (item.runId !== run.id) continue;
353
+ if (
354
+ item.type === "error" &&
355
+ item.status === "failed" &&
356
+ item.nodeId === run.rootNodeId &&
357
+ item.failure.class === "usage_limit"
358
+ ) {
359
+ itemIds.add(item.id);
360
+ if (item.failure === failure) failedProviderTurnId = item.providerTurnId;
361
+ }
362
+ }
363
+ let providerNotice: ThreadStructureTurnItem | null = null;
364
+ if (failedProviderTurnId !== null) {
365
+ for (const item of projection.turnItems) {
366
+ if (item.runId !== run.id || item.providerTurnId !== failedProviderTurnId) continue;
367
+ if (
368
+ item.type === "system_notice" &&
369
+ item.nodeId === run.rootNodeId &&
370
+ item.parentItemId === null &&
371
+ item.nativeItemRef?.driver === "claudeAgent" &&
372
+ item.nativeItemRef.nativeId?.startsWith(`usage-limit:${failedProviderTurnId}:`) === true
373
+ ) {
374
+ itemIds.add(item.id);
375
+ }
376
+ if (
377
+ item.type === "assistant_message" &&
378
+ item.parentItemId === null &&
379
+ (providerNotice === null || item.ordinal > providerNotice.ordinal)
380
+ ) {
381
+ providerNotice = item;
382
+ }
383
+ }
384
+ }
385
+ return { itemIds, providerNoticeItemId: providerNotice?.id ?? null };
386
+}
387
+
388
+export function withoutUsageLimitNoticeRows<
389
+ Row extends OrchestrationV2ThreadProjection["visibleTurnItems"][number],
390
+>(rows: ReadonlyArray<Row>, notice: UsageLimitNoticeRows | null): ReadonlyArray<Row> {
391
+ if (notice === null) return rows;
392
+ const hidden = ({ item }: Row) =>
393
+ notice.itemIds.has(item.id) ||
394
+ (item.id === notice.providerNoticeItemId &&
395
+ item.type === "assistant_message" &&
396
+ PROVIDER_LIMIT_NOTICE.test(item.text.trim()));
397
+ return rows.some(hidden) ? rows.filter((row) => !hidden(row)) : rows;
398
+}
399
+
400
+/** Whether a usage-limit recovery holds the thread's snooze, so its notice offers Wake now. */
401
+export function limitRecoveryOwnsSnooze(input: {
402
+ readonly runId: RunId | null | undefined;
403
+ readonly resetAt: string | null | undefined;
404
+ readonly recovery: OrchestrationV2LimitRecovery | null | undefined;
405
+ readonly snoozedUntil: string | null | undefined;
406
+}): boolean {
407
+ const { runId, resetAt, recovery, snoozedUntil } = input;
408
+ return (
409
+ recovery?.snooze === true &&
410
+ runId != null &&
411
+ recovery.runId === runId &&
412
+ resetAt != null &&
413
+ recovery.resetAt === resetAt &&
414
+ snoozedUntil != null &&
415
+ Date.parse(snoozedUntil) === Date.parse(resetAt)
416
+ );
417
+}
418
+
419
export function threadRuntimeHasInterruptibleRun(
420
runtime: ThreadStructureRuntime | null | undefined,
421
): boolean {