Skip to content

Consent and data rights: follow-ups from the #6 reviews #7

Closed

Description

@juancodedev

Follow-ups from the reviews of #6 (patient consent, data rights and retention). None blocks the merge; all were reported as non-blocking advisories.

Correctness

  • ACEPTO takes no per-sender lock. recordSenderConsent is a plain insert into consent_events, while revoke_sender_consent and erase_sender_data take a per-sender advisory lock (migration 008). If ELIMINAR and ACEPTO from the same sender interleave, a granted event can land after the erasure. Fix: move the grant into a SQL function that takes the same lock and checks the prompt was shown.
  • Crisis exchange on a failed consent read. persistCrisisExchange skips storing the redacted crisis marker when the consent read fails (lookupFailed), even for a consented sender. The helpline is always sent. Decide whether this fail-closed behavior is intended, and pin it with a test.
  • Bare "pánico" overmatches. The clinical keyword was widened from "ataque de pánico" to "pánico", so administrative questions that mention it get the clinical referral and are stored as a marker.
  • Clinical keyword coverage. "estoy deprimida", "tomo sertralina", "no puedo dormir" are not detected as clinical, so for consented senders they reach Claude and storage as written.

Maintainability

  • Command words are duplicated. Reply texts (OPT_IN_CONFIRMED_NOTICE, REVOKED_NOTICE, NOTHING_TO_REVOKE_NOTICE, consentReminder) and the seeded policy text spell out ACEPTO, BAJA and ELIMINAR instead of using OPT_IN_TOKENS, REVOKE_TOKEN and ERASE_TOKEN.
  • isClinicalRefusal is coupled to a substring. It checks for "atención directa", an unstated fragment of CLINICAL_REFERRAL_RESPONSE. Derive the check from the constant.
  • Retention and window literals. The 90 days appear in the purge default, the cron script, the preview query, the consent text and the docs. The 2-hour counter retention in erase_sender_data silently depends on RATE_LIMIT_WINDOW_MS being one hour.
  • Naming. The gate's erased variable holds "a consent was also withdrawn", not "data was erased".
  • Purge SQL test asserts exact counts, so it only passes on a fresh database.

Accepted by design (no action unless it changes)

  • BAJA and ELIMINAR are handled before the rate limit: exercising a right must not depend on message count. Cost is indexed queries and one reply, no Claude call.
  • After BAJA, the record that the policy was shown is kept, so a later ACEPTO counts without showing the text again.

References: odd/tasks/patient-consent-and-data-rights.md (Log L11-L16), docs/09-privacidad-y-consentimiento.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions