Skip to content

feat(writeback): convert duplicate Salesforce Leads into existing Contacts (#520) - #1326

Merged
athvin merged 1 commit into
mainfrom
feat/520-lead-convert
Nov 27, 2026
Merged

athvin merged 1 commit into
mainfrom
feat/520-lead-convert

Conversation

@athvin

@athvin athvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #520

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

Lead conversion proposals materialized by the existing preview job, review (batch decide + a writeback-page section), the journaled lead_convert job over SOAP convertLead(), and corpus convergence by a full Lead re-extract. Entities lead_conversion, lead_conversion_apply; connectors.md §4.3.6 (including recovery: none — conversion is not reversible).

#520 (E10): convert a duplicate Lead into its existing Contact from an approved proposal through the same writeback journal as merges.

Proof

  • pg_lead_convert against a mock Salesforce (queryAll, LeadStatus query, SOAP convertLead): a clean conversion into the Contact's Account; a Lead already converted into the same Contact → converted_externally, nothing sent; one converted into another Contact → failed "not reversible", nothing sent; a stale Lead → skipped_stale, nothing sent; a Contact without an Account → failed, nothing sent; a lost response → in flight, then converted "verified by re-reading the Lead" with no second convertLead. Four extracts queued for the two conversions (full Lead + incremental Contact each). Decide: viewer 403, steward 200 per item; apply 409 with nothing approved.
  • Playwright writeback.spec.ts: a steward approves a conversion, an admin converts.
  • make check exit 0; Postgres suite 162 passed. make frontend: vitest 1139 passed; Playwright 1112 passed, 1 failed — triage.spec.ts "20 reviews by swipe alone" on mobile-safari, the reviews inbox this diff does not touch, run while the machine was loaded (the PG suite took 332s against the usual ~90s). CI's run is the arbiter.

Risk & rollback

Conversion is irreversible in Salesforce, so the apply refuses on any doubt (stale, converted elsewhere, no Account) and never replays an unknown outcome; opt-in by two policies; admin-only apply. git revert <merge-sha>.

Post-merge ledger

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

  • 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: — b95e683, rust 45979912382 + frontend 45979912506 success
  • images built, or correctly never ran because nothing that goes into
    an image changed: — success, run 45979912492
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: — run 45980524947 success; the live process serves the new route: https://dupezero.com/api/openapi lists /lead-conversions/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 b95e683
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: — E10 — Lead conversion #520 CLOSED by feat(writeback): convert duplicate Salesforce Leads into existing Contacts (#520) #1326 via automation
  • follow-ups are open for everything deferred here — numbers: — none; account-dataset previews were Merge previews for account datasets #1309, landed by a parallel session (feat(writeback): merge previews for account datasets (#1309) #1329)
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: — the local mobile-safari triage failure did not reproduce in CI (the machine was loaded by a parallel release build)

Specific to this change

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

Plan

Discoveries

  • "Excluded from the next resolution run" has a mechanism already: a FULL extract tombstones whatever the source omits, and Lead extraction filters IsConverted = false — so a full Lead re-extract after converting is exactly the exclusion.
  • With several Contacts in the entity there is no single target until their merge lands; proposing a conversion then would pick a Contact the merge may delete, so it is deferred and counted in the job's exclusions.

Measurements

Files

🤖 Generated with Claude Code

…tacts (#520)

A steward converts a duplicate Lead into the existing Contact it resolved
with, through the same proposal, approval and journal discipline as
merges — never a second write path. Opt-in by writeback policies for both
Lead and Contact.

- Proposed by the merge_preview job: an entity holding Leads and exactly one
  Contact converts each Lead into it (its Lead merge group is then not
  proposed); with several Contacts the Contact merge lands first. The
  proposal pins both records' revision tokens, both policy revisions and the
  snapshot, and is idempotent on its fingerprint.
- Review: GET …/lead-conversions, POST …/lead-conversions/decide (fingerprint
  and both policy revisions live per item), and a Lead conversions section
  on the writeback page that states conversion cannot be undone.
- Apply (POST …/lead-conversions/apply → lead_convert job): at most once per
  proposal; both records re-read; a Lead already converted into the same
  Contact is CONVERTED_EXTERNALLY, converted elsewhere or deleted is FAILED
  (reported, never retried); a moved SystemModstamp is SKIPPED_STALE; the
  Contact's Account recorded and the call marked in flight before SOAP
  convertLead(); a lost response is resolved by re-reading the Lead.
- After a conversion, a FULL Lead extract (which omits converted Leads, so
  ingest tombstones it and the next run drops it from the entity) and an
  incremental Contact extract are queued.

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 b95e683 into main Nov 27, 2026
49 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 27, 2026 10:10 — with GitHub Actions Inactive

This branch was previously deployed

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

E10 — Lead conversion

2 participants