fix(cli): prevent race condition when restoring prompt after context overflow (#13473)

This commit is contained in:
Sandy Tao
2025-11-20 13:54:16 +08:00
committed by GitHub
parent 66927f4520
commit 4e2d92d999
2 changed files with 82 additions and 1 deletions
+25 -1
View File
@@ -170,6 +170,7 @@ export const AppContainer = (props: AppContainerProps) => {
null,
);
const [copyModeEnabled, setCopyModeEnabled] = useState(false);
const [pendingRestorePrompt, setPendingRestorePrompt] = useState(false);
const [shellModeActive, setShellModeActive] = useState(false);
const [modelSwitchedFromQuotaError, setModelSwitchedFromQuotaError] =
@@ -666,9 +667,32 @@ Logging in with Google... Please restart Gemini CLI to continue.
);
const onCancelSubmit = useCallback((shouldRestorePrompt?: boolean) => {
cancelHandlerRef.current(shouldRestorePrompt);
if (shouldRestorePrompt) {
setPendingRestorePrompt(true);
} else {
setPendingRestorePrompt(false);
cancelHandlerRef.current(false);
}
}, []);
useEffect(() => {
if (pendingRestorePrompt) {
const lastHistoryUserMsg = historyManager.history.findLast(
(h) => h.type === 'user',
);
const lastUserMsg = userMessages.at(-1);
if (
!lastHistoryUserMsg ||
(typeof lastHistoryUserMsg.text === 'string' &&
lastHistoryUserMsg.text === lastUserMsg)
) {
cancelHandlerRef.current(true);
setPendingRestorePrompt(false);
}
}
}, [pendingRestorePrompt, userMessages, historyManager.history]);
const {
streamingState,
submitQuery,