Repository navigation
fix(chat): offer the account switch when a Claude model limit fails a turn #10182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d9556e3
e1421d0
adb5c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,18 +71,15 @@ import { useChildrenByParent } from "../Transcript/hooks/useChildrenByParent"; | |
| import { NestedItemsProvider } from "../Transcript/providers/NestedItemsProvider"; | ||
| import { SessionModeProvider } from "../Transcript/providers/SessionModeProvider"; | ||
| import { TranscriptPluginsProvider } from "../Transcript/providers/TranscriptPluginsProvider"; | ||
| import type { AccountSwitch, SwitchAccount } from "../UsageAccountMenu"; | ||
| import { | ||
| type DrawerExit, | ||
| WorkDrawer, | ||
| type WorkDrawerHandle, | ||
| } from "../WorkDrawer"; | ||
| import { ComposerChips } from "./components/ComposerChips"; | ||
| import { SubagentNotice } from "./components/SubagentNotice"; | ||
| import { | ||
| type SwitchAccount, | ||
| type SwitchableAgent, | ||
| UsageLimitNotice, | ||
| } from "./components/UsageLimitNotice"; | ||
| import { UsageLimitNotice } from "./components/UsageLimitNotice"; | ||
| import { useAgentSignIn } from "./hooks/useAgentSignIn"; | ||
| import { useFailureRecovery } from "./hooks/useFailureRecovery"; | ||
| import { useLaunchPromptDelivered } from "./hooks/useLaunchPromptDelivered"; | ||
|
|
@@ -163,7 +160,9 @@ export function SessionView({ | |
| onSessionState?: (session: SessionState | null) => void; | ||
| /** The mode the user picked, so a resumed session can start in it again. */ | ||
| onModeChange?: (modeId: string) => void; | ||
| onSwitchAccount?: SwitchAccount; | ||
| onSwitchAccount?: ( | ||
| ...args: [...Parameters<SwitchAccount>, { continueWork: boolean }] | ||
| ) => Promise<void>; | ||
| sessionAccount?: TerminalAgentBinding["account"]; | ||
| /** | ||
| * Absent when the agent cannot branch its own session. The transcript is | ||
|
|
@@ -662,31 +661,29 @@ export function SessionView({ | |
| const limit = sessionState?.usageLimit; | ||
| const respondToUsageLimit = session.respondToUsageLimit; | ||
| const hostUrl = useWorkspaceHostUrl(workspaceId); | ||
| const limited = limit !== undefined; | ||
| const accountSwitch = useMemo<AccountSwitch | undefined>(() => { | ||
| const preset = harness ? presetForAnyHarness(harness) : undefined; | ||
| if (preset !== "claude" && preset !== "codex") return undefined; | ||
| return { | ||
| agent: preset, | ||
| hostUrl, | ||
| sessionAccount, | ||
| onSwitch: onSwitchAccount | ||
| ? (setAccount) => onSwitchAccount(setAccount, { continueWork: limited }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Continue after a login switch from a stored usage-limit failure. When the usage limit is no longer live, the account switch passes
|
||
| : undefined, | ||
| }; | ||
| }, [harness, hostUrl, sessionAccount, onSwitchAccount, limited]); | ||
| const usageLimit = useMemo(() => { | ||
| if (!limit) return undefined; | ||
| const preset = harness ? presetForAnyHarness(harness) : undefined; | ||
| const agent: SwitchableAgent | undefined = | ||
| preset === "claude" ? "claude" : preset === "codex" ? "codex" : undefined; | ||
| return { | ||
| limit, | ||
| respond: respondToUsageLimit, | ||
| modelLabel: limit.model | ||
| ? modelDisplayName(limit.model, configOptions ?? []) | ||
| : undefined, | ||
| agent, | ||
| hostUrl, | ||
| sessionAccount, | ||
| onSwitchAccount, | ||
| }; | ||
| }, [ | ||
| limit, | ||
| respondToUsageLimit, | ||
| harness, | ||
| configOptions, | ||
| hostUrl, | ||
| onSwitchAccount, | ||
| sessionAccount, | ||
| ]); | ||
| }, [limit, respondToUsageLimit, configOptions]); | ||
|
|
||
| const heldQueued = held?.queued; | ||
| const heldLaunched = held?.launched; | ||
|
|
@@ -706,6 +703,10 @@ export function SessionView({ | |
| [sentOutbox.transcript, heldOutbox], | ||
| ); | ||
| const booting = sessionState?.status === "starting"; | ||
| const resumeAfterLimit = useMemo( | ||
| () => (limit ? () => respondToUsageLimit("resume") : undefined), | ||
| [limit, respondToUsageLimit], | ||
| ); | ||
| const openModelPicker = useCallback( | ||
| () => composerRef.current?.openModelPicker(), | ||
| [], | ||
|
|
@@ -714,6 +715,7 @@ export function SessionView({ | |
| useAgentSignIn(presetId); | ||
| const { failureActions, onSetConfigOption, onModelPickerOpenChange } = | ||
| useFailureRecovery({ | ||
| accountSwitch, | ||
| blocked: | ||
| !loaded || | ||
| booting || | ||
|
|
@@ -730,6 +732,7 @@ export function SessionView({ | |
| onRestartAndContinue, | ||
| onStartNewChat, | ||
| openModelPicker, | ||
| resumeAfterLimit, | ||
| sendPrompt, | ||
| setConfigOption, | ||
| }); | ||
|
|
@@ -747,13 +750,10 @@ export function SessionView({ | |
| ); | ||
| const usageLimitNotice = usageLimit && !held && ( | ||
| <UsageLimitNotice | ||
| agent={usageLimit.agent} | ||
| hostUrl={usageLimit.hostUrl} | ||
| accountSwitch={accountSwitch} | ||
| limit={usageLimit.limit} | ||
| modelLabel={usageLimit.modelLabel} | ||
| onRespond={usageLimit.respond} | ||
| onSwitchAccount={usageLimit.onSwitchAccount} | ||
| sessionAccount={usageLimit.sessionAccount} | ||
| /> | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schedule the continuation only when no prompts are queued at replacement commit.
The continuation flag uses
queued.lengthfrom the moment the switch starts. Messages submitted whilesetAccount()is pending go toqueuedPromptsand are missing from that snapshot. The replacement can then receiveCONTINUE_PROMPTas its pending prompt next to a queued user message. The new session gets an extra continue prompt that the account-switch behavior does not call for. Queued messages should be sent in order, and the continue prompt should be sent only when nothing is queued.Decide the continuation at replacement commit, using the prompts queued at that point. When any prompts are queued, send them without
CONTINUE_PROMPT. When none are queued, keep the current continuation.