AMS feeding issue while manual feeding work

Recently, my p1s printing start to fail always, the symptom is that AMS loading is not working. If I choose to load from AMS, I can see the filament goes all the way to the print head, and then it goes back, and try again and again 4 times and failed, some something like stuck head. At first I thought it extruder gear issue, so I replaced a new one, but the issue is still there. Actually, I tried to print without AMS and use manual feeding, it works just fine. So I asked chatgpt, it says it might be filament sensor issue. I am not sure if I should replace the sensor too. It looks ok to me. Anyone has the same issue? Is there a way to test the filament sensor? thanks.