plandex-ai/plandex · error

error getting org session: %v

Error message

error getting org session: %v

What it means

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.

Source

Thrown at app/cli/auth/account.go:100

		return fmt.Errorf("error resolving org: %v", err)
	}

	err = setAuth(&shared.ClientAuth{
		ClientAccount:        *selected,
		OrgId:                org.Id,
		OrgName:              org.Name,
		OrgIsTrial:           org.IsTrial,
		IntegratedModelsMode: org.IntegratedModelsMode,
	})

	if err != nil {
		return fmt.Errorf("error setting auth: %v", err)
	}

	_, apiErr = apiClient.GetOrgSession()

	if apiErr != nil {
		return fmt.Errorf("error getting org session: %v", apiErr.Msg)
	}

	fmt.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))
	fmt.Println()

	if !term.IsRepl {
		term.PrintCmds("", "")
	}

	return nil
}

func SignInWithCode(code, host string) error {
	term.StartSpinner("")
	res, apiErr := apiClient.SignIn(shared.SignInRequest{
		Pin:          code,
		IsSignInCode: true,
	}, host)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Re-run sign-in (`plandex signIn`); if it recurs immediately, sign out fully, clear stored auth, and sign in again.
  2. Verify server reachability and that the server time/clock is correct (large skew breaks session validation).
  3. Confirm your membership in the selected org hasn't been revoked; re-accept the invite if needed.
  4. Inspect the embedded apiErr.Msg to distinguish 401/403 (auth/permission) from 5xx/network causes and act accordingly.
Defensive patterns

Strategy: retry

Validate before calling

if !serverReachable(serverURL) {
    return fmt.Errorf("cannot reach plandex server; fix connectivity before validating org session")
}
if clockSkewSeconds() > 60 {
    return fmt.Errorf("local clock skewed %ds; sync NTP to avoid session rejection", clockSkewSeconds())
}

Try / catch

if err := auth.SelectOrSignInOrCreate(); err != nil {
    if strings.Contains(err.Error(), "error getting org session") {
        if isUnauthorized(err) {
            clearStoredAuth()
            return auth.SelectOrSignInOrCreate() // full re-auth on 401
        }
        return retryWithBackoff(auth.SelectOrSignInOrCreate, 3) // transient
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/65e803d790e72513. Report an issue: GitHub.