Architecture
Builds the forecast by 6:25.Weekdays, on Cloud Run.
A script in the VP of Finance's own Google account copies two lab exports into a bucket, and a weekday job turns them into the VP's forecast with the model ported exactly. Nine checks decide whether it goes out, Gemini writes one paragraph over finished numbers, and the same script emails the report back.
49 s
average run from wake to a report in the outbox, over 22 sent mornings
16 of 16
weekday mornings sent since the October 7 fix
0
new numbers Gemini can put in the report; code checks its paragraph on every run
16 days
from the first commit on Sep 8 to the first report from the scheduled job
New York --:-- simulated
Hover a part to trace what it touches. Click it for its notes.
- Built by me
- Managed by Google
- Outside system
- Main data path
- On demand
- Credentials cross
When it breaks
What each failure does, and what it does not do.
-
The invoice export is late
Runs before it lands hold quietly and look again 15 minutes later. If nothing arrives by 11 AM, the morning is marked missed and an alert email goes out.
packages/pipeline/dsr_pipeline/config.py:37
-
A data check fails
The projection still computes and lands on the dashboard marked failed. The email is held, and an alert built on the job's own log line emails me.
scripts/setup_alerts.sh:1
-
Gemini errs or invents
The deterministic template, written from the same inputs, ships in its place. The run records which one wrote the paragraph.
packages/pipeline/dsr_pipeline/narrative.py:240
What I tuned
Small choices that keep it fast and cheap.
-
Wait for a quiet bucket
A run reads only after the bucket has been still for 5 minutes, since a morning's uploads take about half a minute. Since September 28 the report has been built between 6:21 and 6:25.
packages/pipeline/dsr_pipeline/landing.py:45
-
One run at a time
A lock object created only if absent keeps two runs off the same files, so a day's revenue is never counted twice. A lock older than 20 minutes is taken over.
packages/pipeline/dsr_pipeline/lock.py:1
-
Nothing new, seven seconds
532 of 610 scheduled runs found nothing new and exited in about seven seconds. The one that builds the report takes about 49.
BigQuery dsr.job_runs, Oct 29 2026
Guards
Rules the code enforces, not rules people remember.
-
No mailbox credential
Nothing in the project can read mail. The VP's own account copies the attachments in and may only add files to the landing bucket.
infra/terraform/mailbridge.tf:1
-
Patient fields dropped first
Case numbers, patient and practice names, addresses and phones are dropped at parse time, listed by name, before anything reaches BigQuery.
packages/pipeline/dsr_pipeline/parsers.py:54
-
Every number checked
A number in Gemini's paragraph that is missing from the payload, in any reasonable rounding, rejects it. So does a claim the spec tested and found unsupported.
packages/pipeline/dsr_pipeline/narrative.py:209
