X/Y axis's assumed to be 0,0 at printer power on

Fairly new to Klipper. Built several printers. Came over from the “dark side - Marlin 2.0”. Have several successful prints via Klipper but am experiencing an issue I can’t resolve. It seems like the printer “assumes” that the X axis is at 0 when the printer powers on. Sometimes that’s correct but not always. Of course when I run home X/Y , since the printer “thinks” the X axis is already homed, it homes Y and Z correctly but the X axis stays in whatever position it might be at and never moves towards the end stop. The printer has optical end stops and is a CoreXY. I have resorted to disabling the steppers, moving the X manually to the end stop, re-enabling the steppers, and homing all axis which then works as expected.
Here is my current printer.cfg (pertinent parts) - any help would be greatly appreciated:

[stepper_x]
step_pin: P2.2
dir_pin: P2.6
enable_pin: !P2.1
microsteps: 16
full_steps_per_rotation: 200
rotation_distance: 40
endstop_pin: ^P1.29  # P1.28 for X-max
position_endstop: 0
position_min: 0
position_max: 270
homing_speed: 80
homing_retract_dist: 0

[stepper_y]
step_pin: P0.19
dir_pin: !P0.20
enable_pin: !P2.8
microsteps: 16
full_steps_per_rotation: 200
rotation_distance: 40
endstop_pin: ^P1.27  # P1.26 for Y-max
position_endstop: 0
position_min: 0
position_max: 240
homing_speed: 60
homing_retract_dist: 0

[stepper_z]
step_pin: P0.22
dir_pin: P2.11
enable_pin: !P0.21
microsteps: 8
rotation_distance: 4
full_steps_per_rotation: 200
endstop_pin: probe:z_virtual_endstop
position_min: -2 
position_max: 275
homing_speed: 10
homing_retract_dist: 10

[stepper_z1]
step_pin: P0.1
dir_pin: P0.0
enable_pin: !P0.10
microsteps: 8
rotation_distance: 4

[safe_z_home]
home_xy_position: 0, 0
speed: 50
z_hop: 5
#z_hop: 10
z_hop_speed: 30

[extruder]
step_pin: P2.13
dir_pin: P0.11
enable_pin: !P2.12
microsteps: 8
rotation_distance: 25
#rotation_distance: 0.012620
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: P2.7
sensor_type: EPCOS 100K B57560G104F
sensor_pin: P0.24
min_temp: 0
max_temp: 260
min_extrude_temp: 170
max_extrude_only_distance: 780
max_extrude_cross_section: 50
#pressure_advance: 0.254  # See tuning pressure advance doc
#pressure_advance_smooth_time: 0.040

[firmware_retraction]
retract_length: 4
#   The length of filament (in mm) to retract when G10 is activated,
#   and to unretract when G11 is activated (but see
#   unretract_extra_length below). The default is 0 mm.
retract_speed: 20
#   The speed of retraction, in mm/s. The default is 20 mm/s.
#unretract_extra_length: 0
#   The length (in mm) of *additional* filament to add when
#   unretracting.
unretract_speed: 20
#   The speed of unretraction, in mm/s. The default is 10 mm/s.

[heater_bed]
heater_pin: P2.5
sensor_type: ATC Semitec 104GT-2
sensor_pin: P0.23
min_temp: 0
max_temp: 120

[fan]
pin: P2.3

[heater_fan noozle_fan]
heater: extruder
shutdown_speed: 0
cycle_time: 0.010
kick_start_time: 0.100
heater_temp: 50
fan_speed: 1.0
pin: P2.4

[mcu]
serial: /dev/serial/by-id/usb-Klipper_lpc1768_1980FF16039445AF3E58DE5CC42000F5-if00
restart_method: command

[printer]
kinematics: corexy
max_velocity: 300
max_accel: 3000
max_z_velocity: 30
#max_z_velocity: 25
max_z_accel: 75
#max_z_accel: 55

[virtual_sdcard]
path: ~/.octoprint/uploads/


[bltouch]
sensor_pin: ^P1.25 # Pull-up (^ symbol) needed in open drain mode
control_pin: P2.0
pin_up_touch_mode_reports_triggered: False
set_output_mode: 5V
x_offset: 0
y_offset: 0
#z_offset: 1.78
z_offset: 1.85
speed: 2.0
samples: 2

#probe_with_touch_mode: False
#pin_up_reports_not_triggered: True
#pin_up_touch_mode_reports_triggered: True


[bed_mesh]
speed: 150
horizontal_move_z: 7
mesh_min: 0,0
mesh_max: 250,240
probe_count: 3,3
split_delta_z: 0.025
#move_check_distance: 3.0
move_check_distance: 5.0
mesh_pps: 2,2
algorithm: lagrange
fade_start: 1
fade_end: 10
fade_target: 0

Have you run QUERY_ENDSTOPS to verify the X endstop is functioning properly?

Yes. It homes correctly once I manually move the print head over to the end stop. It will also home correctly before performing bed probing.
Also, if I move the print head away from the “real” “0,0” via the “control” buttons on Octoprint, and then try to home, the printer refuses to move back to the end stop and shows that the new location is now “0,0”. Strange… Have performed several “host” and “firmware” resets as well as rebooting the entire printer.

If it doesn’t move when the head is not near the endstop, that indicates the endstop is already triggered. I would double check that the endstop is working properly and triggering only when it should.

Thanks for the reply. Like I mentioned previously, I have completed many successful prints with Klipper. As long as the print head has already triggered the end stop (i.e. after I manually moved it to the end stop), it will home with no issues (before probing the bed for example). I have verified that the end stop functions properly (triggered and open as appropriate).
I understand that anytime the printer doesn’t “know” where the print head is and a homing command is issued it should ALWAYS travel until it triggers the appropriate end stop before it will allow the axis to be moved. It’s just not consistently doing so but only for the X axis (Y and Z act correctly). Please let me know if there’s some log file or additional info you need from me and I’ll gladly provide it. Thanks again!

Another test you can perform is changing the retract distance on the X axis to something like 5. If the axis then reports an error that it’s still triggered after retract, then you know it’s an endstop problem. I know you’ve tested the endstop, but the symptoms you describe indicates that is the problem.

Great! I’ll give that a try. I admit it could be a defective optical sensor or board problem. Figured someone might recognize the problem if I described it adequately. I’ll let you know if that fixed the issue. Thanks for all of the help.