IMPORTANT: After completing the task below, you MUST output a JSON object in a [code]…
- User
IMPORTANT: After completing the task below, you MUST output a JSON object in a ```json code fence at the very end of your response. Do NOT forget this — the workflow fails without it.
Implement the current Spectraplex packet.
Follow:
- CLAUDE.md
- design/SPECTRAPLEX_STRATEGY_AND_EXECUTION_PLAN.md
- design/PHASED_IMPLEMENTATION_PLAN.md
Current coordination:
- phase: Phase 3: Expand Silver Into Reusable Datasets
- work packet: P3-W6: Completeness metadata
- objective: Track dataset completeness per target and time range, expose completeness markers for downstream consumers so they can determine whether a dataset is partial, complete, or backfilling for a given target and network.
- branch: p3-w6-completeness-metadata
- stage: new packet implementation
- existing PR:
Repo touchpoints:
- core/src/v2.rs — CompletenessStatus enum and DatasetCompleteness struct
- adapters/src/v2_repo.rs — Repository CRUD methods for dataset_completeness
- migrations/ — New migration for dataset_completeness table with indexes and unique constraints
- core/src/materializer.rs — DatasetName enum (read-only reference, no changes expected)
Implementation steps:
-
- Add CompletenessStatus enum (Partial, Complete, Backfilling, Gap) with serde, strum, Default derives to core/src/v2.rs following existing enum patterns
-
- Add DatasetCompleteness struct to core/src/v2.rs with fields: id (UUID), target_id (UUID), dataset_name (String), dataset_version_id (Option), network (String), status (CompletenessStatus), coverage_start (Option), coverage_end (Option), block_start (Option), block_end (Option), last_ingestion_run_id (Option), records_count (i64), gap_ranges (Option<serde_json::Value>), notes (Option), created_at, updated_at
-
- Add migration file (next timestamp after 20260310000000) creating dataset_completeness table with UNIQUE(target_id, dataset_name, network) constraint, FK references to index_targets, dataset_versions, networks, and ingestion_runs, and indexes on target_id, dataset_name, and status
-
- Add row_to_dataset_completeness() helper in v2_repo.rs following existing row-mapping patterns
-
- Add upsert_dataset_completeness() repository method with ON CONFLICT UPDATE on the unique constraint
-
- Add get_dataset_completeness(target_id, dataset_name, network) query method
Assistant
I'll start by checking the current state of the codebase and reading the relevant files in parallel.
Assistant
Let me read the v2_repo.rs file in parts and check the existing migration structure:
Assistant
Now let me read the rest of v2_repo.rs to see the existing repository methods and the end of the file:
Assistant
Let me read the rest of the file:
Assistant
Now let me read the end of the tests section:
Assistant
Now I have a thorough understanding of the codebase patterns. Let me create the branch and implement the changes. First, let me check the existing repo.rs to understand the
Repositorystruct andpool()method:Assistant
Now let me implement all the changes. I'll start with the three files in parallel:
Assistant
Now let me add the
CompletenessStatusenum andDatasetCompletenessstruct tocore/src/v2.rs, right before the address normalization helpers:Assistant
Now add the completeness tests to the test module in
core/src/v2.rs:Assistant
Now create the migration file:
Assistant
Now add the repository code to
v2_repo.rs. I need to:- Add
CompletenessStatusandDatasetCompletenessto the import - Add SQL helper functions for
CompletenessStatus - Add
row_to_dataset_completenesshelper - Add
build_dataset_completeness_upsertquery builder - Add repository methods
- Add tests
- Add
Assistant
Now add the
CompletenessStatusSQL helpers after theDatasetVersionStatushelpers:Assistant
Now add the
row_to_dataset_completenesshelper andbuild_dataset_completeness_upsertquery builder. I'll add them after the P3-W4 query builders section:Assistant
Now add the repository methods inside the
impl Repositoryblock, after the HlPositionChanges section and before the closing}:Assistant
Now add the tests at the end of the test module in
v2_repo.rs:Assistant
Now let me run the verification commands:
Assistant
Let me fix the formatting:
Assistant
I need to add a clippy allow attribute. Let me fix that:
Assistant
Clippy passes. Now run the tests:
Assistant
All tests pass. Let me count the total:
Assistant
684 tests pass (up from 665+). Let me also verify the migration SQL is syntactically correct by checking it:
Assistant
Now let me verify the new tests are all included by grep for the test names:
Assistant
19 new completeness tests all pass. Let me now verify formatting one more time and commit:
Assistant
All three verification commands pass. Now let's create the commit:
Assistant
All verification passes:
cargo fmt --all --check✅cargo clippy --workspace --all-targets -- -D warnings✅cargo test --workspace✅ (684 total tests, 19 new completeness tests)
json