mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-07-09 17:19:02 +00:00
fix(web-shell): suppress stale pending prompt refresh errors (#6352)
Co-authored-by: ytahdn <ytahdn@gmail.com>
This commit is contained in:
parent
edc0555ed1
commit
fa6e0f942c
1 changed files with 17 additions and 9 deletions
|
|
@ -52,6 +52,12 @@ interface UseQueuedPromptsArgs {
|
|||
|
||||
const MAX_COMPLETED_PROMPT_IDS = 100;
|
||||
|
||||
type RefreshPendingPromptsResult =
|
||||
| 'refreshed'
|
||||
| 'skipped'
|
||||
| 'superseded'
|
||||
| 'failed';
|
||||
|
||||
function areQueuedPromptsEqual(
|
||||
left: readonly QueuedPrompt[],
|
||||
right: readonly QueuedPrompt[],
|
||||
|
|
@ -221,26 +227,28 @@ export function useQueuedPrompts({
|
|||
);
|
||||
|
||||
const refreshPendingPrompts = useCallback(
|
||||
async (targetSessionId = sessionId): Promise<boolean> => {
|
||||
if (!connected || !targetSessionId) return false;
|
||||
if (latestSessionIdRef.current !== targetSessionId) return false;
|
||||
async (
|
||||
targetSessionId = sessionId,
|
||||
): Promise<RefreshPendingPromptsResult> => {
|
||||
if (!connected || !targetSessionId) return 'skipped';
|
||||
if (latestSessionIdRef.current !== targetSessionId) return 'skipped';
|
||||
const requestSeq = ++refreshRequestSeqRef.current;
|
||||
try {
|
||||
const result = await sessionActions.getPendingPrompts({
|
||||
sessionId: targetSessionId,
|
||||
});
|
||||
if (requestSeq !== refreshRequestSeqRef.current) return false;
|
||||
if (latestSessionIdRef.current !== targetSessionId) return false;
|
||||
if (requestSeq !== refreshRequestSeqRef.current) return 'superseded';
|
||||
if (latestSessionIdRef.current !== targetSessionId) return 'skipped';
|
||||
syncServerQueuedPrompts(
|
||||
result.pendingPrompts.filter(
|
||||
(p) => p.state === 'queued' || p.state === 'running',
|
||||
),
|
||||
targetSessionId,
|
||||
);
|
||||
return true;
|
||||
return 'refreshed';
|
||||
} catch (error) {
|
||||
console.warn('Failed to refresh pending prompts', error);
|
||||
return false;
|
||||
return 'failed';
|
||||
}
|
||||
},
|
||||
[connected, sessionActions, sessionId, syncServerQueuedPrompts],
|
||||
|
|
@ -595,7 +603,7 @@ export function useQueuedPrompts({
|
|||
return false;
|
||||
}
|
||||
completionCallbacksRef.current.delete(target.serverPromptId);
|
||||
if (!(await refreshPendingPrompts(targetSessionId))) {
|
||||
if ((await refreshPendingPrompts(targetSessionId)) === 'failed') {
|
||||
setQueuedPromptFlags(target.id, {
|
||||
isEditing: false,
|
||||
isRemoving: false,
|
||||
|
|
@ -612,7 +620,7 @@ export function useQueuedPrompts({
|
|||
isEditing: false,
|
||||
isRemoving: false,
|
||||
});
|
||||
if (!(await refreshPendingPrompts(targetSessionId))) {
|
||||
if ((await refreshPendingPrompts(targetSessionId)) !== 'refreshed') {
|
||||
restoreQueuedPrompts([target]);
|
||||
}
|
||||
reportError(error, fallback);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue