feat(bcda): incremental _since pulls — watermarks, temporality checks, reconciliation with tiebreakers, ledger and invariants
Some checks failed
Infra CI / notebooks (push) Successful in 1m6s
CI / lint (push) Successful in 46s
CI / notebooks-smoke (push) Successful in 1m44s
CI / test (push) Failing after 2m36s
Infra CI / zotero (push) Successful in 21s
Infra CI / llm (push) Successful in 55s
Infra CI / bcda (push) Successful in 1m38s
Infra CI / docs (push) Successful in 1m46s
Infra CI / api (push) Successful in 1m8s
Infra CI / mc (push) Failing after 36s
CI / lint (pull_request) Successful in 43s
CI / test (pull_request) Failing after 2m30s
Infra CI / zotero (pull_request) Successful in 15s
Infra CI / llm (pull_request) Successful in 16s
CI / notebooks-smoke (pull_request) Successful in 1m52s
Infra CI / docs (pull_request) Successful in 15s
Infra CI / api (pull_request) Successful in 15s
Infra CI / notebooks (pull_request) Successful in 49s
Infra CI / bcda (pull_request) Successful in 18s
Infra CI / mc (pull_request) Failing after 35s

Design: docs/superpowers/specs/2026-10-25-bcda-since-reconciliation-design.md.

Until now a _since export was loaded like a full one: the loader took the
newest export directory per type, so a delta silently replaced the baseline
it was meant to extend. bcda.sync makes incremental pulls safe end to end.

First order — which row is current. A baseline (no _since) is the
authoritative snapshot for its types; deltas of the same population at or
after its cut-off extend it. Keys: Patient BENE_SK, Coverage id, EOB claim
control number (each claim *version* has a new FHIR id — migration guide).
Winner per key: newest meta.lastUpdated, then NCH/DDPS over SharedSystem
(the connector's rule), then later transactionTime, later applied sequence,
larger id. NotFinalAction winners stay as tombstones; only a baseline
retires rows (the API cannot express deletion). eob_item follows its header.

Second order — what a job did, per table, in the ledger: new / replaced /
unchanged / stale_ignored, backfill (lastUpdated < _since for an enrollee we
did not have — the API's promise for newly attributed enrollees on
Group/all) vs late (same shape for one we had — should not happen),
tombstoned, adjusted (clm_orig_cntl_num → bcda.eob_supersession), retired,
orphans (claims/coverage without a current Patient), scope drift.

Third order — invariants on every apply before anything is published:
unique keys, count conservation (|cur'| = |cur| + new − retired), watermark
monotone, every item has a header; replay determinism and idempotency are
tested (apply in either order → byte-identical tables; re-apply → no-op).
Current tables are re-derived from the applied partitions each time, so the
state is a function of the set of applied jobs, not their arrival order.

Temporality checks before a _since export starts (block/warn/ok): format,
future (server 400s), floor (no v3 lastUpdated before 2026-03-26),
no_baseline, gap (since > watermark: a window nobody would ever fetch),
overlap (free), endpoint_mix (runout vs current population),
backfill_scope (/Patient delta over a Group/all baseline), scope_filter
(_typeFilter drift), inflight, unapplied, attribution_newer,
stale_baseline. next_since() is the previous job's transactionTime, as
BCDA recommends; a combined job takes the earliest watermark of its types.

Store: job rows carry transaction_time and request, exports/<key>/
manifest.json keeps the completed-job body, resume() fills both in for
jobs completed before this; adopted jobs read _since from their request
line; a delta with nothing to deliver (200, empty output) still counts and
advances the watermark. flatten_export(out_dir=) writes per-job partitions
under flat/history/<key>/; current tables keep _job_key/_transaction_time/
_since/_kind/_applied_seq and the connector's _ensure() drops them before
the stage contracts. load_bcda(reconcile=True) applies pending jobs and
also loads bcda.sync_ledger, bcda.sync_watermark, bcda.eob_supersession;
an explicit ndjson_dir or a store without job rows keeps the legacy path.

Surfaces: `stack bcda sync status|check|apply|pull`, `stack bcda export
--since auto [--force]`, `stack bcda resume`; the manager's Exports page
gets a _since mode (off / watermark / date) with the checks shown and
blocks respected, and a Sync page (watermarks, pending, reconcile, ledger);
notebook section 8.

Verified on the real Large-entity store: applying the three baselines over
the legacy flat/ tables reported every row unchanged (0 new, 0 retired)
and loaded counts identical to the full load (221,021 medical lines,
11,968 pharmacy, 9,582 eligibility); a real /Patient-endpoint EOB delta
with a _typeFilter reconciled as 248 unchanged with the drift on record;
the sandbox's transactionTime is midnight UTC of the run day, so a
same-day zero-row delta is correctly ignored as predating its baseline.

refs #1139
This commit is contained in:
kert
2026-10-25 16:04:16 -04:00
parent 6c218b5898
commit a05cc51916
129 changed files with 3615 additions and 154 deletions

View File

@@ -1,6 +1,6 @@
---
title: stack api serve
sidebar_position: 77
sidebar_position: 79
---
# `stack api serve`

View File

@@ -1,6 +1,6 @@
---
title: stack api
sidebar_position: 76
sidebar_position: 78
---
# `stack api`

View File

@@ -1,6 +1,6 @@
---
title: stack bcda cancel
sidebar_position: 16
sidebar_position: 17
---
# `stack bcda cancel`

View File

@@ -19,8 +19,12 @@ Usage: stack bcda export [OPTIONS]
│ --endpoint TEXT Group/all, Group/runout or │
│ Patient. │
│ [default: Group/all] │
│ --since TEXT FHIR instant, e.g. │
│ 2026-01-01T00:00:00+00:00 │
│ --since TEXT FHIR instant │
│ (2026-10-01T00:00:00+00:00) │
│ or 'auto' = the per-type │
│ watermark. │
│ --force Start even when the _since │
│ checks say block. │
│ --system-type TEXT _typeFilter System-Type │
│ tag(s). │
│ --outcome TEXT _typeFilter outcome: partial │

View File

@@ -1,6 +1,6 @@
---
title: stack bcda load
sidebar_position: 18
sidebar_position: 19
---
# `stack bcda load`
@@ -8,8 +8,8 @@ sidebar_position: 18
```
Usage: stack bcda load [OPTIONS]
Flatten + load the newest export per type, run the connector, publish the
replica.
Reconcile the store (or flatten the newest export per type), load, run the
connector, publish the replica.
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --pipeline --no-pipeline Run the connector into input_layer.* │

View File

@@ -0,0 +1,21 @@
---
title: stack bcda resume
sidebar_position: 16
---
# `stack bcda resume`
```
Usage: stack bcda resume [OPTIONS] KEY
Finish a store job: re-poll, download missing files, record the manifest.
╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ * key TEXT Store job key (see `stack bcda store`). [required] │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --preset TEXT Public sandbox entity when BCDA_CLIENT_ID is unset. │
│ [default: Large Model Entity] │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

View File

@@ -1,6 +1,6 @@
---
title: stack bcda store
sidebar_position: 17
sidebar_position: 18
---
# `stack bcda store`

View File

@@ -0,0 +1,25 @@
---
title: stack bcda sync
sidebar_position: 21
---
# `stack bcda sync`
```
Usage: stack bcda sync [OPTIONS] COMMAND [ARGS]...
Incremental (_since) pulls.
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ status Watermarks per (endpoint, _typeFilter, type), downloaded vs applied │
│ jobs, ledger, current counts. │
│ check Temporality checks for a proposed _since (exit 2 on block). │
│ apply Reconcile downloaded jobs into the current tables (ledger kept), │
│ then load. │
│ pull Pull every type since its watermark (one job per type), then │
│ reconcile and load. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

View File

@@ -8,7 +8,7 @@ sidebar_position: 10
```
Usage: stack bcda ui [OPTIONS]
Launch the BCDA manager (Streamlit).
Launch the BCDA manager (Streamlit; /metrics when STACK_TELEMETRY is on).
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --port INTEGER Port for the Streamlit server. │

View File

@@ -1,6 +1,6 @@
---
title: stack bcda vendor
sidebar_position: 19
sidebar_position: 20
---
# `stack bcda vendor`

View File

@@ -14,17 +14,21 @@ Usage: stack bcda [OPTIONS] COMMAND [ARGS]...
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ ui Launch the BCDA manager (Streamlit). │
│ ui Launch the BCDA manager (Streamlit; /metrics when STACK_TELEMETRY │
│ is on). │
│ preflight /_version, /_health and metadata — no token needed. │
│ auth Issue a token and show attribution status. │
│ jobs Server job history for the entity (shared on the sandbox). │
│ export Run an export through the store (blocks until downloaded). │
│ adopt Download a completed job this store did not start. │
│ resume Finish a store job: re-poll, download missing files, record the │
│ manifest. │
│ cancel Cancel an in-progress job. │
│ store Local store: jobs, files, bytes. │
│ load Flatten + load the newest export per type, run the connector, │
│ publish the replica. │
│ load Reconcile the store (or flatten the newest export per type), │
│ load, run the connector, publish the replica. │
│ vendor Vendored upstream (CMSgov/bcda-app, bcda.cms.gov): manifest, │
│ verification, drift. │
│ sync Incremental (_since) pulls. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

View File

@@ -1,6 +1,6 @@
---
title: stack bib attach-iom
sidebar_position: 32
sidebar_position: 34
---
# `stack bib attach-iom`

View File

@@ -1,6 +1,6 @@
---
title: stack bib attach-oig
sidebar_position: 37
sidebar_position: 39
---
# `stack bib attach-oig`

View File

@@ -1,6 +1,6 @@
---
title: stack bib backfill-comments
sidebar_position: 30
sidebar_position: 32
---
# `stack bib backfill-comments`

View File

@@ -1,6 +1,6 @@
---
title: stack bib cfr-jump
sidebar_position: 42
sidebar_position: 44
---
# `stack bib cfr-jump`

View File

@@ -1,6 +1,6 @@
---
title: stack bib code-tags
sidebar_position: 43
sidebar_position: 45
---
# `stack bib code-tags`

View File

@@ -1,6 +1,6 @@
---
title: stack bib discover-pfs-rules
sidebar_position: 26
sidebar_position: 28
---
# `stack bib discover-pfs-rules`

View File

@@ -1,6 +1,6 @@
---
title: stack bib fetch-docket-comments
sidebar_position: 27
sidebar_position: 29
---
# `stack bib fetch-docket-comments`

View File

@@ -1,6 +1,6 @@
---
title: stack bib fetch-pfs-comments
sidebar_position: 28
sidebar_position: 30
---
# `stack bib fetch-pfs-comments`

View File

@@ -1,6 +1,6 @@
---
title: stack bib fr-grab
sidebar_position: 40
sidebar_position: 42
---
# `stack bib fr-grab`

View File

@@ -1,6 +1,6 @@
---
title: stack bib fr-jump
sidebar_position: 41
sidebar_position: 43
---
# `stack bib fr-jump`

View File

@@ -1,6 +1,6 @@
---
title: stack bib import-zotero
sidebar_position: 34
sidebar_position: 36
---
# `stack bib import-zotero`

View File

@@ -1,6 +1,6 @@
---
title: stack bib ingest-iom
sidebar_position: 31
sidebar_position: 33
---
# `stack bib ingest-iom`

View File

@@ -1,6 +1,6 @@
---
title: stack bib ingest-mail
sidebar_position: 29
sidebar_position: 31
---
# `stack bib ingest-mail`

View File

@@ -1,6 +1,6 @@
---
title: stack bib ingest-oig
sidebar_position: 36
sidebar_position: 38
---
# `stack bib ingest-oig`

View File

@@ -1,6 +1,6 @@
---
title: stack bib query
sidebar_position: 25
sidebar_position: 27
---
# `stack bib query`

View File

@@ -1,6 +1,6 @@
---
title: stack bib refresh-iom
sidebar_position: 39
sidebar_position: 41
---
# `stack bib refresh-iom`

View File

@@ -1,6 +1,6 @@
---
title: stack bib refresh-oig
sidebar_position: 38
sidebar_position: 40
---
# `stack bib refresh-oig`

View File

@@ -1,6 +1,6 @@
---
title: stack bib sync-zotero
sidebar_position: 35
sidebar_position: 37
---
# `stack bib sync-zotero`

View File

@@ -1,6 +1,6 @@
---
title: stack bib sync
sidebar_position: 23
sidebar_position: 25
---
# `stack bib sync`

View File

@@ -1,6 +1,6 @@
---
title: stack bib tag
sidebar_position: 24
sidebar_position: 26
---
# `stack bib tag`

View File

@@ -1,6 +1,6 @@
---
title: stack bib watch-iom
sidebar_position: 33
sidebar_position: 35
---
# `stack bib watch-iom`

View File

@@ -1,6 +1,6 @@
---
title: stack bib
sidebar_position: 22
sidebar_position: 24
---
# `stack bib`

View File

@@ -1,6 +1,6 @@
---
title: stack bls ces
sidebar_position: 46
sidebar_position: 48
---
# `stack bls ces`

View File

@@ -1,6 +1,6 @@
---
title: stack bls oews
sidebar_position: 45
sidebar_position: 47
---
# `stack bls oews`

View File

@@ -1,6 +1,6 @@
---
title: stack bls
sidebar_position: 44
sidebar_position: 46
---
# `stack bls`

View File

@@ -1,6 +1,6 @@
---
title: stack comments dockets
sidebar_position: 51
sidebar_position: 53
---
# `stack comments dockets`

View File

@@ -1,6 +1,6 @@
---
title: stack comments extract-ocr
sidebar_position: 49
sidebar_position: 51
---
# `stack comments extract-ocr`

View File

@@ -1,6 +1,6 @@
---
title: stack comments extract
sidebar_position: 48
sidebar_position: 50
---
# `stack comments extract`

View File

@@ -1,6 +1,6 @@
---
title: stack comments seal
sidebar_position: 52
sidebar_position: 54
---
# `stack comments seal`

View File

@@ -1,6 +1,6 @@
---
title: stack comments stats
sidebar_position: 50
sidebar_position: 52
---
# `stack comments stats`

View File

@@ -1,6 +1,6 @@
---
title: stack comments unseal
sidebar_position: 53
sidebar_position: 55
---
# `stack comments unseal`

View File

@@ -1,6 +1,6 @@
---
title: stack comments
sidebar_position: 47
sidebar_position: 49
---
# `stack comments`

View File

@@ -1,6 +1,6 @@
---
title: stack db comment
sidebar_position: 70
sidebar_position: 72
---
# `stack db comment`

View File

@@ -1,6 +1,6 @@
---
title: stack db inspect
sidebar_position: 71
sidebar_position: 73
---
# `stack db inspect`

View File

@@ -1,6 +1,6 @@
---
title: stack db
sidebar_position: 69
sidebar_position: 71
---
# `stack db`

View File

@@ -1,6 +1,6 @@
---
title: stack docs build
sidebar_position: 73
sidebar_position: 75
---
# `stack docs build`

View File

@@ -1,6 +1,6 @@
---
title: stack docs generate
sidebar_position: 75
sidebar_position: 77
---
# `stack docs generate`

View File

@@ -1,6 +1,6 @@
---
title: stack docs serve
sidebar_position: 74
sidebar_position: 76
---
# `stack docs serve`

View File

@@ -1,6 +1,6 @@
---
title: stack docs
sidebar_position: 72
sidebar_position: 74
---
# `stack docs`

View File

@@ -1,6 +1,6 @@
---
title: stack generate models
sidebar_position: 21
sidebar_position: 23
---
# `stack generate models`

View File

@@ -1,6 +1,6 @@
---
title: stack generate
sidebar_position: 20
sidebar_position: 22
---
# `stack generate`

View File

@@ -1,6 +1,6 @@
---
title: stack lake deploy
sidebar_position: 55
sidebar_position: 57
---
# `stack lake deploy`

View File

@@ -1,6 +1,6 @@
---
title: stack lake load
sidebar_position: 56
sidebar_position: 58
---
# `stack lake load`

View File

@@ -1,6 +1,6 @@
---
title: stack lake parity
sidebar_position: 58
sidebar_position: 60
---
# `stack lake parity`

View File

@@ -1,6 +1,6 @@
---
title: stack lake validate
sidebar_position: 57
sidebar_position: 59
---
# `stack lake validate`

View File

@@ -1,6 +1,6 @@
---
title: stack lake
sidebar_position: 54
sidebar_position: 56
---
# `stack lake`

View File

@@ -1,6 +1,6 @@
---
title: stack llm eval-tags
sidebar_position: 66
sidebar_position: 68
---
# `stack llm eval-tags`

View File

@@ -1,6 +1,6 @@
---
title: stack llm hosts
sidebar_position: 62
sidebar_position: 64
---
# `stack llm hosts`

View File

@@ -1,6 +1,6 @@
---
title: stack llm index
sidebar_position: 60
sidebar_position: 62
---
# `stack llm index`

View File

@@ -1,6 +1,6 @@
---
title: stack llm prune-rules
sidebar_position: 67
sidebar_position: 69
---
# `stack llm prune-rules`

View File

@@ -1,6 +1,6 @@
---
title: stack llm restamp
sidebar_position: 61
sidebar_position: 63
---
# `stack llm restamp`

View File

@@ -1,6 +1,6 @@
---
title: stack llm serve
sidebar_position: 63
sidebar_position: 65
---
# `stack llm serve`

View File

@@ -1,6 +1,6 @@
---
title: stack llm stamp-themes
sidebar_position: 68
sidebar_position: 70
---
# `stack llm stamp-themes`

View File

@@ -1,6 +1,6 @@
---
title: stack llm tag
sidebar_position: 65
sidebar_position: 67
---
# `stack llm tag`

View File

@@ -1,6 +1,6 @@
---
title: stack llm vocab
sidebar_position: 64
sidebar_position: 66
---
# `stack llm vocab`

View File

@@ -1,6 +1,6 @@
---
title: stack llm
sidebar_position: 59
sidebar_position: 61
---
# `stack llm`

View File

@@ -1,6 +1,6 @@
---
title: stack mail attach-smarthost
sidebar_position: 118
sidebar_position: 120
---
# `stack mail attach-smarthost`

View File

@@ -1,6 +1,6 @@
---
title: stack mail dkim-export
sidebar_position: 117
sidebar_position: 119
---
# `stack mail dkim-export`

View File

@@ -1,6 +1,6 @@
---
title: stack mail dns
sidebar_position: 116
sidebar_position: 118
---
# `stack mail dns`

View File

@@ -1,6 +1,6 @@
---
title: stack mail down
sidebar_position: 114
sidebar_position: 116
---
# `stack mail down`

View File

@@ -1,6 +1,6 @@
---
title: stack mail provision
sidebar_position: 112
sidebar_position: 114
---
# `stack mail provision`

View File

@@ -1,6 +1,6 @@
---
title: stack mail rotate-creds
sidebar_position: 119
sidebar_position: 121
---
# `stack mail rotate-creds`

View File

@@ -1,6 +1,6 @@
---
title: stack mail seed-mailboxes
sidebar_position: 120
sidebar_position: 122
---
# `stack mail seed-mailboxes`

View File

@@ -1,6 +1,6 @@
---
title: stack mail status
sidebar_position: 115
sidebar_position: 117
---
# `stack mail status`

View File

@@ -1,6 +1,6 @@
---
title: stack mail up
sidebar_position: 113
sidebar_position: 115
---
# `stack mail up`

View File

@@ -1,6 +1,6 @@
---
title: stack mail wire-git
sidebar_position: 121
sidebar_position: 123
---
# `stack mail wire-git`

View File

@@ -1,6 +1,6 @@
---
title: stack mail
sidebar_position: 111
sidebar_position: 113
---
# `stack mail`

View File

@@ -1,6 +1,6 @@
---
title: stack perf show
sidebar_position: 79
sidebar_position: 81
---
# `stack perf show`

View File

@@ -1,6 +1,6 @@
---
title: stack perf
sidebar_position: 78
sidebar_position: 80
---
# `stack perf`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs cpt-ingest
sidebar_position: 93
sidebar_position: 95
---
# `stack pfs cpt-ingest`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs elements
sidebar_position: 85
sidebar_position: 87
---
# `stack pfs elements`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs exposure
sidebar_position: 90
sidebar_position: 92
---
# `stack pfs exposure`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs families
sidebar_position: 87
sidebar_position: 89
---
# `stack pfs families`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs guidance
sidebar_position: 88
sidebar_position: 90
---
# `stack pfs guidance`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs lineage
sidebar_position: 86
sidebar_position: 88
---
# `stack pfs lineage`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs reaction
sidebar_position: 89
sidebar_position: 91
---
# `stack pfs reaction`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs review
sidebar_position: 92
sidebar_position: 94
---
# `stack pfs review`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs utilization
sidebar_position: 91
sidebar_position: 93
---
# `stack pfs utilization`

View File

@@ -1,6 +1,6 @@
---
title: stack pfs
sidebar_position: 84
sidebar_position: 86
---
# `stack pfs`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma eligible
sidebar_position: 105
sidebar_position: 107
---
# `stack prisma eligible`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma export
sidebar_position: 102
sidebar_position: 104
---
# `stack prisma export`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma extract
sidebar_position: 106
sidebar_position: 108
---
# `stack prisma extract`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma fetch
sidebar_position: 108
sidebar_position: 110
---
# `stack prisma fetch`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma flow
sidebar_position: 107
sidebar_position: 109
---
# `stack prisma flow`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma init
sidebar_position: 101
sidebar_position: 103
---
# `stack prisma init`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma ping-llm
sidebar_position: 103
sidebar_position: 105
---
# `stack prisma ping-llm`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma run
sidebar_position: 109
sidebar_position: 111
---
# `stack prisma run`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma screen
sidebar_position: 104
sidebar_position: 106
---
# `stack prisma screen`

View File

@@ -1,6 +1,6 @@
---
title: stack prisma vpn
sidebar_position: 110
sidebar_position: 112
---
# `stack prisma vpn`

Some files were not shown because too many files have changed in this diff Show More