Fix archived agent reload failures

Unarchive provider storage before clearing Paseo's archived flag so failed native restores keep the snapshot archived. Keep initial history sync errors visible instead of falling back to the loading state.
This commit is contained in:
Mohamed Boudra
2026-06-20 21:33:25 +07:00
parent 27ecb3a7a9
commit 25252d1b86
9 changed files with 379 additions and 16 deletions
@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import type { AgentScreenMissingState } from "@/hooks/use-agent-screen-state-machine";
import {
clearHistorySyncErrorAfterSuccessfulSync,
reconcileMissingAgentStateWithPresentAgent,
} from "./agent-panel-load-state";
describe("reconcileMissingAgentStateWithPresentAgent", () => {
it("clears lookup-only states once the agent record is present", () => {
expect(reconcileMissingAgentStateWithPresentAgent({ kind: "resolving" })).toEqual({
kind: "idle",
});
expect(
reconcileMissingAgentStateWithPresentAgent({
kind: "not_found",
message: "Agent not found: agent-1",
}),
).toEqual({ kind: "idle" });
});
it("preserves history sync errors while the agent record is present", () => {
const state: AgentScreenMissingState = {
kind: "error",
message: "Failed to get logs: session is archived",
};
expect(reconcileMissingAgentStateWithPresentAgent(state)).toBe(state);
});
});
describe("clearHistorySyncErrorAfterSuccessfulSync", () => {
it("clears a sync error after a later successful refresh", () => {
expect(
clearHistorySyncErrorAfterSuccessfulSync({
kind: "error",
message: "Failed to get logs: session is archived",
}),
).toEqual({ kind: "idle" });
});
it("leaves non-error states alone", () => {
const state: AgentScreenMissingState = { kind: "resolving" };
expect(clearHistorySyncErrorAfterSuccessfulSync(state)).toBe(state);
});
});
@@ -0,0 +1,19 @@
import type { AgentScreenMissingState } from "@/hooks/use-agent-screen-state-machine";
export function reconcileMissingAgentStateWithPresentAgent(
state: AgentScreenMissingState,
): AgentScreenMissingState {
if (state.kind === "resolving" || state.kind === "not_found") {
return { kind: "idle" };
}
return state;
}
export function clearHistorySyncErrorAfterSuccessfulSync(
state: AgentScreenMissingState,
): AgentScreenMissingState {
if (state.kind === "error") {
return { kind: "idle" };
}
return state;
}
+15 -5
View File
@@ -53,6 +53,10 @@ import {
import { useArchiveAgent } from "@/hooks/use-archive-agent";
import { useKeyboardShiftStyle } from "@/hooks/use-keyboard-shift-style";
import { useContainerWidthBelow } from "@/hooks/use-container-width";
import {
clearHistorySyncErrorAfterSuccessfulSync,
reconcileMissingAgentStateWithPresentAgent,
} from "@/panels/agent-panel-load-state";
import { usePaneContext, usePaneFocus } from "@/panels/pane-context";
import type { PanelDescriptor, PanelRegistration } from "@/panels/panel-registry";
import { RenderProfile } from "@/utils/render-profiler";
@@ -847,9 +851,15 @@ function ChatAgentContent({
if (!agentId) {
return;
}
ensureAgentIsInitialized(agentId).catch((error) => {
handleHistorySyncFailure({ origin, error });
});
ensureAgentIsInitialized(agentId)
.then(() => {
setMissingAgentState(clearHistorySyncErrorAfterSuccessfulSync);
return undefined;
})
.catch((error) => {
handleHistorySyncFailure({ origin, error });
return undefined;
});
},
[agentId, ensureAgentIsInitialized, handleHistorySyncFailure],
);
@@ -1011,8 +1021,8 @@ function ChatAgentContent({
return;
}
if (agentState.id) {
if (missingAgentState.kind !== "idle") {
setMissingAgentState({ kind: "idle" });
if (missingAgentState.kind === "resolving" || missingAgentState.kind === "not_found") {
setMissingAgentState(reconcileMissingAgentStateWithPresentAgent);
}
return;
}