Hard Shifting & loss of acceleration with 1999 Subaru Legacy Wagon

Hoping someone has experienced this and may have some advice on the route of repair.

So far three mechanics (including the Subaru dealership) have been unable to solve the source of this issue. The issue is intermittent and random but very scary as it results in a total loss of acceleration and jolting hard shift. The tricky part is that it doesn’t happen all the time and we can go up and down the interstate on long road trips with no issues at all. In town driving is when the issue usually occurs. I have yet to have a mechanic be able to experience the issue when they road test - most likely because they do not have the time to drive it for long amounts of in town driving time?

This is an automatic transmission and what happens when you are in town driving at around 35-45 mph.

Conditions in which hard shift occurs:
Start and stop traffic i.e. between stoplights where you can get up to 35-45 mph. Also tends to happen when accelerating and then going down a hill or steep grade between 35-45 mph. For example accelerating up to a hill and letting off the acceleration (no brake just foot off accelerator) when going down the hill and then give it good amount of gas once it get to a slower rate of speed.

Most times this issue happens when going up a bit of a hill and going car gas or going down a hill while in gear but not giving the car gas and not braking (where the car has to regulate its speed on a downhill grade).

When the issue happens you notice first a loss in acceleration and then the AT Oil light will start flashing and a very noticeable hard knocking shift where you won’t be able to accelerate above 20 mph (like its stuck). The check engine light usually comes on AFTER the hard shift. Sometimes however NEITHER AT oil light nor Check Engine light comes on.

The only way we have found to get it “unstuck” from not being able to accelerate after hard shift is to let the car idle for 20 minutes or more OR turning the car off and on sometimes once but sometimes 2 or 3 times. This gets it back to normal and if AT oil light was flashing, this will go away and check engine remains.

We have had one mechanic replace the Throttle position sensor and that has not resolved the issue. Then we took it to the dealership and they said the voltage was set incorrectly on the Throttle Position Sensor (this was set correctly by my previous mechanic and I suspect what is causing the issue is throwing the voltage out of whack).

The dealership mechanic readjusted the Throttle Position Sensor to spec voltage. It happened again within a day after the voltage was set correctly. Took it back to dealership and they cleaned conductive grease of the Throttle Position Sensor’s plug contacts - they said was put on there incorrectly by my previous mechanic and that would solve the issue. The hard shift came back after a day of in town driving so conductive grease was not the culprit.

Took it back to the dealership and left the car for an ENTIRE week at mechanics request! At the end of the week they still could not tell me what was wrong. The closest they could come to giving me an answer was that it may be electrical or the engine wiring harness. Nothing conclusive though in terms of a diagnosis.

When I dropped it off to the dealership for the week, I set the trip counter to zero to see how much the car was road tested and it showed only 8 miles had been driven for road testing purposes for the whole week it was with the dealership mechanic.

At this point I am not sure what the next step if the dealership cannot solve? How on earth can I get an expert to pinpoint the issue without throwing money at possible problems? Any suggestions are greatly appreciated. Thanks!