Skip to content

fix: search LinkedIn by company name when resolving opportunity companies 🏢 - #919

Merged
queenellie873 merged 1 commit into
colorstackorg:mainfrom
Wisesofthemall:fix/opportunity-company-lookup
Nov 18, 2026
Merged

queenellie873 merged 1 commit into
colorstackorg:mainfrom
Wisesofthemall:fix/opportunity-company-lookup

Conversation

@Wisesofthemall

Copy link
Copy Markdown
Contributor

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 (companyId is NULL), so the leftJoin('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, saveCompanyIfNecessary calls fetchCompanyFromLinkedIn, which puts the raw name into a URL: https://www.linkedin.com/company/Capital One. That isn't a real LinkedIn slug, so the harvestapi~linkedin-company actor returns [], the function returns null, 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 searches input ("List of company names to search on LinkedIn"), next to companies (URLs).

  • Added isLinkedInCompanyReference(), which returns true for a numeric LinkedIn ID or a LinkedIn company URL.
  • saveCompanyIfNecessary keeps the direct URL lookup for those. Plain names now go to the new searchCompanyOnLinkedIn(), which uses searches.
  • Empty actor results are no longer cached, so a miss is retried next time instead of staying broken for 30 days.
  • refineOpportunity only sets companyId when it resolves one, so re-refining an opportunity no longer clears a company it already has. title and description already work this way.
  • Unchanged: member LinkedIn sync (numeric IDs) and the admin company create/update pages (slugs).

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.

Before

After: not captured yet. A local run needs an APIFY_API_TOKEN, which I don't have locally.

Testing 🧪

  • Added employment.utils.test.ts: tests for isLinkedInCompanyReference (numeric ID, URL, names) and parseLinkedInCompanySlug. They pass with bun test.
  • tsc --noEmit, eslint and prettier pass for packages/core.
  • Not yet run live against Apify. The searches input comes from the actor's public input schema, and results are still validated against the existing LinkedInCompany zod schema. A quick check with a real token, e.g. adding an opportunity for "Capital One", would confirm it end to end.

Checklist ✅

  • I have given my PR a descriptive title.
  • I have linked the issue this PR closes.
  • I have added tests for the new helper.

🤖 Generated with Claude Code

…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>

@queenellie873 queenellie873 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 null and 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.

@queenellie873

queenellie873 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

alsoo i ran it locally with my dev apify api key: https://claude.ai/artifact/H6AUQU1aakdixUMoERvevz

great work!

@queenellie873 queenellie873 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither item above is a blocker, I verified that each issue is fairly unreproducible:

  1. 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.
  2. 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.

@queenellie873
queenellie873 merged commit 0960307 into colorstackorg:main Nov 18, 2026
2 checks passed
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.

Companies on Opportunities Page dont Populate

2 participants