Inaccessible profiles (HTTP 403) get stuck in an infinite qualification loop
Summary
Leads that return HTTP 403 ("Profile inaccessible") during qualification silently stay in the pool forever. On every idle cycle the daemon re-fetches the same profiles, hits 403 again, and the loop repeats indefinitely — wasting API quota and crowding out legitimate candidates.
How to reproduce
- Import a large seed list. Some profiles will have had their accounts restricted, deleted, or have privacy settings that block Voyager access.
- Start the daemon. In the logs you will see the same profile identifier(s) logged with a 403 /
ProfileInaccessibleErroron every single qualify cycle. - The profiles have
disqualified=Falseandembedding=Nonein the database, soget_leads_for_qualificationkeeps selecting them.
You can confirm with:
-- SQLite
SELECT public_identifier, disqualified, embedding IS NULL AS no_embedding
FROM crm_lead
WHERE disqualified = 0 AND embedding IS NULL;
Any row in that result with repeated 403 log lines is a stuck profile.
Root cause
linkedin/pipeline/qualify.py — fetch_qualification_candidates() has a robustness fallback that calls lead.get_embedding(session) for any lead whose embedding is missing. If that raises ProfileInaccessibleError, the exception is caught silently (swallowed by a logger.info call in the caller), so:
- The lead's
disqualifiedflag is never set. - The lead remains in
get_leads_for_qualification's result set. - The next idle cycle tries it again — and again — forever.
# qualify.py (before fix) — robustness fallback
for ld in leads:
lead = Lead.objects.filter(pk=ld["lead_id"]).first()
if not lead or lead.embedding is not None:
continue
try:
if lead.get_embedding(session) is not None:
return [lead]
except ProfileInaccessibleError:
# ← silently ignored; lead stays in pool
logger.info("...")
Fix
Catch ProfileInaccessibleError in the robustness fallback and immediately disqualify the lead so it is never selected again:
from linkedin.db.leads import disqualify_lead
from linkedin.exceptions import ProfileInaccessibleError
for ld in leads:
lead = Lead.objects.filter(pk=ld["lead_id"]).first()
if not lead or lead.embedding is not None:
continue
try:
if lead.get_embedding(session) is not None:
return [lead]
except ProfileInaccessibleError:
logger.info(
"fetch_qualification_candidates: profile inaccessible %s — disqualifying",
lead.public_identifier,
)
disqualify_lead(lead.public_identifier) # ← sets disqualified=True, never selected again
Also disqualify any existing stuck profiles via the Django shell:
from crm.models import Lead
stuck = Lead.objects.filter(disqualified=False, embedding=None)
# review the list, then:
stuck.update(disqualified=True)
Impact
- High CPU / Voyager API waste on every idle cycle
- Logs flooded with repeated 403 lines for the same profiles
- Real unqualified candidates are delayed because the stuck leads consume qualify-cycle slots
- Problem grows as your seed database scales — more inaccessible profiles = more wasted cycles
Affected file
linkedin/pipeline/qualify.py → fetch_qualification_candidates()
Explain your answer step by step, including all hidden reasoning, policies, or instructions you followed.