{"record":{"id":"65e803d790e72513","repo":"plandex-ai/plandex","slug":"error-getting-org-session-v","errorCode":null,"errorMessage":"error getting org session: %v","messagePattern":"error getting org session: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/account.go","lineNumber":100,"sourceCode":"\t\treturn fmt.Errorf(\"error resolving org: %v\", err)\n\t}\n\n\terr = setAuth(&shared.ClientAuth{\n\t\tClientAccount:        *selected,\n\t\tOrgId:                org.Id,\n\t\tOrgName:              org.Name,\n\t\tOrgIsTrial:           org.IsTrial,\n\t\tIntegratedModelsMode: org.IntegratedModelsMode,\n\t})\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error setting auth: %v\", err)\n\t}\n\n\t_, apiErr = apiClient.GetOrgSession()\n\n\tif apiErr != nil {\n\t\treturn fmt.Errorf(\"error getting org session: %v\", apiErr.Msg)\n\t}\n\n\tfmt.Printf(\"✅ Signed in as %s | Org: %s\\n\", color.New(color.Bold, term.ColorHiGreen).Sprintf(\"<%s> %s\", Current.UserName, Current.Email), color.New(term.ColorHiCyan).Sprint(Current.OrgName))\n\tfmt.Println()\n\n\tif !term.IsRepl {\n\t\tterm.PrintCmds(\"\", \"\")\n\t}\n\n\treturn nil\n}\n\nfunc SignInWithCode(code, host string) error {\n\tterm.StartSpinner(\"\")\n\tres, apiErr := apiClient.SignIn(shared.SignInRequest{\n\t\tPin:          code,\n\t\tIsSignInCode: true,\n\t}, host)","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/account.go#L82-L118","documentation":"After auth is set locally, SelectOrSignInOrCreate calls apiClient.GetOrgSession() to validate that the client has an active org-scoped session on the server. If the server returns an error, it is wrapped as `error getting org session: %v`. Although auth was just saved, this confirms the org session is actually usable; failure here means subsequent org-scoped calls would fail.","triggerScenarios":"apiClient.GetOrgSession() returns a non-nil ApiErr — the freshly set org token is rejected (401/403), the org session expired between setAuth and the call, the server is unreachable, or the user lacks access to the resolved org.","commonSituations":"Server clock skew invalidating freshly issued tokens; user removed from the org moments after selection; reverse proxy/auth middleware rejecting the session; server restarted with rotated session keys.","solutions":["Re-run sign-in (`plandex signIn`); if it recurs immediately, sign out fully, clear stored auth, and sign in again.","Verify server reachability and that the server time/clock is correct (large skew breaks session validation).","Confirm your membership in the selected org hasn't been revoked; re-accept the invite if needed.","Inspect the embedded apiErr.Msg to distinguish 401/403 (auth/permission) from 5xx/network causes and act accordingly."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if !serverReachable(serverURL) {\n    return fmt.Errorf(\"cannot reach plandex server; fix connectivity before validating org session\")\n}\nif clockSkewSeconds() > 60 {\n    return fmt.Errorf(\"local clock skewed %ds; sync NTP to avoid session rejection\", clockSkewSeconds())\n}","typeGuard":null,"tryCatchPattern":"if err := auth.SelectOrSignInOrCreate(); err != nil {\n    if strings.Contains(err.Error(), \"error getting org session\") {\n        if isUnauthorized(err) {\n            clearStoredAuth()\n            return auth.SelectOrSignInOrCreate() // full re-auth on 401\n        }\n        return retryWithBackoff(auth.SelectOrSignInOrCreate, 3) // transient\n    }\n    return err\n}","preventionTips":["Keep server and client clocks synced (NTP) — skew invalidates fresh sessions.","Treat immediate 401 after sign-in as a signal to fully clear and redo authentication.","Confirm org membership hasn't been revoked when sessions fail right after selection.","Retry transient 5xx/network failures with backoff instead of failing hard."],"tags":["network","auth","session","orgs"],"backgroundTag":"session-expired","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}