Skip to content
Closed
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 apps/server/src/orchestration-v2/runtimeLayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4684,6 +4684,10 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
const orchestrator = yield* Orchestrator.OrchestratorV2;
const events = yield* EventSink.EventSinkV2;
const threadId = ThreadId.make(`manual-resume:${reason}`);
const switchedModelSelection = {
instanceId: alternateInstanceId,
model: "gpt-5.5",
} satisfies ModelSelection;
const projectId = ProjectId.make(`manual-resume:project:${reason}`);
const now = yield* DateTime.now;
const createdAt = DateTime.formatIso(now);
Expand Down Expand Up @@ -4816,6 +4820,8 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
manualContinuationOfRunId: source.id,
text: "Continue where you left off.",
attachments: [],
// A usage limit is often sidestepped by continuing on another provider.
...(reason === "usage_limit" ? { modelSelection: switchedModelSelection } : {}),
dispatchMode: { type: "start_immediately" as const },
createdBy: "user" as const,
creationSource: "web" as const,
Expand All @@ -4825,6 +4831,10 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
assert.lengthOf(after.runs, 3);
assert.equal(after.runs[1]?.status, "queued");
assert.equal(after.runs[2]?.status, "starting");
const expectedModelSelection =
reason === "usage_limit" ? switchedModelSelection : modelSelection;
assert.deepEqual(after.runs[2]?.modelSelection, expectedModelSelection);
assert.deepEqual(after.thread.modelSelection, expectedModelSelection);
assert.equal(
(yield* orchestrator.dispatch(resume("second")).pipe(Effect.exit))._tag,
"Failure",
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2139,16 +2139,17 @@ export default function ChatView(props: ChatViewProps) {
isServerThread &&
serverProjection?.runs.some((run) => run.status === "queued" && run.queueHeld === true) ===
true;
const resumableRunId = useMemo(() => {
const resumableRun = useMemo(() => {
if (!isServerThread || serverProjection === null) return null;
const run = latestExecutedRun(serverProjection.runs);
if (run?.status === "interrupted") return run.id;
if (run?.status === "interrupted") return run;
return run?.status === "failed" &&
serverRuntime?.lastErrorClass === "usage_limit" &&
latestRootProviderFailure(run, serverProjection.turnItems)?.class === "usage_limit"
? run.id
? run
: null;
}, [isServerThread, serverProjection, serverRuntime?.lastErrorClass]);
const resumableRunId = resumableRun?.id ?? null;
const parentSubagentThreadId =
activeThread?.lineage.relationshipToParent === "subagent"
? activeThread.lineage.parentThreadId
Expand Down Expand Up @@ -8604,11 +8605,14 @@ export default function ChatView(props: ChatViewProps) {
interactionMode,
});
if (settingsResult._tag === "Failure") return settingsResult;
// A model picked after the run stopped (say, to get past a usage limit) carries the turn.
const modelSelection = composerRef.current?.getSendContext().selectedModelSelection;
const turnResult = await startThreadTurn({
environmentId,
input: {
threadId,
manualContinuationOfRunId: resumableRunId,
...(modelSelection ? { modelSelection } : {}),
message: {
messageId: newMessageId(),
role: "user",
Expand Down Expand Up @@ -11533,6 +11537,7 @@ export default function ChatView(props: ChatViewProps) {
isConnecting={isConnecting}
isSendBusy={isSendBusy || isSavingQueuedEdit || isResuming}
canResume={resumableRunId !== null || hasHeldQueuedRuns}
resumeRunModelSelection={resumableRun?.modelSelection ?? null}
isRevertingCheckpoint={isRevertingCheckpoint}
sendDisabledReason={
!canOperateThread
Expand Down
25 changes: 20 additions & 5 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
isEnvironmentUnavailable: boolean;
hasSendableContent: boolean;
canResume: boolean;
resumeModelName: string | null;
preserveComposerFocusOnPointerDown?: boolean;
isEditingQueuedMessage: boolean;
onSubmitMessage: React.MouseEventHandler<HTMLButtonElement>;
Expand Down Expand Up @@ -1419,6 +1420,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
isPreparingWorktree={props.isPreparingWorktree}
hasSendableContent={props.hasSendableContent}
canResume={props.canResume}
resumeModelName={props.resumeModelName}
preserveComposerFocusOnPointerDown={props.preserveComposerFocusOnPointerDown ?? false}
isEditingQueuedMessage={props.isEditingQueuedMessage}
onSubmitMessage={props.onSubmitMessage}
Expand Down Expand Up @@ -1543,6 +1545,8 @@ export interface ChatComposerProps {
isConnecting: boolean;
isSendBusy: boolean;
canResume: boolean;
/** The model the resumable run used; resuming with a different composer model continues with it. */
resumeRunModelSelection: ModelSelection | null;
isRevertingCheckpoint?: boolean;
sendDisabledReason: string | null;
isPreparingWorktree: boolean;
Expand Down Expand Up @@ -1724,6 +1728,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
isConnecting,
isSendBusy,
canResume,
resumeRunModelSelection,
isRevertingCheckpoint = false,
sendDisabledReason: externalSendDisabledReason,
isPreparingWorktree,
Expand Down Expand Up @@ -3001,6 +3006,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
);
const showResumeAction =
canResume && !composerDraftHasUserContent(composerDraft) && !isEditingQueuedMessage;
const resumeModelName =
showResumeAction &&
resumeRunModelSelection !== null &&
(resumeRunModelSelection.instanceId !== selectedModelSelection.instanceId ||
resumeRunModelSelection.model !== selectedModelSelection.model)
? resolveContextWindowModelDisplayName(selectedModelSelection, modelOptionsByInstance)
: null;
const collapsedComposerPrimaryActionDisabled =
phase === "running" ||
isSendBusy ||
Expand All @@ -3010,11 +3022,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
projectSelectionRequired ||
environmentUnavailable !== null ||
(!composerSendState.hasSendableContent && !showResumeAction);
const collapsedComposerPrimaryActionLabel = showResumeAction
? "Resume thread"
: props.resumeCompactionTokens !== null
? "Open composer to compact and send"
: "Send message";
const collapsedComposerPrimaryActionLabel = resumeModelName
? `Continue with ${resumeModelName}`
: showResumeAction
? "Resume thread"
: props.resumeCompactionTokens !== null
? "Open composer to compact and send"
: "Send message";
const showMobilePendingAnswerActions =
isMobileViewport && !isComposerCollapsedMobile && pendingPrimaryAction !== null;

Expand Down Expand Up @@ -7596,6 +7610,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
isPreparingWorktree={isPreparingWorktree}
hasSendableContent={composerSendState.hasSendableContent}
canResume={showResumeAction}
resumeModelName={resumeModelName}
preserveComposerFocusOnPointerDown={isMobileViewport || isComposerResting}
isEditingQueuedMessage={isEditingQueuedMessage}
onSubmitMessage={handleSubmitMessage}
Expand Down
31 changes: 31 additions & 0 deletions apps/web/src/components/chat/ComposerPrimaryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ interface ComposerPrimaryActionsProps {
isPreparingWorktree: boolean;
hasSendableContent: boolean;
canResume?: boolean;
/** Set when the composer's model differs from the run being resumed: resume continues with it. */
resumeModelName?: string | null;
preserveComposerFocusOnPointerDown?: boolean;
isEditingQueuedMessage?: boolean;
onSubmitMessage?: MouseEventHandler<HTMLButtonElement>;
Expand Down Expand Up @@ -100,6 +102,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
isPreparingWorktree,
hasSendableContent,
canResume = false,
resumeModelName = null,
preserveComposerFocusOnPointerDown = false,
isEditingQueuedMessage = false,
onSubmitMessage,
Expand Down Expand Up @@ -319,6 +322,34 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
);
}

if (showResume && resumeModelName) {
const continueLabel = `Continue with ${resumeModelName}`;
return (
<Tooltip key="continue">
<TooltipTrigger
render={
<button
type="button"
className={cn(messageActionPillClassName, "h-9 sm:h-8", compact ? "px-3" : "px-4")}
{...pointerFocusProps}
onClick={onResume}
disabled={sendBlocked}
aria-label={continueLabel}
/>
}
>
{isConnecting || isSendBusy ? (
<Spinner size="sm" aria-hidden="true" />
) : (
<PlayIcon className="size-3.5 fill-current" aria-hidden="true" />
)}
{compact ? "Continue" : continueLabel}
</TooltipTrigger>
<TooltipPopup>{sendDisabledReason ?? continueLabel}</TooltipPopup>
</Tooltip>
);
}

const submitLabel = showResume
? "Resume thread"
: isEditingQueuedMessage
Expand Down
Loading