Skip to content

Commit f4bb2ed

Browse files
loganjLarry
andcommitted
fix(desktop): preserve availability freshness during agent deletion
Use the shared exact-key action-time reader for Agents and profile deletion, including channel-discovery awaits and unqueried persona siblings. Request shutdown for unknown availability before removing provider records; retain records on request failure and preserve established Offline and native local deletion behavior. Cover the production hook/IPC seams and profile confirmation journeys with cached Online, Offline and failed/disconnected evidence. Document request-only shutdown and existing cleanup limits. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <[email protected]>
1 parent b55423f commit f4bb2ed

11 files changed

Lines changed: 732 additions & 43 deletions

‎desktop/src/features/agents/AGENTS.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ with a TypeScript lookup table or an id comparison in a component.
205205
actions retain their separate routing. Current exact-key Online/Away presence
206206
suppresses Start for an inactive local record without granting Stop authority;
207207
list/profile/member startup guards must not interpret Offline as proof of safe
208-
startup. See
208+
startup. Deletion also consumes that same exact-key availability reader:
209+
unknown requests shutdown when a channel exists, request failure retains the
210+
record, and only established Offline keeps the intentional no-request path.
211+
Unqueried persona siblings are unknown. No presence state grants deletion or
212+
Stop authority; native local stop-before-remove remains independent. See
209213
[the availability contract](../../../../docs/agent-availability.md).
210214
14. **Thinking effort has two surfaces: a local-only WRITE control and a
211215
read-only two-facts DISPLAY.** The write control is `EffortPickerField`

‎desktop/src/features/agents/lib/managedAgentControlActions.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { sendChannelMessage } from "@/shared/api/tauri";
2-
import type {
3-
Channel,
4-
ManagedAgent,
5-
PresenceLookup,
6-
RelayAgent,
7-
} from "@/shared/api/types";
2+
import type { Channel, ManagedAgent, RelayAgent } from "@/shared/api/types";
3+
import type { AgentAvailabilityReader } from "./useAgentAvailability";
84
import { normalizePubkey } from "@/shared/lib/pubkey";
95

106
type DeleteManagedAgentInput = {
@@ -23,7 +19,7 @@ type ManagedAgentChannelContext = {
2319
};
2420

2521
type ManagedAgentActionContext = ManagedAgentChannelContext & {
26-
presenceLookup?: PresenceLookup | null;
22+
getAvailability: AgentAvailabilityReader;
2723
};
2824

2925
export type ManagedAgentActionResult = {
@@ -148,7 +144,7 @@ export async function deleteManagedAgentWithRules({
148144
channels,
149145
deleteManagedAgent,
150146
preferredChannelId,
151-
presenceLookup,
147+
getAvailability,
152148
relayAgents,
153149
skipRemoteDeleteConfirm = false,
154150
}: {
@@ -157,22 +153,27 @@ export async function deleteManagedAgentWithRules({
157153
skipRemoteDeleteConfirm?: boolean;
158154
} & ManagedAgentActionContext): Promise<ManagedAgentActionResult> {
159155
if (agent.backend.type === "provider" && agent.backendAgentId) {
160-
const presence = presenceLookup?.[normalizePubkey(agent.pubkey)];
156+
const availability = getAvailability(agent.pubkey);
161157
const channelId = resolveManagedAgentChannelId(agent, {
162158
channels,
163159
preferredChannelId,
164160
relayAgents,
165161
});
166162

167163
if (channelId) {
168-
if (presence === "online" || presence === "away") {
164+
// Only established Offline preserves the intentional no-request path.
165+
// Unknown is not evidence that shutdown can safely be skipped.
166+
if (availability !== "offline") {
169167
await sendChannelMessage(channelId, "!shutdown", undefined, undefined, [
170168
agent.pubkey,
171169
]);
172170

173171
if (!skipRemoteDeleteConfirm) {
174172
const confirmed = window.confirm(
175-
"Shutdown command sent, but the agent may still be running. " +
173+
(availability === undefined
174+
? "This agent’s availability is unknown. "
175+
: "") +
176+
"Shutdown requested, but the agent may still be running. " +
176177
"Deleting now removes the local record — the remote deployment " +
177178
"will be orphaned if shutdown hasn't completed. Continue?",
178179
);
@@ -195,7 +196,7 @@ export async function deleteManagedAgentWithRules({
195196
if (!skipRemoteDeleteConfirm) {
196197
const confirmed = window.confirm(
197198
"This agent is deployed but not in any channel. " +
198-
"Deleting will orphan the remote deployment (it will keep running). Continue?",
199+
"Deleting removes the local management record; the remote deployment may still be running. Continue?",
199200
);
200201
if (!confirmed) {
201202
return { cancelled: true };

0 commit comments

Comments
 (0)