Dedup keys on a normalized domain, scoped to your workspace
Three paths can create a company: the UI’s Add company dialog, the internal primitive every auto-create and API call funnels through, andlinkCompanyByDomain’s retry. All three check the same companies index before inserting anything.
The UI mutation normalizes the input with parseAndValidateDomain, which uses the psl library to extract a bare registrable domain and rejects free-mail domains like gmail.com (convex/domains/_shared/_libs/domain.lib.ts:5-12). It then looks up by_domain scoped to domain and organizationId; a match returns the existing company’s id instead of inserting a duplicate (convex/domains/companies/mutations/create.ts:29-58).
The internal primitive (convex/domains/companies/primitives/create.ts:110-123) repeats this exact check independently, since it has its own callers: contact-driven auto-create and the public REST create endpoint (convex/domains/companies/api/apiCreateCompany.ts:69-81).
Dedup is per-organization, not global. The by_domain index is defined on ["domain", "organizationId"] (convex/domains/companies/_tables.lib.ts:10), so the same domain can be its own separate company record in every other Klipy workspace.
Auto-creating a company from a contact’s email
When a new contact’s email carries a valid business domain and no company was passed explicitly,people/primitives/create looks that domain up via companies.primitives.listByDomain (convex/domains/people/primitives/create.ts:216-222). If nothing matches, it schedules — rather than awaits — a company create with companyCreatedSource: "contact_domain_auto_create" (convex/domains/people/primitives/create.ts:225-240).
Because that create is scheduled, not awaited, the contact row is inserted immediately, before the company exists. A follow-up scheduled mutation, linkCompanyByDomain, retries the domain lookup up to 6 times, with a 500ms-growing delay between attempts (roughly 10.5 seconds total). It patches contact.companyId once the scheduled company shows up, then gives up silently (convex/domains/people/primitives/linkCompanyByDomain.ts:6-7,36-50).
A generic domain (gmail.com, outlook.com, and similar) never reaches this path at all — parseAndValidateDomain returns nothing for it, so the contact is created without a companyId (convex/domains/_shared/_libs/domain.lib.ts:10; convex/domains/people/primitives/create.ts:172-214).
An auto-created company gets scheduleEnrichment: true by default and enters the exact same enrichment pipeline described below as a manually created one (convex/domains/companies/primitives/create.ts:137-149).
The enrichment pipeline
Enrichment is requested exactly once, at creation, viarequestEnrichment, which schedules metaCompanies.workflows.trigger (convex/domains/metaCompanies/primitives/requestEnrichment.ts:17-22). trigger checks the org’s subscription-block status first (skipped for house-funded onboarding imports), flips the company’s isUpdating flag on, then starts a durable Workflow run (convex/domains/metaCompanies/workflows.ts:301-350).
That workflow (_runEnrichmentWaterfall, convex/domains/metaCompanies/workflows.ts:141-299) tries, in order: a cached lookup, Clearbit, PDL, Apollo, then an AI research agent built on Exa. Each provider call is wrapped so a thrown error degrades to the next provider instead of failing the run (lines 193-282).
The cache it checks first, metaCompanies, is a separate table keyed only by domain — no organizationId (convex/domains/metaCompanies/_tables.lib.ts:11). One org’s successful enrichment of a domain is reused by every other org that later creates a company on that same domain.
A cache hit younger than 180 days (COMPANY_TTL_MS, convex/domains/_shared/_libs/enrichmentFreshness.lib.ts:3) patches the company immediately and the run ends there — no provider gets called (lines 161-172). A stale hit patches the company from the old data anyway, then still proceeds through the provider waterfall to refresh it (lines 173-176). A domain that only matches a metaCompanyDomains alias row is always treated as stale. That’s true even if the underlying record is fresh under its primary domain, and it forces a fresh fetch (convex/domains/metaCompanies/primitives/lookupWithAlias.ts:17-31).
Every successful provider call normalizes its data, saves it into the shared metaCompanies cache, and patches it onto the per-org company. It then bills 0.5 Orb credits and fires tracking events (convex/domains/metaCompanies/workflows.ts:177-190, 381-488). A fresh cache hit skips that billing step entirely, since it never calls saveAndTrack. If every provider fails or returns nothing, the run only flips isUpdating back off. No field changes, and nothing surfaces as an error (lines 284-298) — matching the “fails silently” behavior described in the overview.
The house-funded onboarding-import flag threads through every one of these hops: contact create, company create, requestEnrichment, trigger, chargeAndTrack. It skips only the Orb charge — enrichment itself still runs (convex/domains/people/primitives/create.ts:71-77; convex/domains/metaCompanies/workflows.ts:410-428).
The AI fallback provider
Only after Clearbit, PDL, and Apollo all fail or return nothing does Klipy fall back toCompanyEnrichmentAgent. It’s an LLM agent (Gemini 3.5 Flash Lite) with a single tool, Exa web search, capped at 6 tool-call steps (convex/ai/companyEnrichmentAgent/agent.lib.ts:116-128). Its instructions tell it to stop once every field is filled, and never to guess: “Leave fields null when uncertain — do not guess or fabricate” (line 109).
Its output goes through a strict schema with a noInfoAvailable field. If that’s true, or the company name is missing, the adapter returns nothing rather than a low-confidence guess (convex/ai/companyEnrichmentAgent/adapters/enrich.ts:62). The agent keeps no transcript and no memory between runs (storageOptions.saveMessages: "none", contextOptions.recentMessages: 0, lines 125-126).
Nothing about this fallback needs approval. Like every other enrichment source, it only fills currently-blank optional fields, never sends anything externally, and stays as editable as a value you typed yourself.
The domain field is structurally read-only
Neither the UI update mutation (convex/domains/companies/mutations/update.ts:8-65) nor the internal primitive it and every other write path route through (convex/domains/companies/primitives/update.ts:4-63) declares a domain key in its patch validator. Convex validates arguments against an exact object shape. A caller can’t add domain to a patch and have it silently pass through — it never reaches either validator’s field list.
The public REST layer illustrates this by omission: apiUpdateCompany’s field allow-list includes "domain" as a candidate (convex/domains/companies/api/apiUpdateCompany.ts:8). Forwarding it to primitives.update.default would still fail, since that mutation’s patch shape never declared the field (convex/domains/companies/api/apiUpdateCompany.ts:66-76). A company’s domain is only ever set at creation, or resolved to an existing record by the dedup check instead of being written at all (convex/domains/companies/primitives/create.ts:113-123).
The UI update mutation has one other mechanic worth knowing. Sending the literal string "_REMOVE" for any field clears it to undefined, rather than setting the field to that string (convex/domains/companies/mutations/update.ts:98-104).
Contacts and deals point at the company, not the reverse
A company record holds no list of its people.contacts.companyId is the only pointer, and Klipy resolves “who works here” by querying contacts for that id — not by reading anything stored on the company (convex/domains/people/primitives/create.ts:242-253). champion is the one exception: a single, direct contacts id stored on the company itself as its primary contact (convex/domains/companies/domain/company.model.ts:40).
Deals attach the same directional way: a dealCompanies join row plus a mirrored companyId column on the deal (convex/domains/deals/_tables.lib.ts:39-44). One write path, deals.primitives.updateCompany, keeps both in sync. It deletes any prior join row before inserting the new one. That keeps a deal pointing at exactly one company at a time, even though the join table’s own shape would allow more (convex/domains/deals/primitives/updateCompany.ts:12-26).
Deleting a company
Deleting a company deletes every deal joined to it throughdealCompanies, routed through deals.primitives.remove so that deal’s own cascades run too. The code states the reasoning directly: “a deal without a company has no meaning” (convex/domains/companies/triggers/cascadeDeleteDeals.ts:11-24).
The same delete also removes every interactionCompanies join row, unlinking past emails and meetings from the company without deleting the interactions themselves. It also clears segment-membership rows, and detaches — never deletes — any Opportunity that referenced the company (convex/domains/companies/_triggers.lib.ts:6-32). An uploaded logo file is deleted from storage in the same pass (convex/domains/companies/_triggers.lib.ts:9-11).
Deleting from the UI can also add the company’s domain to your blocked-domains list, so a future contact from that domain never re-creates it (convex/domains/companies/mutations/remove.ts:36-43).
Limits worth knowing
What this does not do
Klipy never rewrites a company’s domain after creation — every update path’s argument validator excludes that field, so there’s no path left to add one through. It never treats an AI enrichment guess as settled fact. The fallback agent’s own instructions require leaving a field blank over guessing, and any field it fills stays exactly as editable as one entered by hand. It never retries a domain that already came back empty from enrichment. See How do I manage companies in Klipy? for that behavior from the user’s side.Related guides
Companies overview
See where company records come from, what fields they hold, and how enrichment behaves day to day.
Manage a company
Create or find a company, edit its fields, and link people or deals to it.