To be effective the vented gap has to be between the masonry and foam, not between the foam and the studwall. The foam needs to be tight to the studwall, otherwise the channel is both a thermal bypass, but also a code violation, since a vertical cavity partly inside the insulaion layer needs fire-blocking to limit fire spread.
The cavity is a capillary break between the moisture-laden brick and the rest of the materials. 2" foam is a fairly good capillary break on it's own, but if the brick can't dry into a vented cavity it's moisture levels remain high, which puts the joist ends in the joist- pockets at higher risk. The "right" thing to do is to leave a 1" gap between the brick and the foam, and drill weep holes a few inches above grade so that outdoor air can convect into that cavity, and seal the full perimeter of the stud bays to the foam inside of EVERY stud bay, to prevent air migration either sideways or up and down inside the studwall. If the top of the cavity isn't vented to the exterior, drill vent holes corresponding to the weep holes. This should be about every third brick or so.

It's generally safe to insulate the brick & joists at the joist pockets with an inch of closed cell polyurethane for a few inches on either side of the joist, using rock wool on the interior of that to fatten out the . At 1" the closed cell foam will be ~R6-R7, but would also be about 1-perm of vapor permeance, which allows it to dry toward the interior. It's key to NOT put vapor barriers on the interior side of the studwall anywhere, but even more so in the sections around the joist pockets.
Below grade there's no benefit to the cavity, since there is no way to inject dry exterior air into the bottom of that cavity, which would remain at ~100% relative humidity most of the time. With the 2" foam tight to the block it has to dry to the above-grade exterior, which it will do just fine. Concrete block is not adversely affected by moisture but the wood is. If you maximize the drying capacity of the wall above-grade with a vented cavity properly between the brick & foam it'll do just fine.
Ideally you would have at least 1' of roof overhang per story of height to limit the direct rain wetting of the brick (?), as well as good surface drainage at grade near the wall, rain gutters to keep the soil near the foundation from becoming super-saturated.
So from outside to inside above grade:
outdoor air | brick | 0.5-1" of air | 2" foam | 2x4 fiber insulated studwall, framing sealed to the foam | interior wallboard ideally air-tight, but no vapor barriers.
The stackup looks like this image scavenged from the web, except that #4 is 2" foam, not reflective insulation (though foil-faced polyiso would give you a slight edge in your application.)

Below grade:
dirt | brick or block | 2" foam | 2x4 fiber insulated studwall, framing sealed to the foam |
interior wallboard ideally air-tight, but no vapor barriers.
The below grade stackup on this can be used right up to the first floor subfloor level, or slightly below, provided you make clearances around the joist pockets:

For the ~3-4" either side and top/bottom of the joist pockets:
brick or block | 1" closed cell spray foam (max) | rock wool or fiberglass batt | vapor permeable interior air barrier (wallboard is fine)
It's important to make the joist pocket area air-tight to the interior with the closed cell foam, since wintertime air could otherwise come in contact cold enough to adsorb moisture from that air. If any of the joists appear to be rotting you may have to take remedial measures before insulating. Making the closed cell foam the condensing surface rather than the cold wood, the moisture content of the joist end will track the moisture content of the brick, which it mostly does anyway, but won't become a higher-moisture area in winter from interior moisture drives. It may be worth buying a 100-200 board foot 2-part foam kit for this part, depending on how much you are going to do at a time. If it's just small section, a 12 board foot FrothPak (available at most box stores) it probably the "right" solution.