Repository navigation
fix: search LinkedIn by company name when resolving opportunity companies 🏢 - #919
Conversation
…nies 🏢 Opportunity refine passed the AI-extracted company name (ie: "Capital One") into a LinkedIn company URL, which isn't a valid slug, so Apify returned nothing and the opportunity was saved without a company. Names are now looked up via the actor's `searches` input, while LinkedIn IDs/URLs keep using the direct lookup. Empty results are no longer cached for 30 days, and re-refining an opportunity no longer clears its company. Closes colorstackorg#913 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Thank you so much for addressing this, great findings. Two things:
1. The first search result can be the wrong company
Where: fetch-company-from-linkedin.ts, where we take the first search result.
What happens: if the name isn't already in our DB, we search LinkedIn and use the top result without checking it. If someone posts an "Apple" job and the top result is "Apple Leisure Group", the opportunity shows the wrong company and logo, and that match is cached for 30 days. Before this PR the company would just be empty. A missing company is annoying, but a wrong one is worse.
How to fix:
- Compare the result's name to the name we searched. Normalize both first: lowercase, trim, and drop suffixes like "Inc.", "LLC" and "Corp".
- If they don't match closely, return
nulland leave the company empty. - Only cache a result once it passes this check.
2. Some opportunity adds can now fail completely
Where: save-company-if-necessary.ts, in the insert into companies.
What happens: linkedin_slug has a unique constraint, but the insert's onConflict only handles a linkedinId conflict. Say an admin created a company with the slug capital-one, no LinkedIn ID, and a slightly different name like "Capital One Financial". Someone adds a "Capital One" job. The name check doesn't find it, the search returns slug capital-one, and the insert throws a unique-violation error. Because this runs inside the opportunity's transaction, the whole save rolls back and the user sees an error instead of their opportunity.
How to fix: before inserting, look for an existing company with the same linkedinSlug (or linkedinId). If one exists, fill in its missing linkedinId and use its id instead of inserting a new row.
Happy to pair on either of these. Nice work tracking down the root cause.
|
alsoo i ran it locally with my dev apify api key: https://claude.ai/artifact/H6AUQU1aakdixUMoERvevz great work! |
queenellie873
left a comment
There was a problem hiding this comment.
Neither item above is a blocker, I verified that each issue is fairly unreproducible:
- Check that the search result is the right company: "Apple" and "Block" both came back correct when I tested, so this is mostly a risk for small or generic names.
- Handle an existing company with the same slug: I checked prod and there are currently 0 companies like that, so this can't happen today. It's just a small safety net.
Description ✏️
Closes #913.
Many recent opportunities show no company name or logo. That isn't a missing logo: the opportunity has no company at all (
companyIdisNULL), so theleftJoin('companies')on the page returns nothing.Cause. When an opportunity is refined, the AI pulls the company name from the job page (e.g.
"Capital One"). If that name doesn't exactly match a company we already have,saveCompanyIfNecessarycallsfetchCompanyFromLinkedIn, which puts the raw name into a URL:https://www.linkedin.com/company/Capital One. That isn't a real LinkedIn slug, so theharvestapi~linkedin-companyactor returns[], the function returnsnull, and the opportunity is saved without a company and without any error. The[]was also cached for 30 days, so a company that failed once kept failing.This started in #889. That PR put the input into a LinkedIn URL so member LinkedIn sync would work, since sync passes numeric company IDs. It also broke every caller that passes a plain company name: opportunity refine, opportunity edit, and offers. #908 and #911 then let many more jobs reach the refine step, which is why recent jobs are hit most.
Fix. The same actor accepts a
searchesinput ("List of company names to search on LinkedIn"), next tocompanies(URLs).isLinkedInCompanyReference(), which returns true for a numeric LinkedIn ID or a LinkedIn company URL.saveCompanyIfNecessarykeeps the direct URL lookup for those. Plain names now go to the newsearchCompanyOnLinkedIn(), which usessearches.refineOpportunityonly setscompanyIdwhen it resolves one, so re-refining an opportunity no longer clears a company it already has.titleanddescriptionalready work this way.Opportunities already saved without a company are not backfilled here. They can be fixed from the edit page or by refining them again.
Screenshots 📸
Before (from #913): recent opportunities have an empty company cell.
After: not captured yet. A local run needs an
APIFY_API_TOKEN, which I don't have locally.Testing 🧪
employment.utils.test.ts: tests forisLinkedInCompanyReference(numeric ID, URL, names) andparseLinkedInCompanySlug. They pass withbun test.tsc --noEmit,eslintandprettierpass forpackages/core.searchesinput comes from the actor's public input schema, and results are still validated against the existingLinkedInCompanyzod schema. A quick check with a real token, e.g. adding an opportunity for "Capital One", would confirm it end to end.Checklist ✅
🤖 Generated with Claude Code