DuckVEP has two independently built hosts for DuckDB’s C APIs. The stable C API v1 host is the default build and the one the R package and distribution CI use. The v2 host uses the released DuckDB 2.0.0 SDK and its version-locked unstable API. It is an experimental build; its platform and workload qualification are separate from the v1 host.
Host and distribution boundaries
| v1 host | v2 host | |
|---|---|---|
| Extension API | v1.2.0 |
unstable v2 API, footer ABI C_STRUCT_UNSTABLE, DuckDB v2.0.0
|
| Build | make release |
make release_v2 |
| Artifact | build/release/duckvep.duckdb_extension |
build/release_v2/duckvep.duckdb_extension |
| Headers | duckdb_capi/ |
pinned duckdb_capi_v2/
|
The R package builds the v1 host and stamps it with the stable v1.2.0 footer. If an exact-version artifact is absent, the loader can select a stable-v1 artifact for the same platform. DuckDB verifies compatibility when it loads the artifact. The native v2 host is version-locked and is not used as this fallback.
host_v2/ is a separate CMake project. A v1 build does not compile or link its sources. Both hosts compile the host-neutral implementation in src/kernel/ and src/core/; the v1 adapter is in src/, and the v2 adapter is in host_v2/. The adapters translate DuckDB vectors and callbacks to the shared row logic and write host-specific results.
v2 SDK pin and ABI
duckvep-package.json pins the DuckDB 2.0.0 release revision d54cbbe3df17e8e5ce68312f483b4155836112aa and the SHA-256 values of duckdb_v2.h and duckdb_extension_v2.h. duckdb_capi_v2/REVISION records the same commit. make check-v2-sdk verifies these files. The host compiles with DUCKDB_V2_API_ALLOW_UNSTABLE=1 and DUCKDB_V2_API_ALLOW_DEPRECATED=0.
DuckDB 2.0.0 has no stable v2 extension API surface. Its unstable v2 ABI requires an extension built for the matching DuckDB version. The test runner also checks that the CLI source_id matches the pinned revision. Use scripts/stage-v2-duckdb.py to build the test CLI at that revision.
Build and gates
make release_v2
make test-extension-symbols-v2
make check-v2-footer
python3 scripts/stage-v2-duckdb.py
DUCKVEP_V2_DUCKDB=.deps-v2/duckdb-build/duckdb make test_v2
make test_v2 checks the SDK pin, builds the separate host, verifies that the binary exports only duckvep_init_c_api_v2 and imports no duckdb_* symbols, and checks the C_STRUCT_UNSTABLE / v2.0.0 footer. The static gate checks the permitted API symbols and confirms that src/core/ and src/kernel/ contain no DuckDB API calls.
The runtime suite tests repeated LOAD on writable and read-only databases, with no catalog DDL or database-file changes; v2-only SQL assertions; model and budget behavior; and the recorded cases in test/sql_v2/equality_golden.json.gz (gzip). The golden records v1 results. When build/release/duckvep.duckdb_extension exists, the runner also checks those results against the live v1 extension. test/sql_v2/README.md documents the SQL and the separate whole-HG002 check.
Release preflight
The release checklist covers biological evidence, CRAN, citation metadata, and distribution. Stable-v1 remains the default host on DuckDB 2.0.
make check-v2-release-selftest runs offline negative controls. A release admission uses make check-v2-release-preflight with concrete arguments for the extension, pinned CLI, R library, and completed HG002 output directory. The preflight checks the SDK manifest and headers, the actual extension footer and load, runtime and source revisions, and the complete hashed HG002 comparison receipt. It contacts GitHub and CRAN only with explicit --live-status. The current experimental manifest is blocked from release admission; the command can emit READY_TO_QUALIFY when upstream versions are visible but qualification artifacts are incomplete. Details and the required invocation are in test/sql_v2/release-readiness.md.
LOAD registers the native functions without executing SQL or creating persistent catalog objects. The read-only database test covers this contract.
Geometry, repeat/phase, SQL-builder, annotation, coding-discovery and resource-control functions retain their v1 SQL names. The model and haplotype query workflows use v2-specific load builders; the workflow differences are described below. duckvep_model_drop, duckvep_model_save and duckvep_model_restore retain their v1 names.
Ownership, borrowed data and concurrency
The v2 callback’s error-info handle is borrowed. Each fallible API call returns its own detail handle; the adapter copies the error into the callback handle and destroys the detail. Input vector views and VARCHAR payloads are borrowed from the execution chunk and are valid only during that call. Core haplotype row views remain valid until the host fetches the next input row.
Vector resizing can invalidate data and validity pointers. The adapter reacquires them after vector_set_size; nested child pointers are taken after sizing their vectors. Dictionary reads can flatten an aliased child, so load_views takes the returned views twice and uses the second set. Returned owned logical-type, value and error-detail handles are destroyed by their owner.
Registration user data carries destructors and reference counts. The model registry is mutex-protected; table-function scans pin model entries for the duration of use, so a pinned entry remains alive while a scan reads it. Annotation builders capture a numeric model generation once per query. Each annotation chunk pins the model and checks that generation. A drop or reload before a later chunk is an error. Completed chunks retain their original results. Model names remain literal strings; generations are separate arguments. Staged model relations and haplotype jobs are shared state protected by the v2 host’s mutex. Cursor-bearing scans (duckvep_so_terms, haplotype scan and record-plan scan, and duckvep_coding_calls) set their global table-function state to one thread. Annotation workers use the shared process-wide native budget and worker limits.
Model loading
The v1 duckvep_model_load(name, regions_query, transcripts_query, exons_query, ...) executes query strings on its private connection in a transaction. It sees committed permanent relations, not the caller’s TEMP tables or uncommitted rows.
The v2 host cannot execute SQL on a private connection inside a callback. duckvep_model_load_sql returns ordered caller-side statements: a COPY ... TO 'duckvep_stage' for each supplied relation, followed by duckvep_model_publish. The caller executes the statements in order and in its own session. The three required relations are regions, transcripts and exons; mature miRNA, peptide edits and interval features are optional. Queries must return the expected typed columns in the required order, and the COPY preserves row order.
SELECT unnest(duckvep_model_load_sql(
'my_model', 'SELECT ...', 'SELECT ...', 'SELECT ...'));
-- Execute each returned statement in order, including the COPY statements and publish call.
For v2, TEMP tables and uncommitted rows visible to the caller’s COPY can supply the model. Staged rows use DuckDB-managed column collections and can spill under DuckDB’s memory limit. Model arrays and indexes use DuckVEP’s native-memory budget.
Each duckvep_model_load_sql invocation generates a separate load key. Its COPY statements use the literal MODEL name, LOAD_KEY, and RELATION. Publish receives the key in its load_key option. A completed COPY atomically replaces only the matching model/key/relation. A failed COPY publishes no replacement relation. Publish detaches all of that key’s model relations together and consumes them on success or failure. It does not remove another key’s staged relations. Installed model names remain unique: publishing a model whose name already exists fails.
A caller can supply load_key in the builder’s options to manage cleanup. Keys must be nonempty strings without NUL bytes. Execute each key’s COPY statements sequentially; do not reuse one key concurrently. After a failed or abandoned script has stopped, call duckvep_model_stage_discard(name, load_key). This idempotent function returns true and removes only that key’s staged model relations. It does not drop an installed model or cancel a running COPY. The R model wrapper performs this cleanup on exit.
-- After a stopped script created with load_key := 'attempt-1':
SELECT duckvep_model_stage_discard('my_model', 'attempt-1');
Manual COPY statements without LOAD_KEY pair with duckvep_model_publish(name). Serialize each complete unkeyed workflow for a model name. duckvep_model_drop releases an installed model and unkeyed model stages, but preserves keyed loads and haplotype jobs. Haplotype jobs do not accept LOAD_KEY; use distinct job names or serialize each complete job workflow.
Validation uses the same core loaders as v1. Model installation is extension state, not SQL transaction state. A surrounding transaction rollback does not remove a published model on either host. Use duckvep_model_drop to release it.
The visible workflow differs by host: v1 performs loading in one table-function call; v2 returns SQL for the caller to run and then publishes the staged rows. Validation uses the shared core loaders. duckvep_model_save and duckvep_model_restore use the shared snapshot implementation on both hosts.
Haplotype input
The v1 duckvep_haplotypes(calls_query, model, ...) executes and normalizes its query on a private connection. On v2, duckvep_haplotype_load_sql returns caller-side normalization and staging statements; run them in order, then read duckvep_haplotype_scan(job). The scan replays the captured rows through src/core/duckvep_core_haplotypes.c, the same core used by v1. With input_mode = 'source_records', set phase_policy = 'vep_compat'; the builder returns four ordered statements for raw input, record-plan staging, normalized-call staging and cleanup. Complete original diploid calls with at most one original REF/ALT heterozygote and homozygous background can prove raw coding paths without altering their compatibility CDS/protein; hypothetical or unproven carriers are kept in separate qualification rows. Omitted non-diploid REF calls prevent that proof and consume bounded carrier state. A job scan consumes the job once and releases it at completion or error; use duckvep_haplotype_drop to discard a staged job that will not be scanned.
The v2 scan preserves v1 haplotype semantics, the public 36-column relation and the 32-argument scalar bridge. Its bounded final-RNA profile requires complete RNA, one exon per edit and no internal splice-edge edit; coding-transcript edits must remain within one UTR. It compares RNA case-insensitively without changing stored model bytes. Structural variants and empty-ALT source records retain their separate admission rules.
The staging collections are DuckDB-managed and governed by DuckDB’s memory limit, not the native-memory budget. The scan’s workspace and core allocations use the shared native budget. duckvep_coding_calls uses the same budget for its HTSlib reader and discovery workspace.
Haplotype arrangements
duckvep_haplotype_arrangements(calls_query, model, ...) on v1 normalizes and replays strict diploid calls on its private query connection. It therefore sees committed permanent relations, but not caller TEMP relations or uncommitted rows. On v2, call duckvep_haplotype_arrangements_load_sql(calls_query, model, job [, options]), execute its single returned caller-side COPY, then query duckvep_haplotype_arrangements(job). The staged query uses the same shared strict normalization recipe as v1 and preserves event IDs, REF/ALT values, both original alleles, phase_before, and phase_set.
The v2 arrangement job is consumed once. The scan fully validates and charges the native arrangement workspace before returning an output row, then releases its cursor and staged collection. A failed or cancelled COPY publishes no job. Arrangement limits are accepted in the loader’s optional options struct: max_sites, max_calls, max_arrangements, and max_replays; zero, invalid, and over-capacity values are rejected before a job is published. CALLED is not evidence of cis phase: unphased calls produce bounded hypotheses, while only observed phase metadata constrains the lanes.
Whole-HG002 parity measurement
The receipt at benchmarks/data/v2_hg002/d4833a5/ records a run measured on 2026-11-19 with the 2.0.0 release candidate at d4833a5, v1 DuckDB source 7dbb2e646f, and the released DuckDB v2.0.0 source d54cbbe3df17e8e5ce68312f483b4155836112aa. The run used one thread on CPU 4 and an 8 GB DuckDB memory limit.
Both hosts produced 158,137 rows. Schema and the complete nested row multiset matched by bidirectional EXCEPT ALL. The model fingerprint was 8650913055114199712 on each host. Native-memory high-water stayed below 4 GiB, with zero capacity refusals. Peak RSS was 4,038,968 KiB (3.85 GiB) on v1 and 4,689,272 KiB (4.47 GiB) on v2. The v2 capture collections are DuckDB-managed and outside the native budget. Wall times were 10.07 s on v1 and 9.72 s on v2; these values are descriptive rather than a throughput qualification.
The receipt includes hashes, schemas, budget snapshots, inputs and outputs’ provenance. scripts/check_v2_hg002.sh --help describes the reproduction inputs and options. The full-data run is separate from make test_v2.