Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ This fork keeps the Windows reliability, durable checkpointing, and workspace ca

## Divergence Log

### DL060 — Usage-limit retry scheduling

When a provider usage limit stops a thread and automatic recovery has not resumed it, the web client offers a Schedule retry popup from the Usage limit reached banner. Its choices use the environment's configurable snooze presets, arm the existing usage-limit auto-resume recovery, and snooze the thread until the selected local time.

**Implementation evidence:** `apps/web/src/components/chat/UsageLimitRecoveryBanner.tsx`, `apps/web/src/components/ChatView.tsx`, and `apps/web/src/components/chat/UsageLimitRecoveryBanner.test.tsx`.

**Recorded validation:** Web package typecheck, focused Oxlint, formatting, and `git diff --check` pass. The integrated preview reached the dev splash screen after the web bundle loaded.

**Last updated:** 2026-11-23

Each behavior where this fork differs from upstream has one entry here. If you change code in this repository, check if this log needs an update.

The rules:
Expand Down
32 changes: 32 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ThreadFind, ThreadFindCanvas } from "./chat/ThreadFindProvider";
import { closeThreadFind, openThreadFind, useThreadFindOpen } from "./chat/threadFindStore";
import { THREAD_FIND_BAR_RESERVED_HEIGHT } from "./chat/ThreadFindBar";
import { usageLimitRecoveryBannerItem } from "./chat/UsageLimitRecoveryBanner";
import { resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
import { isThreadEnvironmentLocked, resolveDraftHeroState } from "./ChatView.logic";
import { useQueuedRunEdit } from "./chat/useQueuedRunEdit";
import {
Expand Down Expand Up @@ -140,6 +141,7 @@ import {
use,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from "react";
Expand Down Expand Up @@ -237,6 +239,7 @@ import {
useEnvironmentSettings,
} from "../hooks/useSettings";
import { useNowMinute } from "../hooks/useNowMinute";
import { formatUpcomingTimestamp } from "../timestampFormat";
import { usePanelAnimationSettings, usePanelPresence } from "../panelAnimations";
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
Expand Down Expand Up @@ -498,6 +501,9 @@ export default function ChatView(props: ChatViewProps) {
const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
reportFailure: false,
});
const snoozeThread = useOrchestrationCommand(threadEnvironment.snooze, {
reportFailure: false,
});
const resumeAutoRetry = useAtomCommand(threadEnvironment.resumeAutoRetry, "resume auto retry");
const canResumeAutoRetry = useAtomValue(
threadEnvironment.resumeAutoRetry.permissionAtom(environmentId),
Expand Down Expand Up @@ -867,6 +873,14 @@ export default function ChatView(props: ChatViewProps) {
}
}
const nowMinute = useNowMinute();
const retryPresets = useMemo(
() =>
resolveSnoozePresets(new Date(Date.parse(`${nowMinute}:00Z`)), {
presets: settings.snoozePresets,
formatTime: (date) => formatUpcomingTimestamp(date.toISOString(), timestampFormat),
}),
[nowMinute, settings.snoozePresets, timestampFormat],
);
const draftDefaultModelSelection = draftThread
? resolveProjectSettings(
settings,
Expand Down Expand Up @@ -2738,6 +2752,24 @@ export default function ChatView(props: ChatViewProps) {
});
if (result._tag === "Failure") throw squashAtomCommandFailure(result);
},
retryPresets,
onScheduleRetry: async (snoozedUntil) => {
const resetAt = serverRuntime?.usageLimitResetAt;
if (resetAt === null || resetAt === undefined)
throw new Error("Reset time unavailable.");
await updateThreadMetadata({
environmentId,
input: {
threadId: activeThreadShell.id,
limitRecovery: { runId: limitRecoveryRun.runId, resetAt, autoResume: true },
},
});
const result = await snoozeThread({
environmentId,
input: { threadId: activeThreadShell.id, snoozedUntil },
});
if (result._tag === "Failure") throw squashAtomCommandFailure(result);
},
})
: null;
const composerBannerItems = (() => {
Expand Down
63 changes: 62 additions & 1 deletion apps/web/src/components/chat/UsageLimitRecoveryBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type RunId,
} from "@t3tools/contracts";
import { type TimestampFormat } from "@t3tools/contracts/settings";
import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";
import { deadlineStore } from "@t3tools/client-runtime/clock";
import { limitRecoveryOwnsSnooze } from "@t3tools/client-runtime/state/thread-execution";
import {
Expand All @@ -16,6 +17,7 @@ import { useDeadlinePassed } from "../../hooks/useDeadline";
import { OpenAI } from "../Icons";
import { ChatGptUsageButton } from "../settings/ChatGptUsageButton";
import { Button, InlineButton } from "../ui/button";
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
import { formatUpcomingTimestamp } from "../../timestampFormat";
import { toastManager } from "../ui/toast";
import type { ComposerBannerStackItem } from "./ComposerBannerStack";
Expand All @@ -32,6 +34,8 @@ type RecoveryProps = {
recovery: OrchestrationV2LimitRecovery | null;
timestampFormat: TimestampFormat;
onChange: (recovery: OrchestrationV2LimitRecoveryUpdate) => Promise<void>;
retryPresets?: ReadonlyArray<SnoozePreset>;
onScheduleRetry?: (snoozedUntil: string) => Promise<void>;
};

export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBannerStackItem {
Expand All @@ -56,6 +60,14 @@ export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBann
const recoveryActions = canSchedule ? (
<RecoveryActions key={`${runId}:${resetAt}`} {...props} />
) : null;
const scheduleAction =
canSchedule && props.onScheduleRetry && props.retryPresets?.length ? (
<ScheduleRetryAction
{...props}
onScheduleRetry={props.onScheduleRetry}
retryPresets={props.retryPresets}
/>
) : null;
const displayAt =
resumes && resetAt && snoozedUntil && Date.parse(snoozedUntil) > Date.parse(resetAt)
? snoozedUntil
Expand All @@ -71,7 +83,12 @@ export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBann
icon: <GaugeIcon />,
title: "Usage limit reached",
description: resetDescription,
actions: recoveryActions,
actions: (
<>
{recoveryActions}
{scheduleAction}
</>
),
};
}
// OpenAI's partner guidelines specify this ChatGPT notice and its actions.
Expand All @@ -87,6 +104,7 @@ export function usageLimitRecoveryBannerItem(props: RecoveryProps): ComposerBann
actions: (
<>
{recoveryActions}
{scheduleAction}
{workspaceLimit ? (
<Button size="xs" variant="ghost" onClick={copyAdminRequest}>
Copy request for admin
Expand Down Expand Up @@ -153,3 +171,46 @@ function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: R
</span>
);
}

function ScheduleRetryAction({
retryPresets,
onScheduleRetry,
}: Required<Pick<RecoveryProps, "retryPresets" | "onScheduleRetry">>) {
const [pending, setPending] = useState(false);
return (
<Popover>
<PopoverTrigger render={<Button size="xs" variant="ghost" disabled={pending} />}>
{pending ? "Scheduling…" : "Schedule retry"}
</PopoverTrigger>
<PopoverPopup aria-label="Schedule retry" width="sm" side="top" align="start">
<div className="flex flex-col gap-1 p-1">
<p className="px-2 pb-1 text-xs text-muted-foreground">Retry this thread</p>
{retryPresets.map((preset) => (
<Button
key={preset.id}
type="button"
variant="ghost"
className="justify-between"
disabled={pending}
onClick={() => {
setPending(true);
void onScheduleRetry(preset.snoozedUntil)
.catch((cause) => {
toastManager.add({
type: "error",
title: "Could not schedule retry",
description: cause instanceof Error ? cause.message : "An error occurred.",
});
})
.finally(() => setPending(false));
}}
>
<span>{preset.label}</span>
<span className="text-xs text-muted-foreground">{preset.whenLabel}</span>
</Button>
))}
</div>
</PopoverPopup>
</Popover>
);
}
Loading