cc-ultrav-1 7048f44d67 fix: duplicate detected on retry must STOP entire booking process (not just slot)
Critical logic bug caught by careful review:

- When 'Cita insertada' is returned on a retry, the cita is ALREADY
  inserted into the database — no further booking action needed, just
  confirm and exit (the comment 'Book it!' was misleading).

- When a duplicate ('ya existente'/'DNI'/'existe') was detected during
  skew retry, the code only broke the inner while loop. Since booked_hora
  was None, 'if booked_hora: break' did NOT trigger, and the outer for
  loop continued to the NEXT slot — potentially booking additional
  slots when a cita for this person already exists.

- The EXCEPTION branch's force-reconnect retry had NO duplicate detection
  at all — it fell through to a generic 'else: log()' for any unexpected
  response, including duplicates.

Fixes:
- Added duplicate_detected flag (initialized False) checked in outer
  loop: 'if booked_hora or duplicate_detected: break'
- Set duplicate_detected = True in ALL three duplicate detection paths:
  (1) initial attempt, (2) skew retry loop, (3) EXCEPTION retry
- Added explicit 'Hora no permitida' and 'Fecha posterior' handling
  in EXCEPTION retry branch (was generic else)
- Removed stale '5x43ms' comment → reflects true '120s 3-phase backoff'
- Clarified comments: 'Cita insertada' = already booked (success),
  not a booking action to perform

Tests: 58 passed (added test_duplicate_detected_flag_stops_outer_loop)
2026-10-03 22:51:33 +02:00
Description
Municipal cita previa booking automation
412 KiB
Languages
Python 68.7%
JavaScript 29.4%
Shell 1.9%