feat(app): restore recent chat while reconnecting (#2206)

Keep a small non-authoritative view of the last focused chat so the app can paint it before the daemon finishes revalidation. Bound persistence to one focused agent per host and evict whole host entries to limit storage and serialization work.
This commit is contained in:
Mohamed Boudra
2026-07-19 03:08:46 +08:00
committed by GitHub
parent 2185779d6c
commit 5ea311f243
9 changed files with 875 additions and 20 deletions
+12 -5
View File
@@ -498,6 +498,13 @@ function AgentPanelContent({
const runtimeIsConnected = useHostRuntimeIsConnected(runtimeServerId);
const runtimeConnectionStatus = useHostRuntimeConnectionStatus(runtimeServerId);
const runtimeLastError = useHostRuntimeLastError(runtimeServerId);
const hasCachedAgent = useSessionStore((state) => {
if (!resolvedServerId || !resolvedAgentId) return false;
const session = state.sessions[resolvedServerId];
return Boolean(
session?.agents.has(resolvedAgentId) || session?.agentDetails.has(resolvedAgentId),
);
});
const connectionServerId = resolvedServerId ?? null;
const daemon = connectionServerId
@@ -512,7 +519,7 @@ function AgentPanelContent({
: runtimeConnectionStatus;
const lastConnectionError = runtimeLastError;
if (!resolvedServerId || !runtimeClient) {
if (!resolvedServerId || (!runtimeClient && !hasCachedAgent)) {
return (
<AgentSessionUnavailableState
serverLabel={serverLabel}
@@ -549,7 +556,7 @@ function AgentPanelBody({
serverId: string;
agentId?: string;
isPaneFocused: boolean;
client: NonNullable<ReturnType<typeof useHostRuntimeClient>>;
client: ReturnType<typeof useHostRuntimeClient>;
isConnected: boolean;
connectionStatus: HostRuntimeConnectionStatus;
onOpenWorkspaceFile?: (request: WorkspaceFileOpenRequest) => void;
@@ -593,7 +600,7 @@ function AgentPanelBody({
}
return;
}
if (!isConnected || !hasSession) {
if (!client || !isConnected || !hasSession) {
return;
}
if (lookupState.tag === "loading" || lookupState.tag === "not_found") {
@@ -710,7 +717,7 @@ function ChatAgentContent({
serverId: string;
agentId?: string;
isPaneFocused: boolean;
client: NonNullable<ReturnType<typeof useHostRuntimeClient>>;
client: ReturnType<typeof useHostRuntimeClient>;
isConnected: boolean;
connectionStatus: HostRuntimeConnectionStatus;
onOpenWorkspaceFile?: (request: WorkspaceFileOpenRequest) => void;
@@ -949,7 +956,7 @@ function ChatAgentContent({
}
return;
}
if (!isPaneVisible || !isConnected || !hasSession) {
if (!client || !isPaneVisible || !isConnected || !hasSession) {
return;
}
if (