Immune checkpoint inhibitors (ICI) show high efficiency in a small fraction of advanced gastric cancer (GC). However, personalized immune subtypes have not been developed for the prediction of ICI efficiency in GC. Herein, we identified Pan-Immune Activation Module (PIAM), a curated gene expression profile (GEP) representing the co-infiltration of multiple immune cell types in tumor microenvironment of GC, which was associated with high expression of immunosuppressive molecules such as PD-1 and CTLA-4. We also identified Pan-Immune Dysfunction Genes (PIDG), a conservative PIAM-derivated GEP indicating the dysfunction of immune cell cooperation, which was associated with upregulation of metastatic programs (extracellular matrix receptor interaction, TGF-β signaling, epithelial-mesenchymal transition and calcium signaling) but downregulation of proliferative signalings (MYC targets, E2F targets, mTORC1 signaling, and DNA replication and repair). Moreover, we developed 'GSClassifier', an ensemble toolkit based on top scoring pairs and extreme gradient boosting, for population-based modeling and personalized identification of GEP subtypes. With PIAM and PIDG, we developed four Pan-immune Activation and Dysfunction (PAD) subtypes and a GSClassifier model 'PAD for individual' with high accuracy in predicting response to pembrolizumab (anti-PD-1) in advance GC (AUC = 0.833). Intriguingly, PAD-II (PIAMhighPIDGlow) displayed the highest objective response rate (60.0%) compared with other subtypes (PAD-I, PIAMhighPIDGhigh, 0%; PAD-III, PIAMlowPIDGhigh, 0%; PAD-IV, PIAMlowPIDGlow, 17.6%; P = 0.003), which was further validated in the metastatic urothelial cancer cohort treated with atezolizumab (anti-PD-L1) (P = 0.018). In all, we provided 'GSClassifier' as a refined computational framework for GEP-based stratification and PAD subtypes as a promising strategy for exploring ICI responders in GC. Metastatic pathways could be potential targets for GC patients with high immune infiltration but resistance to ICI therapy.