Skip to content

feat(extract): Salesforce Bulk API 2.0 extract job to Parquet (#512) - #873

Merged
athvin merged 7 commits into
mainfrom
issue/512-salesforce-extract
Nov 8, 2026
Merged

athvin merged 7 commits into
mainfrom
issue/512-salesforce-extract

Conversation

@athvin

@athvin athvin commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #512

🚧 Claimed by an agent session — 2026-11-08T14:35:08Z, session 93a44611-348c-4819-b503-ac48b5acd076 on Mac.
The claim is this open draft PR: closing it releases the ticket.

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

What

The Salesforce side of E2: a salesforce_connection resource (org-scoped, admin),
a sf_extract_cursor watermark, a new extract job kind whose pod task pulls an
sObject through Bulk API 2.0 (client-credentials flow) and lands the result as a
CSV delivery in the dataset's drop_root, where the existing Ingest task and
the rest of the incremental pipeline take over. The Bulk API client is
er-server/src/salesforce.rs (the s3_ingest.rs shape), proven against a local
mock server in tests/salesforce_mock.rs.

Why

Issue #512's remaining gap is extraction only: "Our ingestion reads S3 and CSV,
not an org." Bulk API 2.0 query results are already CSV, so the extract job is a
pure producer at the edge of an unchanged engine — exactly the connector contract
in connectors.md §1.

Proof

make check green locally (exit 0) in the worktree, rebased onto b3e35e46;
post-rebase, the byte gates were re-proven (mcp_manifest, response_envelopes,
er-entity verify: "145 generated files are current … every statement plans",
make skills-check ok). The pg family ran for real against a dedicated
Postgres: pg_connections … 1 passed under ER_TEST_PG_DSN (port 5477), and
salesforce_mock … 3 passed. Two gate mutations were observed failing: a 201
echoing client_secret, and a broken cross-page watermark max.

Risk & rollback

New job kind + new entities are additive; no existing DAG, route or schema
changes shape. git revert <merge-sha> rolls back cleanly (the reconciler only
ever adds the two new tables).

Post-merge ledger

Closed by: agent · session 93a44611-348c-4819-b503-ac48b5acd076 on Mac · 2026-11-08T16:50:00Z

  • main is green with this change on it — merge SHA b4186c34;
    rust run 42498531096 success on that SHA itself, with frontend,
    infra and devcontainer green beside it and zero non-success
    completed runs on main through the watch.
  • images built — run 42498531095 success; er-api resolved to
    sha256:a3d9483f… and er-web to sha256:84962bcd… from b4186c34.
  • deploy converged — run 42500136096: the NEW colour's pod (the
    a3d9483f… image) answered er-api-preview /readyz -> 200 before the
    flip — a line the booted process emitted, and readiness requires
    ensure_schema to have reconciled the two new tables — then Cut over
    and Retire the old colour both succeeded.
  • the push-only surface no pull request can pre-test — deploy
    success (above), drift latest run success, kind latest run success.
  • the board card reached Done through the automation (read back
    from the board), and E2 — Dataset model and extraction to DuckDB #512 closed COMPLETED by the merge.
  • follow-ups are open for everything deferred here — feat(ui): Salesforce connections settings surface and extract exposure #879 (connections
    UI), feat(extract): deletion propagation — getDeleted poll and a full-refresh landing mode #880 (deletion propagation), test(extract): executor-harness e2e of the extract DAG against a mock Salesforce #881 (extract-DAG e2e).
  • what was learned is written down — connectors.md §4.1 (what is
    built, the client-credentials deviation, the deletions gap) and
    backend-design's phase-3 ledger updated in this PR; the DATASET_SCOPED
    rule (a NOT NULL dataset_id on a new entity must join fixup 0004 or
    the aged-store tests fail) is written at the list itself in fixups.rs,
    plus session memory salesforce-extract-shipped.

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  1. Entities. entities/salesforce_connection/ — org-scoped (webhook
    shape: org_id NOT NULL + V15 index), columns name, instance_url,
    auth_kind (client_credentials v1), client_id, client_secret,
    api_version, is_active. No history: true — the history trigger
    copies whole rows as jsonb, which would duplicate the secret into an
    append-only side table. languages: [rust] only — no TS binding and no JSON
    wire, so the secret cannot reach openapi.json/bindings (the Column visibility: visibility:internal in entity.yaml, generated wire structs, V18 lint #858 defect
    class). Statements: create/create, read/list_active (projection drops
    the secret in pg.rs), read/by_id (with secret — work-order resolution
    only), update/deactivate (soft, the webhook rule).
    entities/sf_extract_cursor/ — the s3_ingest_cursor shape:
    natural_key [dataset_id, source], the watermark as verbatim Salesforce
    ISO text (so it round-trips into the next SOQL literal unchanged),
    create/advance upsert (COALESCE keeps the mark on a full refresh) +
    read/get.
  2. The Bulk API client (er-server/src/salesforce.rs). Token fetch (OAuth client-credentials), Bulk
    API 2.0 query job lifecycle (create → poll → paged CSV results via
    Sforce-Locator), SOQL builder (fields from the source spec's declared
    columns; SystemModstamp > $watermark; IsConverted = false for Lead when
    asked — spec unit 1.26; user WHERE passthrough — unit 1.2). reqwest with
    redirect::Policy::none() + timeouts (the webhook::client() discipline).
    Unit tests against a local mock HTTP server: auth, paging, retryable vs
    terminal error mapping.
  3. Control plane. Routes: POST/GET /v1/orgs/{org}/connections +
    DELETE /v1/orgs/{org}/connections/{id} (admin; urlguard::check on
    instance_url — SSRF); POST /v1/orgs/{org}/datasets/{ds}/extract
    (steward+, enqueues extract with params {connection_id, object, source, mode, where?, exclude_converted_leads?} parsed by a shared
    extract_params.rs, the profile_params pattern). Audit rows carry ids and
    instance_url, never the secret.
  4. Job kind. JobKind::Extract (ALL → 12), a two-node DAG:
    extract (pod — the pull and the staged-rename publish into drop_root;
    no lake open, so no reconcile_schema) → advance_sf_cursor (control —
    enqueues run_all_incremental on an idempotency key, audits, emits
    import.received, then advances the watermark; the s3-ingest
    publish-then-advance ordering). Work order gains a #[serde(default)]
    connection field resolved server-side in attempt_work_order (the
    models precedent — pods cannot read Postgres), URL-guard re-checked per
    attempt. SCHEDULABLE_KINDS → 8, with extract schedule params validated at
    create.
  5. Gates the change must feed: dag_assembly, dag_task_coverage
    (variant() arm), dispatch_coverage, mcp_manifest + response_envelopes
    • openapi.json regen, egress_guard (no bare Client::new()),
      entities regen (er-entity verify), tests registered in tests/main.rs.
  6. pg family test pg_connections.rs (one test per file): CRUD + role
    enforcement + cross-org 404 + secret never in list body or audit detail +
    urlguard refusal observed failing.
  7. Skills. connectors.md §4: record what is now built and the
    deliberate deviation — v1 auth is OAuth client-credentials, not the
    web-server flow the doc sketched (no redirect URI, no refresh token, no user
    interaction; right shape for a headless extract job).
  8. make check green; PR ready; /land-pr.

Discoveries

  • The existing ingest path is CSV end-to-end (s3_ingest::classify rejects
    non-.csv; find_deliveries globs {source}.csv; land_base_delivery is a
    csv::Reader). Bulk API 2.0 results are CSV — so the extract job lands CSV
    deliveries and no ingestion change is needed. The epic's "Parquet per
    object" is satisfied downstream: DuckLake materialises raw_records as
    Parquet on object storage.
  • A job pod holds no Postgres credential (er-dag/src/task.rs:320-326); the
    Salesforce credential must ride the work order, resolved server-side —
    three precedents (lake_env, models, labels).
  • There is no secret store in the Rust control plane; webhook.secret is the
    plaintext-column precedent. history: true would leak the secret into
    *_history — so the connection entity does not set it.
  • connectors.md §4 designed the web-server OAuth flow; a headless extract job
    wants client-credentials. Recorded as a deviation, not silently diverged.
  • Deletions do not propagate on any path today: stage_ingest passes
    full_refresh: false unconditionally, so even a full-mode extract upserts
    rather than tombstones. Recorded in connectors.md §4.1; getDeleted + a
    full-refresh landing mode are one follow-up ticket (filed at merge).
  • Two mutation tests run per the house rule: the 201 echoing client_secret
    fails pg_connections naming the body, and breaking the cross-page
    watermark max fails salesforce_mock. Both reverted.

Measurements

Files

The org-scoped credential a Salesforce extract authenticates with (webhook
plaintext-secret discipline, deliberately no history trigger) and the
per-(dataset, source) SystemModstamp high-water mark (the s3_ingest_cursor
shape for an API-polled provider).
A pod task pulls one sObject (client-credentials auth, SOQL built from the
source's declared columns, SystemModstamp watermark, converted leads excluded
for Lead per spec 1.26) and stages the result as an ordinary drop-root CSV
delivery; a control task enqueues the incremental run and advances the
cursor, publish-then-advance like the S3 poller. The credential rides the
work order, resolved server-side and URL-guard re-checked per attempt.
Routes: connections CRUD (admin, secret never listed or echoed) and
POST .../extract (steward), both validated by the shared params parser.
…ange touches

pg_connections proves the role gates, the URL-guard refusals, that the secret
never appears in a 201, a listing or an audit row (mutation-tested), every
extract 422-before-queueing, the 202 enqueue, schedule param validation and
the idempotent soft delete. connectors.md §4.1 records what is now built and
the client-credentials deviation; backend-design's phase-3 ledger stops
claiming no connector ships; generated references regenerated.
@athvin
athvin force-pushed the issue/512-salesforce-extract branch from 8da7aa1 to c85647f Compare November 8, 2026 15:40
@athvin
athvin marked this pull request as ready for review November 8, 2026 15:40
pg_schema_replay/pg_schema_race age a store by dropping dataset_id from every
table that carries one; a NOT NULL dataset_id only heals through
0004_dataset_id_required (the reconciler rightly refuses to add it as
Breaking), so the new table joins DATASET_SCOPED with required=true. Both
tests reproduced red in CI and green locally with this.
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.

E2 — Dataset model and extraction to DuckDB

2 participants