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 4: ETL-First Delivery
- work packet: P4-W3: Sink abstraction
- objective: Add a sink abstraction so export jobs can deliver dataset exports to local files, webhooks, or external databases, with object storage designed as the next extension point.
- branch: p4-w3-sink-abstraction
- stage: new packet implementation
- existing PR:
Repo touchpoints:
- core/src/materializer.rs — add SinkConfig enum, SinkType enum, ExportSink trait
- api/src/main.rs — extend ExportJobRequest with optional sink config, integrate sink delivery into export job lifecycle, add sink-specific validation
- adapters/src/v2_repo.rs — potential database-to-database sink support methods
- README.md — update API docs for sink config on POST /v1/export/dataset
- CLAUDE.md — update if any routes or CLI flags change
Implementation steps:
-
- Add SinkType enum to core/src/materializer.rs (LocalFile, Webhook, Database, with ObjectStorage reserved/documented)
-
- Add SinkConfig struct to core/src/materializer.rs with per-type config (file_path for LocalFile, url + optional headers for Webhook, connection_string + table for Database)
-
- Define an async ExportSink trait in core/src/materializer.rs with deliver(data, metadata) -> Result
-
- Implement LocalFileSink in api/src/main.rs — writes serialized export data to a specified file path with proper error handling
-
- Implement WebhookSink in api/src/main.rs — POSTs export data to a validated URL, reusing validate_callback_url() and fire_callback() patterns with proper Content-Type
-
- Implement DatabaseSink as a stub/documented design — database-to-database delivery requires external connection management, so provide the interface and config parsing with a clear TODO for runtime implementation
-
- Extend ExportJobRequest to accept an optional 'sink' field with SinkConfig
-
Assistant
I'll start by reading the current state of the codebase and key files to understand what exists before implementing.
Assistant
The api/src/main.rs is large. Let me read the relevant export sections and understand the current export job pattern.
Assistant
Now let me read the relevant sections of api/src/main.rs to understand the export job structures and lifecycle:
Assistant
Now let me read the create_export_job handler and the export job spawned task to understand the full lifecycle:
Assistant
Now let me also check the existing tests area at the end of the file for the export tests:
Assistant
Now I have a comprehensive understanding of the codebase. Let me also check what dependencies are available in
api/Cargo.tomlandcore/Cargo.toml:Assistant
Now I have a complete understanding of the codebase. Let me create the branch and implement the sink abstraction.
Assistant
Now let me implement the changes. I'll start with the core sink types in
materializer.rs:Assistant
Now let me add the sink tests to
core/src/materializer.rs:Assistant
Now add tests for the sink types at the end of the tests module:
Assistant
Now let's implement the sink implementations and integrate them into
api/src/main.rs. First, let me update the import line to include the new types:Assistant
Now add the sink implementations. Let me find a good location — right after the
validate_callback_urlfunction:Assistant
Now extend
ExportJobRequestto accept an optionalsinkfield:Assistant
Now extend
ExportJobStatusto include sink delivery fields:Assistant
Now update the
create_export_jobfunction. Let me re-read the current state of that function:Assistant
Now I need to replace the entire
create_export_jobfunction with the updated version that validates sink config and uses it:Assistant
Now I need to update all the places in tests where
ExportJobStatusis constructed to include the new fields. Let me find them:Assistant
I need to add the two new fields to all test constructions. Let me do this efficiently with multiple edits. Each
ExportJobStatusconstruction in tests needsdelivered_to: None, delivery_status: None,added:Assistant
Now the two prune test ExportJobStatus entries:
Assistant
Now let me add the new sink-specific tests at the end of the test module. Let me find the end:
Assistant
Now let's try to build and check if the code compiles:
Assistant
Two issues: 1)
async_traitcrate is not in api's dependencies (core has it but api doesn't), and 2) the lifetime mismatch is becauseasync_traitisn't resolving. Let me addasync-traitto api's Cargo.toml and also fix the unused variable:Assistant
Now fix the unused variable warning in LocalFileSink:
Assistant
Clean build. Now let's run the three verification checks:
Assistant
Formatting issues. Let me fix them:
Assistant
Now run the verification checks in parallel:
Assistant
Both pass. Now run tests:
Assistant
Let me verify the total test counts:
Assistant
All 772 tests pass (358+26+22+11+194+27+134 = 772), 0 failures. That exceeds the 737+ baseline.
Now let me update the README.md to document the sink config on POST /v1/export/dataset:
Assistant
Now let me also update the CLAUDE.md API surface section to mention the sink config. Let me check if the current CLAUDE.md needs any route changes — no routes changed, just request/response fields. The API routes are the same. Let me verify the CLAUDE.md API surface listing is still accurate:
Assistant
The routes haven't changed — no new routes were added. The CLAUDE.md API surface is still accurate. No updates needed there.
Now let's do a final verification pass to make sure everything is clean:
Assistant
All 772 tests pass, 0 failures. All checks green. Now let me commit:
Assistant