{"record":{"id":"d89a67e411155521","repo":"block/buzz","slug":"this-agent-is-present-on-the-relay-starting-anoth-d89a67","errorCode":null,"errorMessage":"This agent is present on the relay. Starting another instance is unavailable.","messagePattern":"This agent is present on the relay\\. Starting another instance is unavailable\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"desktop/src/features/profile/ui/useAgentLifecycleActions.ts","lineNumber":53,"sourceCode":"    if (!managedAgent) return;\n\n    try {\n      if (isManagedAgentActive(managedAgent)) {\n        const result = await stopManagedAgentWithRules({\n          agent: managedAgent,\n          channels: channels ?? [],\n          relayAgents: relayAgents ?? [],\n          stopManagedAgent,\n        });\n        if (managedAgent.backend.type === \"local\") {\n          clearActiveTurnsForAgentOnStop(managedAgent.pubkey);\n        }\n        toast.success(result.noticeMessage ?? `Stopped ${managedAgent.name}.`);\n        return;\n      }\n\n      const blockReason = agentPresenceStartBlockReason(false, availability);\n      if (blockReason) throw new Error(blockReason);\n      await startManagedAgentWithRules({\n        agent: managedAgent,\n        startManagedAgent,\n      });\n      toast.success(\n        managedAgent.backend.type === \"provider\"\n          ? `Deploying ${managedAgent.name}.`\n          : `Started ${managedAgent.name}.`,\n      );\n    } catch (error) {\n      toast.error(\n        error instanceof Error ? error.message : \"Agent action failed.\",\n      );\n    }\n  }, [\n    availability,\n    channels,\n    managedAgent,","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/desktop/src/features/profile/ui/useAgentLifecycleActions.ts#L35-L71","documentation":"In useAgentLifecycleActions' primary-action path, after a stop branch the code re-checks agentPresenceStartBlockReason with lifecycleActive=false. If relay presence still reports the agent online/away, starting (or stop-then-restart) is refused with the same presence-block error: the relay already sees this identity, so a new instance is disallowed.","triggerScenarios":"Clicking the agent's primary Start action (or restart whose stop path ran) while the presence lookup returns 'online' or 'away' for the agent's pubkey — e.g. another device is running it or presence hasn't cleared after a stop.","commonSituations":"Restarting an agent whose stop succeeded locally but whose relay presence hasn't flipped offline yet; starting an agent deployed on another machine; degraded connection serving a stale presence snapshot.","solutions":["Wait for presence to report offline after stopping (presence invalidates asynchronously) and retry the action.","Locate and stop the other running instance (other device/session) before starting locally.","If the connection degraded, reconnect so resolveAgentAvailability returns fresh data instead of stale online.","Confirm the local record is inactive and refresh the agent inventory if state looks inconsistent."],"exampleFix":"// before\nconst blockReason = agentPresenceStartBlockReason(false, availability);\nif (blockReason) throw new Error(blockReason);\nawait startManagedAgentWithRules({ agent: managedAgent, startManagedAgent });\n\n// after\nconst blockReason = agentPresenceStartBlockReason(false, availability);\nif (blockReason) {\n  toast.error(blockReason);\n  return; // or: await refreshPresence([managedAgent.pubkey]) then re-check once\n}\nawait startManagedAgentWithRules({ agent: managedAgent, startManagedAgent });","handlingStrategy":"validation","validationCode":"const blockReason = agentPresenceStartBlockReason(false, availability);\nif (blockReason) { toast.error(blockReason); return; }","typeGuard":"const primaryActionAllowed = (a: ManagedAgent): boolean =>\n  agentPresenceStartBlockReason(false, availabilityFor(a.pubkey)) === undefined;","tryCatchPattern":"try {\n  await handleAgentPrimaryAction(managedAgent);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"present on the relay\")) {\n    toast.info(\"Agent is running elsewhere — stop that instance first.\");\n    return;\n  }\n  throw e;\n}","preventionTips":["Await presence invalidation after stop before enabling start/restart controls.","Disable profile lifecycle buttons while presence is online/away.","Reconnect promptly when degraded so availability reflects live relay state.","Never interpret local 'inactive' records as proof another instance isn't running."],"tags":["presence","agents","lifecycle","profile"],"backgroundTag":"agent-already-present-on-relay","analyzedSha":"dad5a33865fc81a2e55b3b60746632f615ec1e3a","analyzedAt":"2026-09-05T18:13:50.666Z","contentChangedAt":"2026-09-05T18:13:50.666Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}