{"record":{"id":"38a25b28688d1208","repo":"block/buzz","slug":"bestie-is-unavailable-outside-a-community","errorCode":null,"errorMessage":"Bestie is unavailable outside a community","messagePattern":"Bestie is unavailable outside a community","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"desktop/src/protectedFeatures/bestie/useBestie.ts","lineNumber":100,"sourceCode":"  );\n  const presenceQuery = usePresenceQuery(\n    assignedAgent ? [assignedAgent.pubkey] : [],\n    { enabled: assignedAgent !== null },\n  );\n  const presenceStatus = assignedAgent\n    ? (presenceQuery.data?.[assignedAgent.pubkey.toLowerCase()] ?? \"offline\")\n    : undefined;\n  const runtime = assignedAgent\n    ? findManagedAgentRuntime(\n        runtimesQuery.data ?? [],\n        assignedAgent.pubkey,\n        relayUrl,\n      )\n    : undefined;\n\n  const assignMutation = useMutation({\n    mutationFn: (agent: ManagedAgent) => {\n      if (!scope) throw new Error(\"Bestie is unavailable outside a community\");\n      return assignBestie(agent.pubkey, scope);\n    },\n    onSuccess: (assignment) => {\n      queryClient.setQueryData(queryKey, assignment);\n    },\n  });\n  const clearMutation = useMutation({\n    mutationFn: () => {\n      if (!scope) throw new Error(\"Bestie is unavailable outside a community\");\n      return clearBestieAssignment(scope);\n    },\n    onSuccess: () => {\n      queryClient.setQueryData(queryKey, null);\n    },\n  });\n  const resolveMutation = useMutation({\n    mutationFn: () => {\n      if (!scope) throw new Error(\"Bestie is unavailable outside a community\");","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/desktop/src/protectedFeatures/bestie/useBestie.ts#L82-L118","documentation":"useBestie's assignMutation guards its mutationFn: Bestie (the auto-assist agent) can only be assigned within a community scope. When `scope` is undefined — no community/relay context is active — the mutation throws 'Bestie is unavailable outside a community' instead of calling assignBestie.","triggerScenarios":"Invoking assignMutation.mutate(agent) while the app has no active community scope (scope is undefined), e.g. before a community is selected or when the community context failed to initialize.","commonSituations":"Rendering the Bestie assignment UI outside a community view; app launched without a configured relay/community; community switch in flight so scope is temporarily undefined when the mutation fires.","solutions":["Ensure a community is active before rendering Bestie controls (gate the UI on scope being defined).","Disable the assign button while `scope` is undefined and show the unavailability message instead.","Wait for community initialization (relay URL + scope resolution) to complete, then retry the assignment.","If scope should exist but doesn't, fix the community context provider wiring upstream of useBestie."],"exampleFix":"// before\nassignMutation.mutate(agent);\n\n// after\nif (!scope) {\n  toast.error(\"Bestie is unavailable outside a community\");\n  return;\n}\nassignMutation.mutate(agent);","handlingStrategy":"validation","validationCode":"if (!scope) {\n  toast.error(\"Bestie is unavailable outside a community\");\n  return;\n}\nassignMutation.mutate(agent);","typeGuard":"function hasCommunityScope(s: CommunityScope | undefined): s is CommunityScope {\n  return s !== undefined;\n}","tryCatchPattern":"try {\n  await assignMutation.mutateAsync(agent);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"outside a community\")) {\n    toast.error(\"Select a community before assigning Bestie.\");\n    return;\n  }\n  throw e;\n}","preventionTips":["Render Bestie UI only inside an active community route/context.","Disable assignment controls until scope is resolved.","Wait for community initialization to settle before firing mutations on mount.","Fail visibly, never silently, when scope is missing."],"tags":["bestie","community-scope","validation","agents"],"backgroundTag":"missing-community-scope","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"}