Inclusion Criteria:
          -  Half of the study population in phase 2 must have a deleterious tumor alteration in at
             least one protocol specified gene
          -  Gastric or gastroesophageal junction adenocarcinoma
          -  Advanced stage 4 or locally unresectable stage 3 disease
          -  Must have measurable disease
          -  Must consent to have a biopsy if archival tissue is not available or not enough for
             molecular testing
          -  Must show evidence of progression or intolerance to at least one previous standard of
             care systemic therapy (not more than 2 lines of prior therapy)
          -  Patients with human epidermal growth factor receptor 2 (HER2) positive disease must
             show progression on prior HER2 targeted therapy
          -  Toxicities related to prior treatment should be recovered to baseline or less than
             grade 2 according to CTCAE
          -  Adequate organ and marrow function
          -  Absence of active autoimmune disease that has required systemic treatment in the past
             2 years
          -  Absence of conditions requiring systemic treatment with either corticosteroids or
             other immunosuppressive medications within 14 days of study drug administration. 10mg
             or less of prednisone or equivalent is acceptable
          -  Evidence of post-menopausal status or negative serum pregnancy test for female
             pre-menopausal patients
          -  Women of child-bearing potential and men with partners of child-bearing potential must
             agree to practice sexual abstinence, or to use two forms of adequate contraception
             prior to study entry, for the duration of study participation, and for 6 months
             following completion of therapy
          -  Men of child-bearing potential must not father a child or donate sperm while on this
             study and for 7 months after their last study treatment
        Exclusion Criteria:
          -  Prior treatment with a programmed cell death protein 1 (PD1) or programmed death-
             ligand 1 (PD-L1) inhibitors
          -  Prior treatment with poly-(ADP-Ribose)polymerase (PARP)
          -  Patients with microsatellite instability (MSI) high or mismatch repair (MMR) deficient
             tumors
          -  Abdominal fistula, GI perforation, bowel obstruction, or intra-abdominal abscess
             within 6 months before first dose
          -  Evidence of active peptic ulcer disease, inflammatory bowel disease, diverticulitis,
             cholecystitis, symptomatic cholangitis or appendicitis, acute pancreatitis, acute
             obstruction of the pancreatic duct or common bile duct, or gastric outlet obstruction
          -  Inability to swallow tablets
          -  Uncontrollable ascites or pleural effusion
          -  Cavitating pulmonary lesion(s) or known endotracheal or endobronchial disease
             manifestation
          -  Clinically significant hematuria, hematemesis, or hemoptysis, or other history of
             significant bleeding within 12 weeks
          -  Lesions invading any major blood vessels
          -  Receipt of the last dose of anticancer therapy less than 28 days prior to the first
             dose of study drug
          -  Major surgery within 8 weeks before first dose of study treatment
          -  History of allogenic organ transplantation
          -  Active infection including tuberculosis, hepatitis B, hepatitis C, or human
             immunodeficiency virus. Patients with a past or resolved hepatitis B virus (HBV)
             infection are eligible. Patients positive for hepatitis C antibody are eligible only
             if polymerase chain reaction is negative for hepatitis C virus (HCV) RNA
          -  Receipt of live attenuated vaccine within 30 days prior to the first dose of study
             drug
          -  Uncontrolled intercurrent illness, including but not limited to, ongoing or active
             infection, symptomatic congestive heart failure, unstable angina pectoris, cardiac
             arrhythmia, interstitial lung disease, or serious chronic gastrointestinal conditions
          -  Uncontrolled hypertension defined as sustained blood pressure (BP) > 150 mm Hg
             systolic or > 100 mm Hg diastolic despite optimal antihypertensive treatment
          -  Prolonged baseline QT interval corrected for heart rate greater than 470 ms
          -  Brain metastases or spinal cord compression. Patients whose brain metastases have been
             treated may participate provided they show radiographic stability
          -  Known allergy or hypersensitivity to any of the study drugs or any of the study drug
             excipients
          -  Current or anticipated use of other investigational agents while participating in this
             study
          -  History of another primary malignancy except for:
               -  Malignancy treated with curative intent and with no known active disease before
                  the first dose of investigational product (IP) and of low potential risk for
                  recurrence
               -  Adequately treated non-melanoma skin cancer or lentigo maligna without evidence
                  of disease
               -  Adequately treated carcinoma in situ without evidence of disease
          -  Psychiatric illness/social situations that would limit compliance with study
             requirements
          -  Pregnant or breast feeding