Skip to content

feat(writeback): apply approved Salesforce upserts through a journal (#998) - #1324

Merged
athvin merged 1 commit into
mainfrom
feat/998-upserts
Nov 27, 2026
Merged

athvin merged 1 commit into
mainfrom
feat/998-upserts

Conversation

@athvin

@athvin athvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #998

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

Upsert policies, upsert previews materialized by the existing preview job, review (batch decide + the writeback page's Upserts section), the journaled upsert_apply job with read-back reconciliation, and convergence by an always-match assertion. Entities upsert_policy, upsert_preview, upsert_apply; connectors.md §4.3.5.

#998: the last E9 writeback mode — upserting golden records Salesforce does not have yet, with the same authorization, staleness, journal and review as merges.

Proof

  • pg_upsert_apply against a mock Salesforce: a create (preimage = null, a new id, and the always-match assertion webforms:<entity> ↔ sfdc:<new id> staged); an update (preimage holds the old value); a record modified after the proposal → skipped_stale, never written; an upsert that landed but answered 500 → left in flight, then created "verified by reading the record back" with no second write and no duplicate record; a refusal → failed with the code. Policy validation (role, object, golden attribute, Id never writable); batch decide reports a stale fingerprint per item; apply 409 with nothing approved.
  • pg_merge_preview_dag (real DuckLake pipeline): with an upsert policy on webforms, the webforms-only entities are proposed keyed by their entity id with only allowlisted, non-null golden fields; the entity already synced from Contact is not proposed (it is the merge preview).
  • Playwright writeback.spec.ts: a steward approves a proposed upsert; an admin applies.
  • make check exit 0; Postgres suite 161 passed; make frontend green (vitest 1139, Playwright 1110).

Risk & rollback

Opt-in per (connection, object) and per source; nothing is written until an admin applies approved upserts. git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:24d16c2e-fec6-49d8-9797-060338df4848 on brians-MacBook-Pro · 2026-11-27T09:58:37Z

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not: — 3ec5d1f, rust 45971243621 + frontend 45971243538 success
  • images built, or correctly never ran because nothing that goes into
    an image changed: — success, run 45971243513
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: — run 45971807456 success; the live process serves the new route: https://dupezero.com/api/openapi lists /upsert-previews/apply
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change: — infra, devcontainer, marketing preview all success on 3ec5d1f
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: — E9: Apply approved upserts through the writeback journal #998 CLOSED by feat(writeback): apply approved Salesforce upserts through a journal (#998) #1324 via automation
  • follow-ups are open for everything deferred here — numbers: — none; lead conversion (E10 — Lead conversion #520) and export/DRS (E11 — Public resolution results, lineage and bulk export #521) are their own tickets, as scoped
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: — the docs-reference gate needs each new public resource in a workflow group (upsert-previews → api-writeback); caught by vitest, fixed before push

Specific to this change

  • the deploy reconciles upsert_policies, upsert_previews and upsert_applies — the new er-server serves (boot reconcile refuses to start on a failed apply), run 45971807456
Context — plan, discoveries, measurements, files

Plan

Discoveries

  • Upsert by External ID is what makes the apply retry-safe: the key carries the entity id, so a retry can update twice but never create twice — no separate dedupe of ambiguous responses is needed beyond reading back.
  • "Import-commit writeback" is the policy's sources: an import into a named source feeds the same generation, so there is no second trigger path.

Measurements

Files

🤖 Generated with Claude Code

…998)

Golden records that arrived by upload and are not yet in a Salesforce
object can be upserted there, reviewed and approved like merges.

- Upsert policies (PUT/GET …/writeback/upsert-policies, append-only): the
  External ID field keyed on, a golden → field mapping, an allowlist, and
  the delivery sources (an import's) whose records may be upserted.
- Materialized by the same merge_preview job, runs and checkpoint: an
  entity is a candidate when a member came from a policy source and none is
  already provenanced from the policy's object — that entity is a merge's,
  never an upsert's. Golden values, mapped and allowlisted; nulls omitted;
  keyed by the entity id; idempotent on a fingerprint.
- Review: GET …/upsert-previews, POST …/upsert-previews/decide (≤100, each
  item checked against its fingerprint and live policy revision), and an
  Upserts section on the writeback page.
- Apply (POST …/upsert-previews/apply → upsert_apply job): APPROVED →
  APPLYING at most once; the record read by its External ID; a record
  modified after the proposal is skipped as stale; the preimage written and
  the call marked in flight before PATCH …/{object}/{field}/{key}. An
  in-flight call is reconciled by reading back; keyed by External ID, a
  retry updates the same record and can never create a second.
- A created record is asserted always-match to its entity's upload member,
  so the next extraction converges on it rather than resolving a new
  entity.

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

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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

@athvin
athvin merged commit 3ec5d1f into main Nov 27, 2026
49 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 27, 2026 09:08 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — 9f0e4193 Deployed Nov 27, 2026 by athvin via remove closed PR previews #106
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.

E9: Apply approved upserts through the writeback journal

2 participants