Saltar a contenido

PDF-012J - Worker Global Guard Integration

Estado: PDF-012J_WORKER_GLOBAL_GUARD_INTEGRATION_PASS.

Causa raiz PDF-012H

PDF-012H confirmo un NO-GO real: el worker manual de outbox produjo 2 emails internos cuando la regla operacional esperaba 1. La falla fue de idempotencia global: el retry/fallback podia avanzar sin validar primero si ya existia un SEND_SUCCEEDED compatible.

Regla global

Antes de cualquier fallback y antes de cualquier SMTP real, el worker debe evaluar:

  • request_id
  • payload_hash
  • notification_type
  • recipient_email
  • scope/gate/manual run key
  • semantic_event=SEND_SUCCEEDED

Si existe un exito compatible, el worker registra o devuelve ALREADY_SENT_GLOBAL_BLOCKED, mantiene email_sent=false, no crea fallback enviable, no conecta SMTP y no ejecuta MAIL FROM, RCPT TO ni DATA.

Casos probados

  • Caso A - exito historico existente: detecta SEND_SUCCEEDED previos de PDF-012H y PDF-012F, evalua GLOBAL_GUARD_EVALUATED y bloquea con ALREADY_SENT_GLOBAL_BLOCKED antes de SMTP.
  • Caso B - fallback candidate: simula una notification original no lista y un fallback candidate READY_BLOCKED; el fallback queda bloqueado con FALLBACK_BLOCKED_BEFORE_SMTP y fallback_sendable=false.
  • Caso C - notification nueva sintetica: crea o reutiliza PDF-012J:BILLING_CUSTOMER_REQUEST:TEST001 con tipo/recipient permitidos por DDL, payload/scope/request propios sin exito compatible, y registra SEND_ELIGIBLE_BUT_BLOCKED.
  • Caso D - retry: reintenta el guard y conserva idempotencia de eventos sin envio.

Evidencia sin SMTP real

El ejecutor execute_pdf_012j_worker_global_guard_integration.py no importa smtplib, no lee secrets SMTP y no define flags de confirmacion de envio. Los eventos quedan con:

  • email_sent=false
  • smtp_connected_for_send=false
  • smtp_send_commands_executed=false
  • smtp_mail_from_executed=false
  • smtp_rcpt_to_executed=false
  • smtp_data_executed=false

SQL write local/dev exacto

Autorizado y ejecutado solo en PostgreSQL local/dev gestion_de_negocios_core, schema business_observer:

  • insert idempotente en business_observer.ecommerce_notification_outbox para PDF-012J:HISTORICAL_SUCCESS_GUARD:TEST001 si faltaba.
  • insert idempotente en business_observer.ecommerce_notification_outbox para PDF-012J:ORIGINAL_NOT_READY:TEST001 si faltaba.
  • insert idempotente en business_observer.ecommerce_notification_outbox para PDF-012J:FALLBACK_CANDIDATE:TEST001 si faltaba, siempre bloqueado y no enviable.
  • insert idempotente en business_observer.ecommerce_notification_outbox para PDF-012J:BILLING_CUSTOMER_REQUEST:TEST001 si faltaba.
  • insert idempotente en business_observer.ecommerce_notification_event_log para NOTIFICATION_CREATED de las notifications PDF-012J nuevas.
  • insert idempotente en business_observer.ecommerce_notification_event_log para GLOBAL_GUARD_EVALUATED, ALREADY_SENT_GLOBAL_BLOCKED, FALLBACK_BLOCKED_BEFORE_SMTP y SEND_ELIGIBLE_BUT_BLOCKED.

Resultado

PDF-012J integra el guard global como contrato local/dev del worker real/manual. Produccion sigue bloqueada para envio real hasta nuevo GO explicito.

Proximo paso

Crear un gate separado para revision final del worker con guard global aplicado al flujo real/manual completo antes de autorizar cualquier nuevo envio SMTP.