Skip to content

Commit 019c017

Browse files
fagnersalesclaude
andcommitted
feat(web): continue a usage-limited thread with the newly picked model
When a run stops on a usage limit, picking another model in the composer turns the resume button into "Continue with <model>". Resuming now sends the composer's model selection, so the thread continues on the new model without retyping the message. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent a8c4802 commit 019c017

4 files changed

Lines changed: 69 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,6 +4684,10 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
46844684
const orchestrator = yield* Orchestrator.OrchestratorV2;
46854685
const events = yield* EventSink.EventSinkV2;
46864686
const threadId = ThreadId.make(`manual-resume:${reason}`);
4687+
const switchedModelSelection = {
4688+
instanceId: alternateInstanceId,
4689+
model: "gpt-5.5",
4690+
} satisfies ModelSelection;
46874691
const projectId = ProjectId.make(`manual-resume:project:${reason}`);
46884692
const now = yield* DateTime.now;
46894693
const createdAt = DateTime.formatIso(now);
@@ -4816,6 +4820,8 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
48164820
manualContinuationOfRunId: source.id,
48174821
text: "Continue where you left off.",
48184822
attachments: [],
4823+
// A usage limit is often sidestepped by continuing on another provider.
4824+
...(reason === "usage_limit" ? { modelSelection: switchedModelSelection } : {}),
48194825
dispatchMode: { type: "start_immediately" as const },
48204826
createdBy: "user" as const,
48214827
creationSource: "web" as const,
@@ -4825,6 +4831,10 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
48254831
assert.lengthOf(after.runs, 3);
48264832
assert.equal(after.runs[1]?.status, "queued");
48274833
assert.equal(after.runs[2]?.status, "starting");
4834+
const expectedModelSelection =
4835+
reason === "usage_limit" ? switchedModelSelection : modelSelection;
4836+
assert.deepEqual(after.runs[2]?.modelSelection, expectedModelSelection);
4837+
assert.deepEqual(after.thread.modelSelection, expectedModelSelection);
48284838
assert.equal(
48294839
(yield* orchestrator.dispatch(resume("second")).pipe(Effect.exit))._tag,
48304840
"Failure",

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,16 +2139,17 @@ export default function ChatView(props: ChatViewProps) {
21392139
isServerThread &&
21402140
serverProjection?.runs.some((run) => run.status === "queued" && run.queueHeld === true) ===
21412141
true;
2142-
const resumableRunId = useMemo(() => {
2142+
const resumableRun = useMemo(() => {
21432143
if (!isServerThread || serverProjection === null) return null;
21442144
const run = latestExecutedRun(serverProjection.runs);
2145-
if (run?.status === "interrupted") return run.id;
2145+
if (run?.status === "interrupted") return run;
21462146
return run?.status === "failed" &&
21472147
serverRuntime?.lastErrorClass === "usage_limit" &&
21482148
latestRootProviderFailure(run, serverProjection.turnItems)?.class === "usage_limit"
2149-
? run.id
2149+
? run
21502150
: null;
21512151
}, [isServerThread, serverProjection, serverRuntime?.lastErrorClass]);
2152+
const resumableRunId = resumableRun?.id ?? null;
21522153
const parentSubagentThreadId =
21532154
activeThread?.lineage.relationshipToParent === "subagent"
21542155
? activeThread.lineage.parentThreadId
@@ -8604,11 +8605,14 @@ export default function ChatView(props: ChatViewProps) {
86048605
interactionMode,
86058606
});
86068607
if (settingsResult._tag === "Failure") return settingsResult;
8608+
// A model picked after the run stopped (say, to get past a usage limit) carries the turn.
8609+
const modelSelection = composerRef.current?.getSendContext().selectedModelSelection;
86078610
const turnResult = await startThreadTurn({
86088611
environmentId,
86098612
input: {
86108613
threadId,
86118614
manualContinuationOfRunId: resumableRunId,
8615+
...(modelSelection ? { modelSelection } : {}),
86128616
message: {
86138617
messageId: newMessageId(),
86148618
role: "user",
@@ -11533,6 +11537,7 @@ export default function ChatView(props: ChatViewProps) {
1153311537
isConnecting={isConnecting}
1153411538
isSendBusy={isSendBusy || isSavingQueuedEdit || isResuming}
1153511539
canResume={resumableRunId !== null || hasHeldQueuedRuns}
11540+
resumeRunModelSelection={resumableRun?.modelSelection ?? null}
1153611541
isRevertingCheckpoint={isRevertingCheckpoint}
1153711542
sendDisabledReason={
1153811543
!canOperateThread

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
13761376
isEnvironmentUnavailable: boolean;
13771377
hasSendableContent: boolean;
13781378
canResume: boolean;
1379+
resumeModelName: string | null;
13791380
preserveComposerFocusOnPointerDown?: boolean;
13801381
isEditingQueuedMessage: boolean;
13811382
onSubmitMessage: React.MouseEventHandler<HTMLButtonElement>;
@@ -1419,6 +1420,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
14191420
isPreparingWorktree={props.isPreparingWorktree}
14201421
hasSendableContent={props.hasSendableContent}
14211422
canResume={props.canResume}
1423+
resumeModelName={props.resumeModelName}
14221424
preserveComposerFocusOnPointerDown={props.preserveComposerFocusOnPointerDown ?? false}
14231425
isEditingQueuedMessage={props.isEditingQueuedMessage}
14241426
onSubmitMessage={props.onSubmitMessage}
@@ -1543,6 +1545,8 @@ export interface ChatComposerProps {
15431545
isConnecting: boolean;
15441546
isSendBusy: boolean;
15451547
canResume: boolean;
1548+
/** The model the resumable run used; resuming with a different composer model continues with it. */
1549+
resumeRunModelSelection: ModelSelection | null;
15461550
isRevertingCheckpoint?: boolean;
15471551
sendDisabledReason: string | null;
15481552
isPreparingWorktree: boolean;
@@ -1724,6 +1728,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
17241728
isConnecting,
17251729
isSendBusy,
17261730
canResume,
1731+
resumeRunModelSelection,
17271732
isRevertingCheckpoint = false,
17281733
sendDisabledReason: externalSendDisabledReason,
17291734
isPreparingWorktree,
@@ -3001,6 +3006,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
30013006
);
30023007
const showResumeAction =
30033008
canResume && !composerDraftHasUserContent(composerDraft) && !isEditingQueuedMessage;
3009+
const resumeModelName =
3010+
showResumeAction &&
3011+
resumeRunModelSelection !== null &&
3012+
(resumeRunModelSelection.instanceId !== selectedModelSelection.instanceId ||
3013+
resumeRunModelSelection.model !== selectedModelSelection.model)
3014+
? resolveContextWindowModelDisplayName(selectedModelSelection, modelOptionsByInstance)
3015+
: null;
30043016
const collapsedComposerPrimaryActionDisabled =
30053017
phase === "running" ||
30063018
isSendBusy ||
@@ -3010,11 +3022,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
30103022
projectSelectionRequired ||
30113023
environmentUnavailable !== null ||
30123024
(!composerSendState.hasSendableContent && !showResumeAction);
3013-
const collapsedComposerPrimaryActionLabel = showResumeAction
3014-
? "Resume thread"
3015-
: props.resumeCompactionTokens !== null
3016-
? "Open composer to compact and send"
3017-
: "Send message";
3025+
const collapsedComposerPrimaryActionLabel = resumeModelName
3026+
? `Continue with ${resumeModelName}`
3027+
: showResumeAction
3028+
? "Resume thread"
3029+
: props.resumeCompactionTokens !== null
3030+
? "Open composer to compact and send"
3031+
: "Send message";
30183032
const showMobilePendingAnswerActions =
30193033
isMobileViewport && !isComposerCollapsedMobile && pendingPrimaryAction !== null;
30203034

@@ -7596,6 +7610,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
75967610
isPreparingWorktree={isPreparingWorktree}
75977611
hasSendableContent={composerSendState.hasSendableContent}
75987612
canResume={showResumeAction}
7613+
resumeModelName={resumeModelName}
75997614
preserveComposerFocusOnPointerDown={isMobileViewport || isComposerResting}
76007615
isEditingQueuedMessage={isEditingQueuedMessage}
76017616
onSubmitMessage={handleSubmitMessage}

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ interface ComposerPrimaryActionsProps {
4444
isPreparingWorktree: boolean;
4545
hasSendableContent: boolean;
4646
canResume?: boolean;
47+
/** Set when the composer's model differs from the run being resumed: resume continues with it. */
48+
resumeModelName?: string | null;
4749
preserveComposerFocusOnPointerDown?: boolean;
4850
isEditingQueuedMessage?: boolean;
4951
onSubmitMessage?: MouseEventHandler<HTMLButtonElement>;
@@ -100,6 +102,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
100102
isPreparingWorktree,
101103
hasSendableContent,
102104
canResume = false,
105+
resumeModelName = null,
103106
preserveComposerFocusOnPointerDown = false,
104107
isEditingQueuedMessage = false,
105108
onSubmitMessage,
@@ -319,6 +322,34 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
319322
);
320323
}
321324

325+
if (showResume && resumeModelName) {
326+
const continueLabel = `Continue with ${resumeModelName}`;
327+
return (
328+
<Tooltip key="continue">
329+
<TooltipTrigger
330+
render={
331+
<button
332+
type="button"
333+
className={cn(messageActionPillClassName, "h-9 sm:h-8", compact ? "px-3" : "px-4")}
334+
{...pointerFocusProps}
335+
onClick={onResume}
336+
disabled={sendBlocked}
337+
aria-label={continueLabel}
338+
/>
339+
}
340+
>
341+
{isConnecting || isSendBusy ? (
342+
<Spinner size="sm" aria-hidden="true" />
343+
) : (
344+
<PlayIcon className="size-3.5 fill-current" aria-hidden="true" />
345+
)}
346+
{compact ? "Continue" : continueLabel}
347+
</TooltipTrigger>
348+
<TooltipPopup>{sendDisabledReason ?? continueLabel}</TooltipPopup>
349+
</Tooltip>
350+
);
351+
}
352+
322353
const submitLabel = showResume
323354
? "Resume thread"
324355
: isEditingQueuedMessage

0 commit comments

Comments
 (0)