Date a role by posted_at, not just first_seen

recency and the newest feed both counted from first_seen, when the app
itself first stored a role, so a newly added board's whole backlog scored
as freshly posted for two weeks: 10,223 of 15,415 board roles were posted
more than 30 days before they were first seen (average gap in days: Ashby
78, Greenhouse 143, Lever 226, Personio 333).

Add roles.posted_at (migration 9): the earlier of first_seen and a trusted
host's published_at, where TRUSTED_POSTED_HOSTS (app/models.py) records
which of the ats and search hosts report a creation date rather than one
that moves on an edit, checked against live boards and the live database.
A future or pre-2015 date is not trusted either. upsert_role sets it on
insert and keeps the earliest on update, so an edit on the board can only
move it earlier, never later. recency, the feed's newest order, the "new
since" days filter and _top_scope's tie-break now read posted_at;
first_seen is unchanged and still what the UI shows as when the app found
a role. The row's age in roles.js now shows the posted date instead.

A partial index (posted_at DESC, uid) WHERE closed_at IS NULL serves the
newest feed; sqlite3's bundled build has no STAT4, so its planner
otherwise sorts every open role instead of using it, measured 30x slower
on the live database, so Store.roles() forces it for that query shape.

Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet committed 2026-09-29 14:13:06 +02:00
1 parent 0558ef19ed
commit 75eca1c914
8 files changed
+335 -33

No files matched your search

+21 -4
View File
@@ -80,9 +80,10 @@ def config(tmp_path: Path) -> Config:
def role(store: Store, source_id: str, title: str = "Backend Engineer", *,
company: str = "Acme", body: str = "", **raw: Any) -> str:
company: str = "Acme", body: str = "",
published_at: datetime = datetime(2026, 9, 20, tzinfo=UTC), **raw: Any) -> str:
item = Item(source_id=source_id, location=f"https://boards.example/{source_id}",
title=title, body=body, published_at=datetime(2026, 9, 20, tzinfo=UTC),
title=title, body=body, published_at=published_at,
raw={"company": company, **raw})
item.source = "ats"
store.upsert_role(item)
@@ -133,7 +134,7 @@ def test_recency_halves_every_fourteen_days() -> None:
def test_a_role_without_a_vector_is_scored_without_fit_unless_fit_is_all() -> None:
candidate = Candidate(uid="u", first_seen=NOW.isoformat(), affinity=0)
candidate = Candidate(uid="u", posted_at=NOW.isoformat(), affinity=0)
value, reason = score.score_one(candidate, [], Weights(), None, NOW)
assert reason == "" and value == pytest.approx((0.2 * 1.0 + 0.2 / 3) / 0.4)
@@ -193,7 +194,7 @@ def test_failed_gates_reads_evidence_only() -> None:
Gate(field="seniority", values=["senior"], mode="any"),
Gate(field="function", values=["engineering"], mode="prefer")]
def cand(*states: int) -> Candidate:
return Candidate(uid="u", first_seen=NOW.isoformat(), affinity=0, gates=list(states))
return Candidate(uid="u", posted_at=NOW.isoformat(), affinity=0, gates=list(states))
assert score.failed_gates(cand(1, 1, 0, 0), gates) == []
assert score.failed_gates(cand(-1, -1, -1, 0), gates) == []
assert score.failed_gates(cand(0, 0, -1, 1), gates) == [
@@ -261,6 +262,22 @@ def test_an_older_role_scores_lower(
assert scores[new][0] > scores[old][0]
def test_recency_counts_from_posted_at_not_first_seen(
store: Store, config: Config, fake: FakeEmbedder) -> None:
"""A trusted board's backlog, first seen today, must not score as fresh:
recency has to read the board's own (trusted) posted date, not the
moment the app happened to pull it in."""
stale = role(store, "1", board="greenhouse",
published_at=NOW - timedelta(days=28))
fresh = role(store, "2") # untrusted host: posted_at falls back to first_seen (NOW)
agent = store.save_agent("Any")
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert scores[fresh][0] > scores[stale][0]
def test_two_agents_rank_the_same_roles_the_other_way_round(
store: Store, config: Config, fake: FakeEmbedder) -> None:
back = role(store, "1", "Backend Engineer", body="Python services")