Observability & events
This page defines the words to read, from the logs only, what happened to a note that came in over WhatsApp. It covers the study channel, the milestones, and the two structured log lines that show them.
This page is the operational complement to intake & extraction and the WhatsApp channel (coach). Those pages describe what the system does. This page describes how to see it. The page has two goals:
- Reconstruct an incident without opening the database.
- Give a stable event stream that an eval harness can subscribe to.
Status of this page
Section titled “Status of this page”The study channel, the five milestones, the audit_log and the two structured log lines (biobadamex.study_channel and biobadamex.milestone_sent) are merged to main and in production.
No field on this page carries PHI (protected health information). No field holds the phone, the filename or a clinical value.
| Term | Meaning |
|---|---|
| Study channel | The path of the WhatsApp webhook for participating clinicians. The whitelist selects it. |
| Pseudonym | wa- followed by a salted hash of the phone. It identifies the sender in place of the phone. |
| Outcome | The one decision that the study channel makes for each inbound message. |
| Milestone | A privacy-safe status message that the system sends to the clinician at a key point of the journey. |
| Claimed | A milestone that won its turn to send. A unique index in the database makes this exactly-once. |
| Sent | A milestone that won its claim and whose send resolved. |
| Receipt code | A PHI-free code for one note, for example RC-XXXXXXXXXX. |
The study channel
Section titled “The study channel”One WhatsApp webhook serves two very different types of sender: patients in triage, and participating clinicians who send clinical notes for the study. The study channel is the path for the clinician. A flag does not select this path. The whitelist decides.
- A number on the whitelist is a participating clinician. Its messages never touch the patient path.
- A number that is not on the whitelist behaves exactly as it did before the study channel existed.
In the study channel, the sender moves as a pseudonym, never as the raw number. The pseudonym is deterministic. Thus an operator can follow one clinician across messages and never see the phone. The pseudonym is the only sender identifier in the logs and the audit rows.
For each inbound message, the channel makes one decision (outcome). The system logs this decision:
| outcome | What it means |
|---|---|
submitted |
The channel ingested an accepted document and put it in the extraction queue. |
rejected |
The channel could not process a document (format, no text layer, queue paused). The clinician gets a reason with an action. |
unauthorized |
The owner of a whitelisted number does not resolve to one active, approved clinician. This number now also gets a reply, never silence. |
duplicate |
The message is a repeated delivery of an event that the channel already claimed (exactly-once). No side effect ran. |
replied |
The channel answered with guidance or a notice (how to submit, consent, invalid format). |
consent_granted / consent_revoked |
The clinician enrolled (ACEPTO) or withdrew (BAJA). |
coach_relayed / coach_duplicate |
The channel relayed a text turn to the conversational coach (or the turn was a repeated delivery). |
The channel does not observe a message from a number that is not on the whitelist (pass_through). That message keeps its exact silent path from before the study.
A note’s journey, end to end
Section titled “A note’s journey, end to end”Figure 1 shows the path of an inbound message and the records that it leaves.
Event: biobadamex.study_channel
Section titled “Event: biobadamex.study_channel”The system emits this line one time for each inbound message that the study channel handled. The line is the decision record. The incident that caused this instrumentation needed four tables and the audit_log to reconstruct. This one line shows the answer at once.
| Field | Content |
|---|---|
outcome |
The terminal decision (see the table above). |
pseudonym |
The salted pseudonym of the sender. Never the phone. |
messageType |
text, audio or document. |
extension |
Only the document extension (.docx, .pdf, .txt), never the filename. Filenames carry patient data. null for a message that is not a document. |
denialReason |
On unauthorized: ownerless, missing, inactive, revoked or ambiguous. |
reply |
The key of the reply that the channel sent, on replied / rejected. |
receiptCode |
The PHI-free receipt code (for example RC-XXXXXXXXXX), on submitted / duplicate. |
uploadId, jobId |
The upload id and the extraction job id, on submitted. |
coachEnabled |
Whether the coach relay was enabled for this event. |
durationMs |
The wall-clock time inside the channel. |
Example of the failure that caused this page: a .docx came from a whitelisted number. The owner of the number was an admin account without approval. The channel logged outcome: "unauthorized", denialReason: "inactive". This was the missing line. It would have named the problem immediately.
The milestones
Section titled “The milestones”The system does not process a note immediately. The system downloads the note and puts it in the queue. A model extracts the note, and the system makes a draft. This work takes seconds to minutes in a separate worker process. A milestone tells the clinician the status at the key points of this journey. There are five milestones:
accepted: “We received your document; it’s being extracted.” This is the intake acknowledgement.draft_ready: “The draft is ready for review.” It carries the owner-scoped link. When available, it also carries the number of drafts that wait for review.delayed: the extraction takes longer than normal (a retry).failed: the extraction failed terminally. The milestone asks the clinician to send the file again.rejected: the system rejected the draft automatically, for example because the document has no readable text. The milestone gives the reason and asks the clinician to correct the note and send it again.
An incomplete WhatsApp draft can get the proactive coach opening in place of draft_ready. This opening is not a milestone. Refer to WhatsApp channel (coach).
The privacy contract is strict. A milestone can carry only the receipt code, a pending count and the owner-scoped link. The rejected milestone also carries a fixed-text reason, for example “the birth date of the patient is missing”. It never carries a filename, a patient label, a clinical field or value, or a registry identifier.
Do not confuse two states. A milestone is claimed separately from being sent. In the incident, the test PDF had accepted and draft_ready claimed in the database. This alone does not prove that the text reached the handset of the clinician.
Event: biobadamex.milestone_sent
Section titled “Event: biobadamex.milestone_sent”This line closes that gap. The system emits it only when a milestone is sent: the milestone won its claim AND the send resolved. A claim alone does not emit the line. Thus the logs show the difference between “we decided to notify them” and “they were notified”.
| Field | Content |
|---|---|
milestone |
accepted, draft_ready, delayed, failed or rejected. |
receiptCode |
The PHI-free receipt code of the note. |
The audit_log: the durable trail
Section titled “The audit_log: the durable trail”The two lines above are application logs. Application logs are ephemeral. The audit_log is their durable complement at rest. Every channel decision writes a row with the actor wa:<pseudonym> and an action. Some actions are biobadamex.study_consent_granted, biobadamex.study_submission_received, biobadamex.study_authorization_denied.<reason> and biobadamex.study_submission_rejected. After the logs rotate, the audit_log still answers “what happened to this participation”.
The trail of a successful submission
Section titled “The trail of a successful submission”A successful submission leaves this trail. The numbers in Figure 2 are the numbers in this list.
- The study channel logs
study_channelwithoutcome: submittedand itsreceiptCode. The channel also writes itsaudit_logrow. - The channel sends the
acceptedmilestone and logsmilestone_sent: accepted. - After the extraction, the system sends the
draft_readymilestone and logsmilestone_sent: draft_ready.
A submission can fail before it makes a receipt, for example with an authorization denial. Then the trail is study_channel with outcome: unauthorized and its denialReason, and no receipt. This is exactly the “nothing happens” case that was invisible before.
As a basis for evals
Section titled “As a basis for evals”The study_channel observation is a structured, PHI-free record of the decision for each event. An eval harness subscribes to the same shape. On this stream you can measure these values:
- the rate of
submittedagainstrejectedagainstunauthorized - the distribution of the denial reasons
- the outcomes of the coach relay
The logs of the extraction worker give the completeness (missing fields) of each draft. The principle: no coverage boundary is silent. Every handled event emits its line.
Evidence in code
Section titled “Evidence in code”Paths on main:
- Monorepo:
apps/api/src/services/whatsapp-study-channel.ts(StudyChannelObservation, theobservehook, the wrapper that emits it) - Monorepo:
apps/api/src/services/whatsapp-webhook.ts(connectsobserveto the logger) - Monorepo:
apps/api/src/services/whatsapp-study-milestone.ts(theonSenthook andbiobadamex.milestone_sent) - Monorepo:
apps/api/src/services/whatsapp-study-authorization.ts(the denial reasons in the observation)