fix: only confirm archive when agent is running

Skip the confirmation dialog when archiving idle agents — archive
immediately. Show a warning that the agent will be stopped only when
it is running or initializing.
This commit is contained in:
Mohamed Boudra
2026-04-06 11:04:05 +07:00
parent f75e28a77f
commit 5d1b3383d7
2 changed files with 35 additions and 13 deletions
+19 -3
View File
@@ -261,9 +261,23 @@ export function AgentList({
[isActionSheetVisible, onAgentSelect], [isActionSheetVisible, onAgentSelect],
); );
const handleAgentLongPress = useCallback((agent: AggregatedAgent) => { const handleAgentLongPress = useCallback(
(agent: AggregatedAgent) => {
const isRunning = agent.status === "running" || agent.status === "initializing";
if (isRunning) {
setActionAgent(agent); setActionAgent(agent);
}, []); return;
}
const client = useSessionStore.getState().sessions[agent.serverId]?.client ?? null;
if (!client) {
setActionAgent(agent);
return;
}
void client.archiveAgent(agent.id);
},
[],
);
const handleCloseActionSheet = useCallback(() => { const handleCloseActionSheet = useCallback(() => {
setActionAgent(null); setActionAgent(null);
@@ -365,7 +379,9 @@ export function AgentList({
> >
<View style={styles.sheetHandle} /> <View style={styles.sheetHandle} />
<Text style={styles.sheetTitle}> <Text style={styles.sheetTitle}>
{isActionDaemonUnavailable ? "Host offline" : "Archive this session?"} {isActionDaemonUnavailable
? "Host offline"
: "This agent is still running. Archiving it will stop the agent."}
</Text> </Text>
<View style={styles.sheetButtonRow}> <View style={styles.sheetButtonRow}>
<Pressable <Pressable
@@ -1284,9 +1284,14 @@ function WorkspaceScreenContent({ serverId, workspaceId }: WorkspaceScreenProps)
return; return;
} }
const agent =
useSessionStore.getState().sessions[normalizedServerId]?.agents?.get(agentId) ?? null;
const isRunning = agent?.status === "running" || agent?.status === "initializing";
if (isRunning) {
const confirmed = await confirmDialog({ const confirmed = await confirmDialog({
title: "Archive agent?", title: "Archive running agent?",
message: "This closes the tab and archives the agent.", message: "This agent is still running. Archiving it will stop the agent and close the tab.",
confirmLabel: "Archive", confirmLabel: "Archive",
cancelLabel: "Cancel", cancelLabel: "Cancel",
destructive: true, destructive: true,
@@ -1294,6 +1299,7 @@ function WorkspaceScreenContent({ serverId, workspaceId }: WorkspaceScreenProps)
if (!confirmed) { if (!confirmed) {
return; return;
} }
}
setHoveredTabKey((current) => (current === tabId ? null : current)); setHoveredTabKey((current) => (current === tabId ? null : current));
setHoveredCloseTabKey((current) => (current === tabId ? null : current)); setHoveredCloseTabKey((current) => (current === tabId ? null : current));