Skip to content

Commit 4c5d3ee

Browse files
authored
fix: prevent member organization title overflow during enrichment (#4343)
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 3a4b6c5 commit 4c5d3ee

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

  • services
    • apps/members_enrichment_worker/src/activities
    • libs/data-access-layer/src/old/apps/members_enrichment_worker

services/apps/members_enrichment_worker/src/activities/llm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export async function squashWorkExperiencesWithLLM(
272272
If multiple roles from the same organization overlap in time IN DIFFERENT SOURCES, squash them into one entry with a unified startDate, endDate, and picked information (e.g., job titles, descriptions).
273273
Preserve all unique identities and consolidate other fields appropriately.
274274
If necessary, ONLY merge dateRanges and NEVER merge titles together, but pick the one that best represents the role.
275+
Job Titles:
276+
Return only a concise professional job title (e.g. "Software Engineer", "Engineering Manager").
277+
Do not return job descriptions, responsibilities, or full sentences.
278+
If the input is a description, infer the most appropriate professional job title.
275279
Handle Missing Dates:
276280
Use logical assumptions to fill gaps where possible, always using existing date information but nothing else.
277281
If there is a role with a missing startDate and a missing endDate, and there's also another role from same or similar organization with dates, you can remove the role with missing dates.

services/libs/data-access-layer/src/old/apps/members_enrichment_worker/index.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ import {
1414
OrganizationSource,
1515
} from '@crowd/types'
1616

17+
function truncateTitle(title: string | null | undefined) {
18+
const maxLength = 255
19+
20+
if (title == null) {
21+
return title
22+
}
23+
24+
const codePoints = [...title]
25+
if (codePoints.length <= maxLength) {
26+
return title
27+
}
28+
29+
return codePoints.slice(0, maxLength).join('')
30+
}
31+
1732
export async function fetchMemberDataForLLMSquashing(
1833
db: DbConnOrTx,
1934
memberId: string,
@@ -483,15 +498,24 @@ export async function updateMemberOrg(
483498
return null
484499
}
485500

501+
const normalizedToUpdate = { ...toUpdate }
502+
if (typeof normalizedToUpdate.title === 'string') {
503+
normalizedToUpdate.title = truncateTitle(normalizedToUpdate.title)
504+
}
505+
486506
// First check if another row like this exists so that we don't get unique index violations.
487507
// We compute the "target" state after applying toUpdate to decide what to look for.
488508
const params = {
489509
memberId,
490510
id: original.id,
491511
organizationId: original.orgId,
492512
// Use updated value if provided, otherwise keep original
493-
dateStart: toUpdate.dateStart !== undefined ? toUpdate.dateStart : original.dateStart,
494-
dateEnd: toUpdate.dateEnd !== undefined ? toUpdate.dateEnd : original.dateEnd,
513+
dateStart:
514+
normalizedToUpdate.dateStart !== undefined
515+
? normalizedToUpdate.dateStart
516+
: original.dateStart,
517+
dateEnd:
518+
normalizedToUpdate.dateEnd !== undefined ? normalizedToUpdate.dateEnd : original.dateEnd,
495519
}
496520

497521
let dateEndFilter = `and "dateEnd" = $(dateEnd)`
@@ -538,7 +562,7 @@ export async function updateMemberOrg(
538562
{
539563
memberId,
540564
id: original.id,
541-
...toUpdate,
565+
...normalizedToUpdate,
542566
},
543567
)
544568

@@ -554,6 +578,8 @@ export async function insertWorkExperience(
554578
dateEnd: string | null,
555579
source: OrganizationSource,
556580
): Promise<string | null> {
581+
const truncatedTitle = truncateTitle(title)
582+
557583
let conflictCondition = `("memberId", "organizationId", "dateStart", "dateEnd")`
558584
if (!dateEnd) {
559585
conflictCondition = `("memberId", "organizationId", "dateStart") WHERE "dateEnd" IS NULL`
@@ -574,7 +600,7 @@ export async function insertWorkExperience(
574600
${onConflict}
575601
RETURNING id;
576602
`,
577-
[memberId, orgId, title, dateStart, dateEnd, source],
603+
[memberId, orgId, truncatedTitle, dateStart, dateEnd, source],
578604
)
579605

580606
return result?.id ?? null

0 commit comments

Comments
 (0)