mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(app): keep automatic queue drain paused after failed startup settings until dismissed
This commit is contained in:
@@ -26,6 +26,7 @@ import { useProvidersSnapshot } from "@/hooks/use-providers-snapshot";
|
||||
import { useDraftProviderOptions } from "@/hooks/use-draft-provider-options";
|
||||
import {
|
||||
clearStagedProviderSwitch,
|
||||
dismissRetainedProviderSwitchEditFailure,
|
||||
isStagedProviderSwitchInFlight,
|
||||
type StagedProviderSwitch,
|
||||
useStagedProviderSwitch,
|
||||
@@ -1320,6 +1321,7 @@ export const AgentControls = memo(function AgentControls({
|
||||
}
|
||||
try {
|
||||
await client.setAgentModel(agentId, modelId, { expectedProvider: agentProvider });
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, agentId);
|
||||
await updatePreferences((current) =>
|
||||
mergeProviderPreferences({
|
||||
preferences: current,
|
||||
@@ -1332,7 +1334,7 @@ export const AgentControls = memo(function AgentControls({
|
||||
toast.error(toErrorMessage(error));
|
||||
}
|
||||
},
|
||||
[agentId, agentProvider, client, toast, updatePreferences],
|
||||
[agentId, agentProvider, client, serverId, toast, updatePreferences],
|
||||
);
|
||||
|
||||
const handleSelectModel = useCallback(
|
||||
@@ -1515,7 +1517,11 @@ export const AgentControls = memo(function AgentControls({
|
||||
}
|
||||
void client
|
||||
.setAgentThinkingOption(agentId, thinkingOptionId, { expectedProvider: agentProvider })
|
||||
.then((notice) => showProviderNoticeToast(toast, notice))
|
||||
.then((notice) => {
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, agentId);
|
||||
showProviderNoticeToast(toast, notice);
|
||||
return undefined;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn("[AgentControls] setAgentThinkingOption failed", error);
|
||||
toast.error(toErrorMessage(error));
|
||||
@@ -1561,6 +1567,10 @@ export const AgentControls = memo(function AgentControls({
|
||||
});
|
||||
void client
|
||||
.setAgentOptions(agentId, { [key]: value }, { expectedProvider: agentProvider })
|
||||
.then(() => {
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, agentId);
|
||||
return undefined;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn("[AgentControls] setAgentOptions failed", error);
|
||||
toast.error(toErrorMessage(error));
|
||||
|
||||
@@ -13,6 +13,7 @@ import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
beginStagedProviderSwitch,
|
||||
clearStagedProviderSwitch,
|
||||
dismissRetainedProviderSwitchEditFailure,
|
||||
endStagedProviderSwitch,
|
||||
getStagedProviderSwitch,
|
||||
hasRetainedProviderSwitchEditFailure,
|
||||
@@ -1780,6 +1781,9 @@ function ComposerContentImpl({
|
||||
const stagedProviderSwitch =
|
||||
pendingSwitch && pendingSwitch.provider !== liveProvider ? pendingSwitch : null;
|
||||
useSessionStore.getState().setQueuedSendError(serverId, targetAgentId, null);
|
||||
if (!stagedProviderSwitch) {
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, targetAgentId);
|
||||
}
|
||||
if (stagedProviderSwitch) {
|
||||
beginStagedProviderSwitch(serverId, targetAgentId);
|
||||
}
|
||||
@@ -2182,6 +2186,7 @@ function ComposerContentImpl({
|
||||
});
|
||||
if (!result) return;
|
||||
useSessionStore.getState().setQueuedSendError(serverId, agentId, null);
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, agentId);
|
||||
replaceUserInput(result.text);
|
||||
setSelectedAttachments(result.attachments);
|
||||
},
|
||||
@@ -2192,6 +2197,7 @@ function ComposerContentImpl({
|
||||
async (id: string) => {
|
||||
if (!sendAgentMessageRef.current && !onSubmitMessageRef.current) return;
|
||||
useSessionStore.getState().setQueuedSendError(serverId, agentId, null);
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, agentId);
|
||||
// Reuse the regular send path; server-side send atomically interrupts any active run.
|
||||
const result = await sendQueuedComposerMessageNow({
|
||||
agentId,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export {
|
||||
beginStagedProviderSwitch,
|
||||
clearStagedProviderSwitch,
|
||||
dismissRetainedProviderSwitchEditFailure,
|
||||
endStagedProviderSwitch,
|
||||
getStagedProviderSwitch,
|
||||
hasRetainedProviderSwitchEditFailure,
|
||||
|
||||
@@ -14,7 +14,11 @@ import { HostRuntimeStore } from "@/runtime/host-runtime";
|
||||
import { useSessionStore } from "@/stores/session-store";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { ProviderSwitchItem, StreamItem, UserMessageItem } from "@/types/stream";
|
||||
import { getStagedProviderSwitch, useStagedProviderSwitchStore } from "./index";
|
||||
import {
|
||||
dismissRetainedProviderSwitchEditFailure,
|
||||
getStagedProviderSwitch,
|
||||
useStagedProviderSwitchStore,
|
||||
} from "./index";
|
||||
|
||||
function createInMemoryRowStore(): ReplicaRowStore {
|
||||
const rows = new Map<string, ReplicaRow>();
|
||||
@@ -1064,12 +1068,28 @@ describe("app provider switching integration", () => {
|
||||
expect(getStagedProviderSwitch(serverId, "agent-1")?.providerOptions).toEqual({
|
||||
plan_mode: true,
|
||||
});
|
||||
// M4 MUST NOT have drained after settings rejection!
|
||||
// M4 MUST NOT have drained after settings rejection, AND later drain callbacks (turn completion /
|
||||
// reconnect / timeline sync) MUST keep automatic sending paused and preserve the error & draft!
|
||||
runtime.drainQueuedAgentMessage(serverId, "agent-1");
|
||||
await new Promise((resolve) => setTimeout(resolve, 25));
|
||||
expect(useSessionStore.getState().sessions[serverId]?.queuedSendErrors.get("agent-1")).toBe(
|
||||
"Plan mode rejected by provider",
|
||||
);
|
||||
expect(getStagedProviderSwitch(serverId, "agent-1")?.providerOptions).toEqual({
|
||||
plan_mode: true,
|
||||
});
|
||||
expect(callOrder.some((entry) => entry.startsWith("send:"))).toBe(false);
|
||||
expect(useSessionStore.getState().sessions[serverId]?.queuedMessages.get("agent-1")).toEqual([
|
||||
{ id: "m4", text: "Must stay queued", attachments: [] },
|
||||
]);
|
||||
|
||||
// Once the user explicitly dismisses or re-applies the failed settings, automatic drain resumes.
|
||||
dismissRetainedProviderSwitchEditFailure(serverId, "agent-1");
|
||||
runtime.drainQueuedAgentMessage(serverId, "agent-1");
|
||||
await vi.waitFor(() => {
|
||||
expect(callOrder).toContain("send:Must stay queued");
|
||||
});
|
||||
|
||||
sessionStore.clearSession(serverId);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -212,6 +212,11 @@ export function hasRetainedProviderSwitchEditFailure(serverId: string, agentId:
|
||||
.retainedOnEditFailureByKey.has(stagedKey(serverId, agentId));
|
||||
}
|
||||
|
||||
export function dismissRetainedProviderSwitchEditFailure(serverId: string, agentId: string): void {
|
||||
if (!hasRetainedProviderSwitchEditFailure(serverId, agentId)) return;
|
||||
useStagedProviderSwitchStore.getState().clear(serverId, agentId);
|
||||
}
|
||||
|
||||
export function settleStagedProviderSwitch(
|
||||
serverId: string,
|
||||
agentId: string,
|
||||
|
||||
@@ -87,6 +87,7 @@ import {
|
||||
beginStagedProviderSwitch,
|
||||
endStagedProviderSwitch,
|
||||
getStagedProviderSwitch,
|
||||
hasRetainedProviderSwitchEditFailure,
|
||||
settleCommittedProviderSwitch,
|
||||
} from "@/composer/provider-switch";
|
||||
import { createMessageSubmissionWriter } from "@/composer/submission/writer";
|
||||
@@ -2891,6 +2892,9 @@ export class HostRuntimeStore {
|
||||
}
|
||||
|
||||
drainQueuedAgentMessage(serverId: string, agentId: string): void {
|
||||
if (hasRetainedProviderSwitchEditFailure(serverId, agentId)) {
|
||||
return;
|
||||
}
|
||||
const drainKey = `${serverId}:${agentId}`;
|
||||
if (this.queuedAgentDrainInFlight.has(drainKey)) {
|
||||
this.queuedAgentDrainPending.add(drainKey);
|
||||
|
||||
Reference in New Issue
Block a user