Skip to content

[#649] Add Career job ingestion, dedupe and classification - #672

Open
jesusthecreator017 wants to merge 3 commits into
mainfrom
api/career-job-ingestion
Open

jesusthecreator017 wants to merge 3 commits into
mainfrom
api/career-job-ingestion

Conversation

@jesusthecreator017

Copy link
Copy Markdown
Contributor

Why

#633 ports CS Job Poster into Forge. Cron (#652 adapters, #653 polling) fetches raw listings; this PR adds the API side that turns each source's snapshot into deduplicated Job rows with locations, categories, an active/inactive lifecycle, and a silent first-run baseline. #651 search, #653 and #654 build on this data.

What

Closes: #649

  • careerJobSourceSnapshotSchema and types in @forge/validators: the contract agreed in [SPRINT-04] Bring CS Job Poster into Forge and build a Blade Career page #633 (inventory: "full" | "rolling", optional track, description, compensation).

  • ingestJobSnapshot(snapshot, destinations) in @forge/api/job-board.server, for cron only. No tRPC procedure.

  • Pure rules in utils/job-board/ that need no database:

    • normalize: cleans apply URLs, builds identity keys from ATS IDs, recognizes aggregator links.
    • classify: decides track, and category using rules ported from upstream categories.py.
    • locations: parses city, state and U.S. remote, and detects foreign locations.
    • listing: prepares each listing and records why it was rejected.
  • Dedupe uses IDs only, strongest first:

    • an ATS requisition ID;
    • the cleaned apply URL, but only when it points at one posting (careers landing pages and aggregator links never count);
    • otherwise an ID scoped to the source.

    Matching compares the hash column and also the raw key. Concurrent ingests of the same job produce one job.

  • Lifecycle:

    • A source's first successful run is silent.
    • After that, a new job is queued (pending) only when cron passes a channel for its track.
    • When a full inventory omits a job, it closes; a rolling feed never closes anything.
    • A reappearing job reopens without being posted again.
    • A snapshot fetched before a newer run closed a job can't reopen it.
  • Each listing is validated on its own, so one bad listing never blocks a board. Rejection reasons: invalid_listing, invalid_apply_url, not_student_role, non_us. Any U.S. signal keeps a location ("London, KY", "ON-SITE - Austin, TX").

  • Never creates Company rows. A job links to an approved Company by normalized name or alias.

  • No schema changes. Uses the 0065 tables as merged.

Known limit (documented in the SRD): when an aggregator listing creates a job first, a later employer listing of the same posting shares no ID with it, so the job is posted twice. Mitigations are proposed for #652 (send the employer link) and #654 (posting guard).

Test Plan

  • pnpm format, pnpm lint, pnpm typecheck: pass. The new integration test has one max-lines warning.
  • @forge/api pnpm test against local PostgreSQL 16: 151 files, 1256 tests pass. That includes the rule tests in tests/job-board/ingestion-rules.test.ts and the ingest tests in tests/integration/job-board-ingest.test.ts.
  • @forge/validators vitest: 29 files, 380 tests pass.
  • Ran forge-review (standard tier: api-shape, validation/placement and test-quality reviewers) and fixed what it found. I broke the code on purpose to check that the new stale-run and kept-details tests fail.
  • Test cases are listed in .forge/features/career-job-ingestion/test-cases.md (TC-001 to TC-026, NEG-001 to NEG-004).

Out of scope: polling, leases and error recording (#653); Discord sends (#654). Upstream's "recent catch-up" of first-run jobs is not ported, by decision.

Checklist

  • Database: No schema changes, OR I ran pnpm db:generate and committed the generated files in packages/db/drizzle/
  • Environment Variables: No environment variables changed, OR I have contacted the Development Lead to modify them on Coolify BEFORE merging.

🤖 Generated with Claude Code

jesusthecreator017 and others added 3 commits November 19, 2026 11:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jesusthecreator017 jesusthecreator017 added Feature New Feature or Request Major Big change - 2+ reviewers required API Change modifies code in the global API/tRPC package labels Nov 19, 2026
@jesusthecreator017 jesusthecreator017 self-assigned this Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The change adds snapshot and listing validation, identity normalization, track and category classification, U.S. location parsing, and job ingestion in @forge/api. The ingestion process supports source baselines, job matching, observation updates, and full-inventory closure. New unit and database integration tests cover these behaviors.

Merge Risk: Moderate · up to 0d732

The new job ingestion can merge distinct openings into one job when board keys contain colons or when shared careers links carry numeric query parameters. Overlapping full-inventory runs from different sources can leave closed jobs active. A few edge cases around conflict recovery, out-of-order snapshots and lowercase state codes also give wrong results. Fix the identity and closure issues before merge.

Pre-merge checks: Passed 7

Check name Status Explanation
Title check Passed The title begins with the issue number in brackets, "[#649]", followed by a concise description of the main change, and is 58 characters, under the 72-character limit. It matches the requirements and …
Description check Passed The description explains the motivation (#633 port of CS Job Poster), lists the new schema, ingestion function, pure rules for normalization, classification, locations, and listing preparation, dedupe…
Linked Issues check Passed Only #649 is directly linked and active. Its coding requirements are met by the ingestion layer:

- Cron input contract: careerJobSourceSnapshotSchema in @forge/validators (`packages/validators/sr…
Out of Scope Changes check Passed Changed files map to #649 objectives or their supporting work:

- packages/validators/src/job-board.ts: snapshot contract.
- packages/consts/src/job-board.ts: JOB_SOURCE_INVENTORIES for full ver…
No Hardcoded Secrets Passed No hardcoded secrets found in the 15 changed files. Searches of added lines covered key/secret/password/token patterns, vendor token prefixes (sk-, ghp_, xox, AKIA), PEM headers, credentialed URLs, an…
Validated Env Access Passed Checked the PR range refs/coderabbit/pre-merge-check/base..head. It changes 15 files. No added line in the diff contains process.env. A search of each changed file's head version also found no `proc…
No Typescript Escape Hatches Passed The check flags any types, @ts-ignore, @ts-expect-error, and non-null assertions (!.) in changed code. I took the PR diff against refs/coderabbit/pre-merge-check/base and scanned all added `…
Full details: Title check

Explanation

The title begins with the issue number in brackets, "[#649]", followed by a concise description of the main change, and is 58 characters, under the 72-character limit. It matches the requirements and the changeset, which adds career job ingestion, deduplication, and classification.

Full details: Description check

Explanation

The description explains the motivation (#633 port of CS Job Poster), lists the new schema, ingestion function, pure rules for normalization, classification, locations, and listing preparation, dedupe and lifecycle behavior, and the test plan. It directly matches the changeset.

Full details: Linked Issues check

Explanation

Only #649 is directly linked and active. Its coding requirements are met by the ingestion layer:

  • Cron input contract: careerJobSourceSnapshotSchema in @forge/validators (packages/validators/src/job-board.ts) and the spec and SRD documents in .forge/features/career-job-ingestion/.
  • Grouping and dedupe: normalize.ts builds identity keys (ATS requisition ID, cleaned apply URL, source-scoped ID). ingest.ts matches on hash and raw key. Integration tests cover dedupe and concurrent ingest.
  • Classification: classify.ts (category and track) and locations.ts (U.S. location parsing, foreign filtering).
  • First seen, last seen, and active state: ingest.ts maintains observations and deactivates jobs on full-inventory omission. Reopen and stale-snapshot rules are implemented and tested.
  • Silent baseline: the first successful run records a baseline and queues no Discord delivery. Covered by job-board-ingest.test.ts.

One point is not implemented in this PR. #649 states that inactive listings are "excluded from default search". The PR adds no search filter, and the PR description assigns search to #651. The data side (active flag) is present. Search exclusion is treated as out of this PR's scope.

Full details: Out of Scope Changes check

Explanation

Changed files map to #649 objectives or their supporting work:

  • packages/validators/src/job-board.ts: snapshot contract.
  • packages/consts/src/job-board.ts: JOB_SOURCE_INVENTORIES for full versus rolling inventories.
  • packages/api/package.json and packages/api/src/job-board.server.ts: cron-only export of ingestJobSnapshot.
  • packages/api/src/utils/job-board/*: normalization, classification, location, listing preparation, and ingest.
  • packages/api/src/utils/career/us-cities.ts: findUsCity used by location parsing.
  • Tests under packages/api/src/tests/.
  • .forge/features/career-job-ingestion/*: spec, SRD, status, and test cases for the same feature.

No tRPC procedure, schema change, polling, or Discord send code is listed in the summary. Those items are excluded by the PR description.

Full details: No Hardcoded Secrets

Explanation

No hardcoded secrets found in the 15 changed files. Searches of added lines covered key/secret/password/token patterns, vendor token prefixes (sk-, ghp_, xox, AKIA), PEM headers, credentialed URLs, and long opaque literals. Every hit was benign: url.username || url.password is a guard that rejects credentialed URLs in normalize.ts; key in us-cities.ts is a cache lookup string; the 64-hex literal in the test is the published SHA-256 test vector for "abc". The integration test gets its database URL from provisionDisposableDatabase at runtime and stubs DATABASE_URL through vi.stubEnv, so no credential is committed.

Full details: Validated Env Access

Explanation

Checked the PR range refs/coderabbit/pre-merge-check/base..head. It changes 15 files. No added line in the diff contains process.env. A search of each changed file's head version also found no process.env reference. The new code adds no direct env access outside env.ts or .config. files, so the custom check is satisfied.

Full details: No Typescript Escape Hatches

Explanation

The check flags any types, @ts-ignore, @ts-expect-error, and non-null assertions (!.) in changed code. I took the PR diff against refs/coderabbit/pre-merge-check/base and scanned all added .ts/.tsx lines (about 1,700 lines across 11 TypeScript files). I found no @ts-ignore, @ts-expect-error, @ts-nocheck, explicit any, as any, or any[] usage. I also found no non-null assertions, including x!., x![, )!, and ]!. The only as unknown as/as never search returned nothing. The new code, such as ingest.ts, listing.ts, locations.ts, and the validators, uses typed signatures and Zod schemas.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/api/package.json

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/api/src/job-board.server.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

packages/api/src/tests/integration/job-board-ingest.test.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 9 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 3

packages/api/src/utils/job-board/ingest.ts: 2

206-206: Minor · Data Integrity & Integration · Quick win

Keep older snapshots from replacing newer details.

If the 12:02 snapshot commits before the 12:01 snapshot, the delayed snapshot overwrites the title and other details. lastSeenAt still records 12:02.

Check seenAt against the stored freshness timestamp before replacing details. Preserve the null-safe updates for current snapshots.


193-193: Minor · Data Integrity & Integration · Quick win

Reconcile the job after insert-conflict recovery.

If another ingest inserts and closes the job after findJob returns no row, a newer snapshot can lose the insert conflict and retrieve that inactive job here. This path skips the update branch. It creates an open observation but leaves Job.active false.

Run the existing-job update path after conflict recovery.

packages/api/src/utils/job-board/locations.ts: 1

159-159: Minor · Functional Correctness · Quick win

Retain lowercase city/state locations.

With locationTexts: ["London, ky"], FOREIGN matches London, but hasUsEvidence misses ky. prepareListing then rejects the listing as non_us, although parseCityState accepts ky as KY.

Recognize state codes without case sensitivity in a city/state position. Keep the protection against bare prose tokens.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 98f3f9d and 0d7325e.

Files selected for processing: 16

  • .forge/features/career-job-ingestion/spec.md
  • .forge/features/career-job-ingestion/srd.md
  • .forge/features/career-job-ingestion/status.md
  • .forge/features/career-job-ingestion/test-cases.md
  • packages/api/package.json
  • packages/api/src/job-board.server.ts
  • packages/api/src/tests/integration/job-board-ingest.test.ts
  • packages/api/src/tests/job-board/ingestion-rules.test.ts
  • packages/api/src/utils/career/us-cities.ts
  • packages/api/src/utils/job-board/classify.ts
  • packages/api/src/utils/job-board/ingest.ts
  • packages/api/src/utils/job-board/listing.ts
  • packages/api/src/utils/job-board/locations.ts
  • packages/api/src/utils/job-board/normalize.ts
  • packages/consts/src/job-board.ts
  • packages/validators/src/job-board.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

and(
inArray(Job.id, jobIds),
eq(Job.active, true),
notExists(openObservation),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Data Integrity & Integration · Heavy lift

Concurrent source closures can leave a job active with no open observations.

closeMissing closes one source's observations, then checks notExists(openObservation) across all sources. Under PostgreSQL READ COMMITTED, a closure from source A cannot see an uncommitted closure of the same job's observation from source B. If both full inventories overlap on a job that has only those two open observations, each check can still find the other's observation open. Neither transaction deactivates the job.

Later inventories from both sources find no newly closed observations and return at line 282. The job remains active: true with no open observations. Nothing in the inspected path corrects it.

Make deactivation of a job correct when its final open observation closes, even when full inventories from different sources overlap. The job-row lock must be taken in a statement that completes before the notExists check runs. A lock inside the same UPDATE does not provide this. Choose between serializing closures per job and retrying on serialization failure. Use the same lock order as the listing transactions.

const last = url.pathname.split("/").filter(Boolean).at(-1) ?? "";
return (
/[0-9]/.test(last) ||
[...url.searchParams.values()].some((value) => /[0-9]/.test(value))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Data Integrity & Integration · Quick win

Do not treat every numeric query value as a posting ID.

Two openings with the shared link https://acme.example/careers?year=2026 receive the same URL identity. This violates the requirement that shared careers links keep postings separate.

Accept query parameters only when their names and provider contracts identify one posting.

}): [string, ...string[]] {
const url = new URL(input.applyUrl);
const keys: [string, ...string[]] = [
`source:${input.provider}:${input.boardKey}:${input.externalId}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Data Integrity & Integration · Quick win

Encode source identity components without ambiguity.

boardKey="acme:engineering", externalId="17" and boardKey="acme", externalId="engineering:17" produce the same key for one provider. Both inputs pass validation. Distinct openings can therefore match the same job.

Use an unambiguous tuple encoding, such as JSON.stringify([provider, boardKey, externalId]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Change modifies code in the global API/tRPC package Feature New Feature or Request Major Big change - 2+ reviewers required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SPRINT-04] Career: build job ingestion, dedupe, and classification services in @forge/api

1 participant