fix(app): keep agent visible during history handoff

Running and terminal updates could clear create continuity before the initial authoritative timeline arrived, leaving a streaming agent behind the loading screen. End the handoff only when authoritative history is applied.
This commit is contained in:
Mohamed Boudra
2026-07-27 18:18:21 +02:00
parent 5334008e44
commit 5794ec6c27
3 changed files with 1 additions and 29 deletions

View File

@@ -214,14 +214,6 @@ export function useDraftAgentCreateFlow<TDraftAgent, TCreateResult>({
}),
);
markPendingCreateLifecycle({ draftId, lifecycle: "sent" });
if (
useSessionStore.getState().sessions[pendingServerId]?.agents.get(createResult.agentId)
?.status === "running"
) {
useCreateFlowStore
.getState()
.clearByAgent({ serverId: pendingServerId, agentId: createResult.agentId });
}
}
await onCreateSuccess({ result: createResult.result, attempt });

View File

@@ -327,12 +327,10 @@ function finalizeTimelineApplication(input: {
}
if (shouldMarkAuthoritativeHistoryApplied) {
setAgentAuthoritativeHistoryApplied(serverId, agentId, true);
useCreateFlowStore.getState().clearByAgent({ serverId, agentId });
markAgentHistorySynchronized(serverId, agentId);
const session = useSessionStore.getState().sessions[serverId];
const agent = session?.agents.get(agentId) ?? session?.agentDetails.get(agentId);
if (agent?.status === "running") {
useCreateFlowStore.getState().clearByAgent({ serverId, agentId });
}
if (agent && agent.status !== "running") {
getHostRuntimeStore().drainQueuedAgentMessage(serverId, agentId);
}
@@ -815,14 +813,6 @@ function SessionProviderInternal({ children, serverId, client }: SessionProvider
) {
voiceRuntime?.onTurnEvent(serverId, agentId, event.type);
}
if (
event.type === "turn_completed" ||
event.type === "turn_failed" ||
event.type === "turn_canceled"
) {
useCreateFlowStore.getState().clearByAgent({ serverId, agentId });
}
agentStreamReducerQueue.enqueue(agentId, {
event: streamEvent,
seq,

View File

@@ -9,7 +9,6 @@ import { acceptAgentDirectoryUpdate } from "@/utils/agent-directory-update-polic
import { buildDraftStoreKey } from "@/stores/draft-keys";
import { useDraftStore } from "@/stores/draft-store";
import { getInitDeferred, getInitKey, rejectInitDeferred } from "@/utils/agent-initialization";
import { useCreateFlowStore } from "@/stores/create-flow-store";
type AgentDirectoryFetchEntry = FetchAgentsEntry;
export type AgentDirectoryDelta = Extract<
@@ -53,9 +52,6 @@ function upsertAgentDirectoryReplica(
previousAgent?.projectPlacement,
};
const acceptedAgent = upsertAgentReplica(serverId, agent);
if (acceptedAgent.status === "running") {
useCreateFlowStore.getState().clearByAgent({ serverId, agentId: acceptedAgent.id });
}
if (acceptedAgent.archivedAt) {
clearArchiveAgentPending({ queryClient, serverId, agentId: acceptedAgent.id });
}
@@ -178,12 +174,6 @@ export function replaceFetchedAgentDirectory(input: {
const store = useSessionStore.getState();
for (const agent of fetchedAgents.values()) {
if (agent.status === "running") {
useCreateFlowStore.getState().clearByAgent({
serverId: input.serverId,
agentId: agent.id,
});
}
if (agent.archivedAt) {
clearArchiveAgentPending({ queryClient, serverId: input.serverId, agentId: agent.id });
}