Sync Behavior & Dashboard
Sync Behavior
ODK sync is the process by which DigitVA downloads Verbal Autopsy submissions from ODK Central, enriches them with metadata, syncs attachments, runs SmartVA analysis, and prepares submissions for coding. The sync pipeline is driven by Celery background tasks on a configurable schedule.
Three-Phase Pipeline
For each mapped form, the sync pipeline runs three sequential phases:
| Phase | Description |
|---|---|
| 1. Incremental Sync | Runs an OData filter-gated delta check against ODK Central. If submissions have changed since the last sync, downloads and upserts them locally. If no changes are detected, runs a gap check to catch submissions missed by earlier failed syncs. All submissions from ODK are stored regardless of consent value. |
| 2. SmartVA Generation |
Prepares a SmartVA input CSV from the current active payload versions, runs the SmartVA analysis subprocess, and stores cause-of-death predictions in va_smartva_results. SmartVA runs per-form after that form's Phase 1 completes.
|
| 3. Coding Readiness |
Submissions with valid consent transition through attachment_sync_pending and smartva_pending to ready_for_coding only after both attachment syncing and SmartVA are complete for the current payload. Submissions without valid consent are stored but routed to consent_refused.
|
Celery Beat Schedule
Sync is driven by Celery Beat using a PostgreSQL-backed scheduler. The default schedule includes:
| Task | Default Schedule | Purpose |
|---|---|---|
| Full ODK Sync | Every 6 hours | Downloads and upserts changed submissions across all active form mappings. |
| Submission Analytics MV Refresh | Every 1 hour | Refreshes the submission analytics materialized view for dashboard reporting. |
The sync schedule can be changed from the admin sync dashboard without restarting services. The dashboard offers 1, 2, 4, 6, 12, 24 or 48 hours; the API accepts any whole number from 1 to 168 hours.
Delta Check
Before fetching submission data, the sync runs a lightweight OData count query:
- If
last_synced_atis NULL (first-ever sync), all submissions are downloaded. - If the delta count is zero, a gap check compares ODK instance IDs against local rows to catch any missing submissions.
- If the delta count is greater than zero, changed submissions are fetched via paginated OData JSON (250 per page).
A snapshot_time is captured before any ODK calls, and
last_synced_at is set to that snapshot time after success. This
ensures submissions arriving mid-run are caught on the next sync.
Language Normalization
During upsert, raw ODK language values (from the narr_language or
language field) are normalized to canonical codes using the
map_language_aliases table. For example, "Bengali", "bn", and
"bengali" all normalize to "bangla". Unknown values pass through unchanged
and appear in the admin Languages panel unmapped alert for manual resolution.
Sync Dashboard
The admin sync dashboard at /admin/panels/sync provides real-time
visibility and operational controls:
| Section | Description |
|---|---|
| Status Bar | Shows the last run outcome. Auto-refreshes every 30 seconds (every 5 seconds while a run is active). |
| Sync Now | Triggers a full sync. Returns 409 if a run is already in progress. |
| Stop | Shown only while a sync run is active. Sends a revoke/terminate signal to the Celery task and marks the run as cancelled. |
| Schedule Configurator | Change the sync interval (1, 2, 4, 6, 12, 24 or 48 hours) without restarting services. |
| Coverage Table | Compares ODK totals against local totals per site mapping. Loaded on demand, not automatically. Includes per-form Force-resync buttons. |
| Form Repair Coverage | Shows project/site/form completeness for local data, metadata, attachments, and SmartVA. Includes per-form Repair triggers for targeted gap fixing. |
| Legacy Attachment Rows | Reports attachment rows with missing storage names and provides a dedicated Repair trigger. |
| Progress Log | Live timestamped entries. Clears when a new run starts. |
| Run History | Last 20 runs with duration, trigger source, status, and error details. |
On-Demand Coverage
Per-Form Backfill
The Repair button in the Form Repair coverage table triggers a targeted backfill for one form. This is distinct from Force-resync:
- Fetches ODK instance IDs for the selected form.
- Backfills only missing thin local submissions.
- Revalidates the current ODK payload for each repair candidate.
- Repairs metadata enrichment, attachment sync, legacy attachment-row migration, and SmartVA gaps.
- Protected submissions whose ODK payload changed follow the
finalized_upstream_changedpath rather than ordinary repair.
Repair Coverage Categories
The Form Repair Coverage table shows per-form completeness across five categories. Each category has explicit completeness logic:
| Category | Complete When |
|---|---|
| Metadata | All 8 fields present: summary, category list, form version, device ID, submitter ID, instance ID, attachments expected, attachments present. |
| Attachments | Present file count meets or exceeds expected count, and no legacy rows remain. audit.csv is excluded from the file count. |
| Audit | audit.csv present on disk (informational only — does not block completeness). |
| Legacy | All ODK-backed attachment rows have been migrated to opaque storage names (no storage_name IS NULL rows remain). |
| SmartVA | Active SmartVA result exists for the current payload version with a non-empty cause of death prediction. |
Repair Iteration Flow
When you click Repair on a form, the system follows a structured batch flow:
- Fetch ODK instance IDs for the selected form and backfill missing thin local rows (batches of 50).
- Build a repair map identifying which submissions have gaps in metadata, attachments, or SmartVA.
- Process submissions in batches of 5. For each submission:
- Build repair map — if no gaps, skip.
- Fetch current ODK payload and enrich metadata → commit.
- If the upstream payload changed on a protected submission, stop (transition to
finalized_upstream_changed). - Download missing attachments and migrate legacy rows → commit.
- Advance workflow state if attachments are now complete → commit.
- After each batch, collect submissions still needing SmartVA and run SmartVA once per form → commit.
payload-backfill enrich command runs. All entrypoints share the
same canonical per-submission repair engine.
Force-Resync
The Force-resync button in the Coverage table bypasses the delta check entirely and redownloads all submissions for that form. Use this when a form's data is suspected to be out of sync or when a previous sync run reported partial failure.
Attachment Backfill
A separate attachment-cache backfill trigger repairs only missing local attachment files for already-stored submissions. This does not re-fetch submission data from ODK; it only downloads attachment binaries that are absent from local storage.
Stop Control
While a sync run is in progress, the dashboard shows a Stop button. Activating it:
- Sends a revoke request with termination enabled to the running Celery task.
- Marks the corresponding
va_sync_runsrow ascancelled. - Cancelled runs remain visible in sync history and status views.
The Stop control applies to all sync types: full sync, SmartVA-only sync, single-form sync, and single-submission sync. The Sync button remains disabled while any run is active.
Protected Finalized Submissions
Submissions in protected workflow states are not automatically refreshed by sync:
coder_finalizedreviewer_eligiblereviewer_coding_in_progressreviewer_finalizedfinalized_upstream_changedclosed(legacy compatibility)
When ODK data changes for a protected submission, the sync:
- Does not destroy existing coding artifacts.
- Transitions the submission to
finalized_upstream_changed. - Creates a pending upstream payload version.
- Records a durable upstream-change snapshot.
- Creates notifications for data managers and admins.
A data manager or admin must then review the changes and choose to either Accept and Recode (promote the new payload, rerun SmartVA, return to coding) or Keep Current ICD Decision (promote the new payload while preserving the current COD and rebinding SmartVA).
Connection Health Alerts
The sync dashboard status card shows active ODK connection cooldowns and recent retryable failures. These alerts are informational and help explain why coverage loads, per-form syncs, or other live ODK actions may fail fast. The alerts do not trigger additional live ODK calls.
Sync Run History
Every sync run is recorded in va_sync_runs with the following
statuses:
| Status | Meaning |
|---|---|
running |
Sync is in progress. |
success |
All forms succeeded or were delta-skipped. |
partial |
At least one form failed and at least one succeeded. |
error |
Task crashed or all forms failed. |
cancelled |
Operator stopped the run from the dashboard. |
Manual Sync Triggers
In addition to the scheduled sync, administrators and data managers can trigger targeted syncs:
| Action | Endpoint | Who |
|---|---|---|
| Full sync | POST /admin/api/sync/trigger |
Admin |
| Per-form force-resync | POST /admin/api/sync/form/<form_id> |
Admin |
| Per-form backfill | POST /admin/api/sync/backfill/form/<form_id> |
Admin |
| Data manager single-form sync | POST /api/v1/data-management/forms/<form_id>/sync |
Data Manager (scoped) |
| Data manager single-submission refresh | POST /api/v1/data-management/submissions/<va_sid>/sync |
Data Manager (scoped) |