Skip to content

feat(api): bulk export — an async, snapshot-pinned, tenant-scoped artifact (#1230) - #1239

Merged
athvin merged 10 commits into
mainfrom
issue/1230-bulk-export
Nov 25, 2026
Merged

athvin merged 10 commits into
mainfrom
issue/1230-bulk-export

Conversation

@athvin

@athvin athvin commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #1230

🚧 Claimed by an agent session — 2026-11-25T18:31:06Z, session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on brians-MacBook-Pro.
The claim is this open draft PR: closing it releases the claim.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

Bulk export of a dataset's results at one pinned snapshot:

  • POST …/exports (steward+) takes {kind: golden|duplicates, format: csv|jsonl, snapshot?}. It pins the snapshot through E11.2 — Run-to-snapshot identity, explicit snapshot reads #1229's pin_requested, enqueues job kind export, audits export.create, and returns {export_id, snapshot, state}.
  • GET …/exports/{id} (viewer+) returns the job read back: state, kind, format, snapshot, rows, error_class, expires_at.
  • GET …/exports/{id}/download (viewer+) streams the artifact with its media type and Content-Disposition. It is a 409 until the export succeeds and a 410 after seven days or once swept.
  • The export is the job: export_id is the job id. No new table: the job row already holds state, params, error and timestamps.
  • The pod task export is read-only and has no reconcile_schema. It pages the declared, snapshot-pinned golden and duplicates reads, so it adds no new SQL. It writes <lake>/exports/<id>.<ext> beside the data directory, never inside it, where DuckLake's orphan cleanup would delete it. The file is written .partial and then renamed. A 1M-row ceiling fails loudly, never truncates.
  • lake_maintain sweeps expired artifacts and .partial files dead for a day.
  • A new file envelope class documents the download as text/csv | application/x-ndjson. MCP never offers the download: an agent gets the status, not a million rows.

Why

#1230, part of #521. A customer needs the whole result set, consistent with one run, without paging the API.

Proof

make check: 1,189 passed, 0 failed. er-server + er-cli --tests against Postgres with DEDUPE_E2E_DUCKLAKE=1: 497 passed. make frontend: 964 passed.

The gates caught three things on the way, each fixed in its own commit:

  • every_pod_task_has_an_explicit_route: an export routes embedded, not DuckFleet-qualified;
  • the /docs/api grouping test: exports belong under Results;
  • the generated gates.md and developer reference.

Every test added here was observed failing first.

  • export_write.rs (real lake), page size 2:
    • golden CSV at run R after R+1 committed: 4 rows and one header across page boundaries;
    • golden JSONL at the latest: 5;
    • duplicates JSONL: 3 groups with their members;
    • an empty lake exports zero rows. This test first caught it as a hard Catalog Error;
    • the ceiling fails by name and leaves no file and no .partial.
  • pg_exports.rs (router, Postgres and a lake):
    • a viewer's POST is 403, and duplicates as CSV is 422;
    • the snapshot pinned equals the latest, and the audit row exists;
    • download is 409 while queued;
    • another dataset's route, another org's key and another org's route are all 404;
    • after success, the download streams a header plus 10 rows with its media type;
    • 8 days later it is 410.
  • exports units: request parsing (unknown fields refused), the path beside the data directory, an S3 lake refused, a path-shaped id refused, and the sweep removing only the expired.
  • a_file_download_is_never_offered (er-mcp), and the envelope classifier's File case.
Mutation Caught by
the export not scoped to its dataset pg_exports: /datasets/second/exports/{id} was not 404
expiry never checked pg_exports: 410 expected
a viewer may create pg_exports: 403 expected

Risk & rollback

Additive: three new routes and one new job kind. lake_maintain gains a file sweep of <lake>/exports/ only. The one shared-type change is DatasetDetail: Clone. Rollback: git revert <merge-sha>. Export jobs already queued would then fail to parse their kind, which is a terminal config failure.

Post-merge ledger

Closed by: agent · session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac · 2026-11-25T19:37:01Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

Design change from the ticket: an authenticated streamed download, not a presigned URL. Probed 2026-11-25:

  • the er-api pod has no S3 grant (envs/*/pod_identity.tf: SES, plus Bedrock in dev);
  • only the two isolation-probe orgs are S3-enrolled (tenant-runners.json), and every other tenant's lake is on EFS, which the API pod mounts;
  • duckfleet_artifacts.rs already states the policy "signed URLs never travel in query responses".

Presigning would need a new er-api read grant across tenant prefixes, a cross-tenant blast radius, to serve a URL the guard cannot see. Streaming through er-server keeps the org guard on every byte.

  1. Declared COPY … TO statements under entities/golden_record/read/ and entities/acct_golden_record/read/ (and duplicate membership), taking snapshot and a target path. Hand-written lake SQL is forbidden in er-server, and read/ accepts COPY.
  2. JobKind::Export, shaped like profile: one pod task (ExportResults) writing <lake root>/exports/<export_id>.<parquet|csv>, params parsed by a shared export_params.rs. The snapshot is pinned at enqueue (E11.2 — Run-to-snapshot identity, explicit snapshot reads #1229's pin_requested).
  3. POST …/exports (steward+) enqueues and returns {export_id, snapshot, status}. GET …/exports/{id} returns status, row count, snapshot, kind, format, expires_at. GET …/exports/{id}/download streams the file. Cross-org → 404.
  4. Bounds and expiry: a row ceiling per export; artifacts expire after 7 days (a default, recorded in the API docs), enforced on read (410 after expiry) and swept by lake_maintain.
  5. An audit row per export, trace-joined.
  6. Tests: an empty dataset, more than one page, a failed export (job.failed), a concurrent newer run (the export stays on its snapshot), cross-dataset and cross-org refused, and an expired export as 410.
  7. S3-enrolled tenants: the API pod cannot read their prefix, so download answers 501 with a detail naming why. Lifting that is a filed follow-up (er-api scoped read), not hidden here.

Discoveries

Measurements

Files

bmoore813 and others added 7 commits November 25, 2026 10:48
…d three routes (#1230)

POST …/exports pins a snapshot and enqueues kind export; one read-only pod
task pages the declared golden or duplicates reads at that snapshot into one
CSV or JSON Lines artifact beside the lake (written .partial, then renamed;
a 1M-row ceiling fails loudly). GET …/exports/{id} reads the job back;
…/download streams the file behind the org guard (409 until succeeded, 410
after seven days). No presigned URL: the API pod has no S3 grant, and an
S3-backed lake is refused at enqueue. A File envelope class documents the
download; MCP never offers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… lake is zero rows (#1230)

export_write.rs: golden CSV across a page boundary with one header, at R
after R+1 committed; golden JSONL at the latest; duplicates JSONL; a lake no
run has finished in exports zero rows rather than failing (found by this
test); the row ceiling fails by name and leaves no file or .partial.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

@athvin
athvin marked this pull request as ready for review November 25, 2026 19:19
@athvin
athvin merged commit c185fbf into main Nov 25, 2026
44 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 25, 2026 19:24 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — 47c4f9ec Deployed Nov 25, 2026 by athvin via remove closed PR previews #56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E11.3 — Bulk export: async artifact with expiry, tenant-scoped

2 participants