{"record":{"id":"ad939e83e509155e","repo":"different-ai/openwork","slug":"organization-not-found-ad939e","errorCode":null,"errorMessage":"Organization not found.","messagePattern":"Organization not found\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx","lineNumber":107,"sourceCode":"  const [orgSettingsCompletion, setOrgSettingsCompletion] = useState<OrgSettingsCompletion | null>(null);\n  const pendingReauthMutationsRef = useRef<PendingReauthMutation[]>([]);\n  const pathnameRef = useRef(pathname);\n  const [reauthDialogOpen, setReauthDialogOpen] = useState(false);\n\n  const activeOrg = useMemo(\n    () =>\n      orgDirectory.find((entry) => entry.isActive) ??\n      orgDirectory[0] ??\n      null,\n    [orgDirectory],\n  );\n\n  const activeOrgId = activeOrg?.id ?? orgContext?.organization.id ?? null;\n  const isSingleOrgMode = runtimeConfigLoaded && runtimeConfig.orgMode === \"single_org\";\n\n  function ensureActiveOrganizationSelected() {\n    if (!activeOrgId) {\n      throw new Error(\"Organization not found.\");\n    }\n  }\n\n  function getCurrentAccess() {\n    return getOrgAccessFlags(\n      orgContext?.currentMember.role ?? \"member\",\n      orgContext?.currentMember.isOwner ?? false,\n      orgContext?.roles,\n    );\n  }\n\n  function ensureCanManageSettings() {\n    if (!getCurrentAccess().canManageSettings) {\n      throw new Error(\"Only workspace owners and super-admins can change settings.\");\n    }\n  }\n\n  function ensureCanDeleteOrganization() {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx#L89-L125","documentation":"ensureActiveOrganizationSelected in org-dashboard-provider.tsx guards all org mutations (settings update, delete, invites, seat checkout, invitation cancel, role change). It throws 'Organization not found.' when neither the active organization nor the org context provides an id, meaning the provider cannot determine which organization to act on.","triggerScenarios":"Calling any wrapped mutation before the runtime config has loaded or before orgContext resolves (activeOrgId null), e.g. invoking updateOrganizationSettings or inviteMember during initial mount, after a failed /me fetch, or in an org-less account state.","commonSituations":"Autosave or a scheduled action firing before org context hydration, a user with no organization membership, org context fetch failing silently (network/auth), single_org mode with runtimeConfig not yet loaded, or stale UI rendered before context load.","solutions":["Wait for runtimeConfigLoaded and orgContext to resolve before enabling mutation UI (disable buttons until ready).","Check why the org context fetch failed (auth, network) and reload the dashboard.","Verify the account actually belongs to an organization; create/join one if not.","Guard call sites with an activeOrgId check instead of calling the mutation directly.","Refresh the page to re-run the org context bootstrap."],"exampleFix":"// before\nawait updateOrganizationSettings(orgId, settings);\n// after\nif (!activeOrgId) return; // or show org-picker\nawait updateOrganizationSettings(orgId, settings);","handlingStrategy":"validation","validationCode":"if (!activeOrgId) { showToast(\"Select an organization first\"); return; }\nawait mutation(...);","typeGuard":"null","tryCatchPattern":"try {\n  await updateOrganizationSettings(orgId, settings);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Organization not found.\") {\n    await refreshOrgContext(); // re-bootstrap, then retry or prompt org picker\n  } else throw e;\n}","preventionTips":["Gate mutation UI on runtimeConfigLoaded && activeOrgId != null.","Never fire org mutations from effects before context hydration completes.","Handle failed org-context fetches visibly instead of silently leaving activeOrgId null.","Show an org picker when the user has no active organization."],"tags":["guard","state","organization","race-condition"],"backgroundTag":"missing-active-organization","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}