Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .forge/features/career-job-ingestion/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Career job ingestion

Status: Approved (2026-11-17), amended 2026-11-19 after review (pending approval)

## User-facing purpose

Part of #633. Turns raw listings from every job feed and board into one clean,
deduplicated set of jobs, so Career search (#651/#655) and Discord posts (#654)
show each real opening once with a usable company, track, category, location
and apply link. Adds no UI of its own.

## Users / actors

- Members see the results in Career search and in job pings or posts.
- Cron (#652/#653) hands each source's listings to ingestion.
- Officers see no direct surface. Source health reporting belongs to #653.

## User-visible interface

- A job seen on several feeds or boards appears once.
- Each job shows its company, title, track (internship or new grad), category,
apply link, and every location the sources gave. Unparsed location text shows
as written.
- Jobs that are no longer posted drop out of default search but stay on members'
applications.
- Discord shows nothing from the first run of a new source. After that, new jobs
go out once.

## Scope

### In scope

- Group listings by company and merge the same job seen across sources.
- Decide the track, classify the role category, and parse U.S. locations.
- Record when a job was first and last seen, and whether it's still active.
- Silent first-run baseline for each source.

### Out of scope

- Fetching or parsing feeds (#652), polling and failure handling (#653),
sending to Discord (#654), alert matching (#650), and search (#651).
- An officer view of ingest results. Cron gets counts only.
- Fuzzy title matching across sources.
- Non-U.S. jobs.
- Reposting a reopened job.
- Importing old CS Job Poster data.
- Creating or approving Guild companies.

## Vocabulary

- `source`: one feed or employer board, such as a GitHub list or a Greenhouse board.
- `listing`: one entry from one source.
- `job`: the single opening that one or more listings describe.
- `full inventory` vs `rolling feed`: a full inventory lists every open role, so
a missing listing means the role closed. A rolling feed doesn't, so a missing
listing proves nothing.
- `baseline`: a source's first successful run, which is recorded but never posted.

## Acceptance criteria

- The same opening from two sources appears as one job, except when the first
listing has only an aggregator link (known limit, see SRD).
- Rerunning an unchanged source changes nothing a member can see.
- Listings that are neither internship nor new grad, or that are only outside
the U.S., never appear.
- A city, a state, U.S. remote, several locations, and unparsed text all display
correctly.
- A job missing from a full inventory goes inactive. A job missing from a rolling
feed doesn't.
- A closed job that reappears is active again, with no second Discord post.
- When sources disagree on track, the first accepted track stays, and a track
change never causes another post.
- Title, description, posted date and compensation follow the latest listing
that provides them; a feed without them doesn't erase them. The employer's own
apply link wins over an aggregator's.
- Two postings that share a generic careers link stay two jobs.
- A job whose listing no longer qualifies (for example, its title becomes
"Senior…") goes inactive on a full inventory.
- An older, delayed run never reopens a job a newer run closed.
- One malformed listing doesn't block the rest of its source.
- A new source's first run posts nothing. New jobs after that are queued for
Discord once, and only if that track has a channel configured.

## Open questions

- None. Resolved 2026-11-19: upstream's "recent catch-up" of baseline jobs is not
ported. A new source's first run stays fully silent; those jobs are still
searchable.
157 changes: 157 additions & 0 deletions .forge/features/career-job-ingestion/srd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Career job ingestion SRD

Status: Draft, awaiting human review

## Technical purpose

`@forge/api` owns the job rules for #633. Cron hands `ingestJobSnapshot` one
source's parsed snapshot. Ingestion classifies, deduplicates, and writes `Job`,
`JobObservation`, `JobLocation`, and `JobSource` state. It doesn't fetch, poll,
or send anything.

## Relevant principles

- Keep pure rules (normalize, classify, locations) separate from DB writes so they
can be unit-tested without a database (forge-api "where workflow logic lives").
- No Discord calls. Ingestion only sets delivery state for #654 to claim.
- Reuse `normalizeCompanyName` (`@forge/validators`) and the U.S. city catalog
(`utils/career/us-cities.ts`).

## Access policy

There is no tRPC procedure. The service is exported only through
`@forge/api/job-board.server`, following the `discord-archive.server` pattern,
for cron. Nothing in Blade imports it.

## Architecture / data flow

1. Cron adapter (#652) builds a `CareerJobSourceSnapshot`, which the
`careerJobSourceSnapshotSchema` validator checks.
2. Cron reads channel IDs from the #648 config keys and calls
`ingestJobSnapshot(snapshot, destinations)`.
3. Ingestion rejects the snapshot if `complete` is false, or if the snapshot's
envelope (source, fetchedAt, inventory) is invalid. Otherwise it finds or
creates the `JobSource` row by (provider, boardKey).
4. Each listing is validated on its own (an invalid one is counted as
`invalid_listing`, and the rest still ingest), then goes through a pure prepare step: clean the apply URL, decide the
track, parse locations, classify the category, and build the company key and
the identity keys. A rejected listing is counted by reason.
5. Each accepted listing then runs in its own transaction:
- Find the job by observation (sourceId + externalId), then by any identity
key, and insert one only if neither exists.
- Insert or update the observation.
- Refresh the job's fields and add any new location rows.
6. If `inventory = "full"`, observations missing from this run close. A job with
no open observations goes inactive.
7. A successful run sets `baselineCompletedAt` (if unset) and `lastSuccessAt`.
Attempts and errors (`lastAttemptAt`, `lastError`) belong to #653.

### Identity

- Candidate keys, strongest first:
- `ats:greenhouse:<id>`, `ats:lever:<id>`, `ats:ashby:<id>`, `ats:workday:<tenant>:<req>` from the apply URL;
- `url:<cleaned apply URL>`, only when the URL identifies one posting (a digit
in its last path segment or in a query value). A shared careers landing page
or an aggregator URL is never an identity. A Workday key needs a
`_<requisition>` suffix;
- `source:<provider>:<boardKey>:<externalId>`.
- A new job's `identityKey` is the strongest key it has. Lookup tries every key, so
a later source with a stronger key still finds the job.
- Lookups compare the hash column (Node SHA-256 of the UTF-8 key, which matches
the generated column) and also compare the raw key. A row with a matching hash
but a different raw key is an error.
- A job insert uses `ON CONFLICT (identity_hash) DO NOTHING` and selects the row
again, so two concurrent ingests produce one job.
- Company and title never form an identity.
- Known limit: if an aggregator listing (source key only) creates a job and an
employer board later lists the same posting, the two share no ID, so they
don't match and the job is posted twice. Storing more keys per job wouldn't
help, and upgrading a job's key in place rarely fires because #652 falls back
to the apply URL as `externalId`. Mitigations live outside #649: adapters
send the employer link when a feed row has one (#652), and a company + title
posting guard (#654, needs lead sign-off).

### Field rules

- `track`: on a new job, use the adapter's track if given, otherwise classify it
from the title. On an existing job it never changes.
- `title`, `description`, `compensation`, `postedAt`, `category`: take the latest
listing's values. Description and compensation aren't overwritten with null.
- `applyUrl`: keep the employer's own link over an aggregator's (jobright,
simplify, speedyapply). Otherwise take the latest.
- `companyLabel` and `companyKey` come from the first listing. `companyId` is set
when an approved `Company` matches by `normalizedDisplayName` or by a
normalized alias, following `mergedIntoCompanyId`. Ingestion never inserts a
`Company`.
- A job that reappears gets `active = true` and `inactiveAt = null`. Its delivery
state stays as it was, so it isn't posted again. A snapshot fetched before the
job (or observation) closed is stale and doesn't reopen it.
- A listing rejected this run counts as unseen, so a full inventory closes its
job.

### Delivery state on insert

- The job is `pending`, with `deliveryTrack = track` and `discordChannelId` set,
only when the source already has `baselineCompletedAt` and
`destinations[track]` is set.
- Otherwise it keeps the default `suppressed`.

### Track and location rejection

- `not_student_role`: there's no adapter track, the title has no internship or
new-grad signal, or the title carries a seniority signal (senior, staff,
principal, director, vp, architect).
- `non_us`: every location is explicitly outside the U.S. Any U.S. evidence (a
state code, state name, or "US") keeps a text in scope, so "London, KY" and
"ON-SITE - Austin, TX" stay. A province code counts only after a comma.
- `invalid_apply_url`: the URL has credentials or isn't http(s).
- `invalid_listing`: the listing fails the schema, or its company label has no
ASCII letters or digits to build a company key from.
- No locations, or unparsed text, keeps the job with an `unknown` location.

## tRPC/API behavior

No procedures. `ingestJobSnapshot` returns:

```
{ created, updated, rejected: Record<reason, number>, deactivated, baselined }
```

## Validation

Add `careerJobSourceSnapshotSchema` and its inferred type to
`packages/validators/src/job-board.ts`. The fields are the ones agreed in #633:
`source`, `fetchedAt`, `complete`, `inventory`, and `listings[]` with optional
`track`, `postedAt`, `description`, and `compensation`. Listings are strict (an
unknown field rejects that listing). A description longer than 20,000
characters is truncated, not rejected.

## Data / migration / compatibility

No schema change. Uses the 0065 tables as merged. #670 also writes to
`utils/job-board/` with different file names.

## Discord integration

None. #654 claims `pending` rows.

## Configurability review

The channel for each track comes from DiscordConfig through the caller. Sources
are rows, not code constants. Category regexes and aggregator hosts are
code-owned rules, like upstream.

## React / frontend constraints

None.

## Testing / verification strategy

- Unit tests (no database) for normalize, classify, and locations, with fixtures
for each source type.
- Database tests through `provisionDisposableDatabase` cover the ingest flow and
are skipped when no loopback DB is available.

## Open questions

- Resolved 2026-11-19: upstream's recent catch-up of baseline jobs is not ported.
51 changes: 51 additions & 0 deletions .forge/features/career-job-ingestion/status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Career job ingestion Status

Current phase: Implemented; review fixes applied, awaiting human review (fixes not committed)

> This file is the maintained progress tracker for the feature/change. Keep it current whenever decisions, tasks, validation, or open questions change.

## Decision log

- 2026-11-13: Cross-source dedupe matches only on IDs: ATS requisition keys and the normalized apply URL, with a source-scoped key as the fallback. No fuzzy or company/title matching, per the #647 SRD.
- 2026-11-13: The API classifies track from the title, using the adapter's track when one is given. Listings that are neither internship nor new grad are rejected.
- 2026-11-13: Listings whose only locations are explicitly outside the U.S. are rejected. Location text that can't be parsed is kept as `unknown`.
- 2026-11-13: Before a source's first successful run finishes, its jobs stay `suppressed`. After that, new jobs become `pending` with a frozen track and the channel that cron passes in. A track with no channel stays `suppressed`.
- 2026-11-17: A closed job that reappears becomes active again with no second Discord post, following #647's one-post-per-job rule. The user first picked "repost", then chose to follow #647 because of spam risk from flaky boards.
- 2026-11-17: When sources disagree on track, the track from the first accepted listing stays. A changed track never causes a repost.
- 2026-11-17: Title, description and compensation update from the latest listing. Apply links prefer the employer's own page over an aggregator. Track and first-seen date never change.
- 2026-11-17: No officer view of ingest results. Ingestion returns counts, including rejections by reason, to cron, and #653 decides how to report them.
- 2026-11-17: Build on the `CareerJobSourceSnapshot` shape from the #652 branch instead of a separate draft.
- 2026-11-19: forge-review (standard) fixes: landing-page and generic Workday URLs are no identity; stale snapshots don't reopen closed jobs; U.S. evidence beats foreign words; each listing is validated alone (`invalid_listing`); long descriptions truncate; company keys always pass `companyKeySchema`.
- 2026-11-19: Spec amended after review: aggregator-first duplicate limit, null-safe detail updates, and four new acceptance criteria (landing-page links, rejected listings close, stale runs don't reopen, malformed listings don't block a source).
- 2026-11-19: A listing rejected this run counts as unseen, so a full inventory closes its job.
- 2026-11-19: Known limit: an aggregator-first job and a later employer listing of the same posting share no ID, so they aren't matched. No change in #649 fixes it: a per-job key table wouldn't help, and in-place key upgrades rarely fire because #652 uses the apply URL as `externalId` when a row has no ID. Mitigations to propose: employer links from adapters (#652) and a company + title posting guard (#654).

## Open questions

- Resolved 2026-11-17: #652 owner replied "LGTM" to the contract (https://github.com/KnightHacks/forge/issues/633#issuecomment-6961617503): split `complete` into `complete` plus `inventory: "full" | "rolling"`, look up or create `JobSource` by provider and boardKey, make `track` optional, and move the zod schema into `@forge/validators`.
- Resolved 2026-11-19: upstream's "recent catch-up" posting of first-run jobs is not ported; the baseline stays fully silent, matching #649's "silent first-run baseline".

## Task list

- [x] Agree the snapshot contract in #633.
- [x] Complete reverse-prompting for `spec.md`.
- [ ] Human review of `srd.md` (drafted from the approved plan, not reverse-prompted).
- [ ] Human review of `test-cases.md` (drafted from the approved plan, not reverse-prompted).
- [ ] Human approves the full artifact bundle (spec approved 2026-11-17).
- [x] Pure functions: normalize, classify, locations (+ `findUsCity`).
- [x] `ingest.ts` + `job-board.server.ts` export.
- [x] Tests: per-source fixtures + DB ingest scenarios.

## Validation / commands

- 2026-11-17 `pnpm format`: pass
- 2026-11-17 `pnpm lint`: pass (0 errors; one max-lines warning in the new integration test)
- 2026-11-17 `pnpm typecheck`: pass (33/33)
- 2026-11-17 `@forge/api` vitest, full suite against local PostgreSQL 16: 151 files, 1248 tests pass, including 13 rule tests and 12 ingest DB tests
- 2026-11-17 `@forge/validators` vitest: 29 files, 380 tests pass

## Links

- PRs: #670 (#651 router, shares `utils/job-board/`)
- Issues: #633, #649, #652 (branch `career/job-poster-to-cron`), #653, #654
- Discord/thread context:
Loading
Loading