Skip to content

Commit c7537d0

Browse files
shivamhwpclaude
andauthored
fix(chat): show one usage-limit recovery notice (#29292)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 8b2c4d1 commit c7537d0

10 files changed

Lines changed: 322 additions & 100 deletions

File tree

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
BACKGROUND_WORK_STOP_RETRY_AFTER_MS,
6363
type BackgroundWorkStopRequest,
6464
isBackgroundWorkStopPending,
65+
limitRecoveryOwnsSnooze,
6566
presentPendingBackgroundWork,
6667
presentProviderGoal,
6768
} from "@t3tools/client-runtime/state/thread-execution";
@@ -642,6 +643,19 @@ function ThreadDetailBody(
642643
return () => clearTimeout(timer);
643644
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Re-arm if timer clamping fires before the wake time.
644645
}, [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+
});
645659
const settled = configLoaded && props.selectedThread.settledOverride === "settled";
646660
const wokeAt = configLoaded ? threadWokeAt(props.selectedThread, { now: lifecycleNow }) : null;
647661
const woke = isThreadWokeUnseen({
@@ -809,30 +823,31 @@ function ThreadDetailBody(
809823
},
810824
};
811825
}
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";
814828
const label =
815-
snoozed && snoozedUntil !== null
829+
lifecycleSnoozed && snoozedUntil !== null
816830
? `Snoozed, wakes in ${snoozeWakeLabel(snoozedUntil, { now: lifecycleNow })}`
817831
: settled
818832
? "Settled"
819833
: "Woke from snooze";
820-
const actionLabel = snoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
834+
const actionLabel = lifecycleSnoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
821835
return {
822836
kind: "lifecycle",
823837
state,
824838
label,
825839
action: {
826840
label: statusPending
827-
? snoozed
841+
? lifecycleSnoozed
828842
? "Waking..."
829843
: settled
830844
? "Un-settling..."
831845
: "Dismissing..."
832846
: actionLabel,
833847
accessibilityLabel: actionLabel,
834848
disabled: !props.canOperateThread || statusPending,
835-
onPress: () => void runStatusAction(snoozed ? "wake" : settled ? "unsettle" : "dismiss"),
849+
onPress: () =>
850+
void runStatusAction(lifecycleSnoozed ? "wake" : settled ? "unsettle" : "dismiss"),
836851
},
837852
};
838853
}

‎apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx‎

Lines changed: 93 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { Button } from "../../components/ui/Button";
21
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
32
import { AsyncResult } from "effect/reactivity";
43
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
4+
import { limitRecoveryOwnsSnooze } from "@t3tools/client-runtime/state/thread-execution";
55
import type { EnvironmentId } from "@t3tools/contracts";
66
import {
77
CHATGPT_USAGE_LIMIT_CODE,
88
CHATGPT_USAGE_URL,
99
CHATGPT_WORKSPACE_ADMIN_REQUEST,
1010
CHATGPT_WORKSPACE_USAGE_LIMIT_CODE,
1111
} from "@t3tools/shared/usageLimits";
12-
import * as DateTime from "effect/DateTime";
1312
import * as Clipboard from "expo-clipboard";
1413
import { useState } from "react";
1514
import { Linking, Pressable, View } from "react-native";
@@ -31,13 +30,22 @@ export function UsageLimitRecoveryCard({
3130
const [error, setError] = useState<string | null>(null);
3231
const resetAt = thread.runtime?.usageLimitResetAt ?? null;
3332
const canSchedule =
33+
thread.settledOverride !== "settled" &&
3434
resetAt !== null &&
3535
Date.parse(resetAt) > Date.parse(thread.latestRun?.completedAt ?? thread.updatedAt);
3636
const resetPassed = useDeadlinePassed(resetAt === null ? null : Date.parse(resetAt));
3737
const runId = thread.latestRun?.runId;
3838
const recovery = thread.limitRecovery;
3939
const scheduled =
4040
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;
4149
const [copied, setCopied] = useState(false);
4250
const [actionPending, setActionPending] = useState(false);
4351
const code = thread.runtime?.lastErrorCode;
@@ -51,16 +59,19 @@ export function UsageLimitRecoveryCard({
5159
!runId
5260
)
5361
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+
)}.`
5667
: null;
5768
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;
6475
async function toggle(action: "resume" | "snooze") {
6576
if (!resetAt || !runId || !canSchedule) return;
6677
if (action === "snooze" && !snoozed && Date.parse(resetAt) <= Date.now()) {
@@ -123,50 +134,52 @@ export function UsageLimitRecoveryCard({
123134
<ProviderIcon provider="codex" size={16} />
124135
</View>
125136
) : null}
126-
<View className="min-w-0 flex-1 gap-2">
137+
<View className="min-w-0 flex-1 gap-1">
127138
{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
154141
</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}
170183
</View>
171184
) : null}
172185
{error ? (
@@ -178,3 +191,31 @@ export function UsageLimitRecoveryCard({
178191
</View>
179192
);
180193
}
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‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
deriveThreadActivityRun,
8383
deriveLatestThreadRun,
8484
deriveThreadStructureRuntime,
85+
limitRecoveryOwnsSnooze,
8586
} from "@t3tools/client-runtime/state/thread-execution";
8687
import {
8788
resolveWorkflowOpening,
@@ -983,11 +984,19 @@ export default function ChatView(props: ChatViewProps) {
983984
);
984985
const browserAvailable = isPreviewSupportedInRuntime() || activeEnvironmentServerBrowser;
985986
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+
});
986998
const timelineThreadError =
987-
serverRuntime?.status === "failed" &&
988-
serverRuntime.lastErrorClass === "usage_limit" &&
989-
activeThreadShell?.latestRun &&
990-
visibleThreadError === serverRuntime.lastError
999+
limitRecoveryRun !== null && visibleThreadError === serverRuntime?.lastError
9911000
? null
9921001
: visibleThreadError;
9931002

@@ -2414,6 +2423,7 @@ export default function ChatView(props: ChatViewProps) {
24142423
activeThreadKey,
24152424
activeThreadShell,
24162425
activeLatestRun,
2426+
limitRecoveryHoldsSnooze,
24172427
activeProjectCwd,
24182428
serverConfig,
24192429
runtimeMode,
@@ -2542,14 +2552,14 @@ export default function ChatView(props: ChatViewProps) {
25422552
return item ? [item] : [];
25432553
});
25442554
const limitRecoveryBanner =
2545-
serverRuntime?.status === "failed" &&
2546-
serverRuntime.lastErrorClass === "usage_limit" &&
2547-
activeThreadShell?.latestRun
2555+
limitRecoveryRun !== null && activeThreadShell !== null
25482556
? 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,
25532563
recovery: activeThreadShell.limitRecovery ?? null,
25542564
snoozedUntil: activeThreadShell.snoozedUntil,
25552565
timestampFormat,

‎apps/web/src/components/chat/UsageLimitRecoveryBanner.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function bannerDescription(resetAt: Date, timestampFormat: TimestampFormat) {
1212
errorCode: null,
1313
resetAt: resetAt.toISOString(),
1414
stoppedAt: stoppedAt.toISOString(),
15+
settled: false,
16+
requestPending: false,
1517
snoozedUntil: null,
1618
recovery: null,
1719
timestampFormat,

0 commit comments

Comments
 (0)