Gates reject on evidence only, any gates are one group, remote is read off the location line

A require gate on an empty column gated the role ("country unknown"), and extract, the stage that fills the column, is bounded to the roles that rank, so 2,281 of 15,556 open roles could never come back: every board that writes "Remote", "Hybrid" or "Distributed" as its location. An empty column now neither passes nor fails a gate; the role ranks, extract reads it, the rescore decides.

`any` is a third gate mode: the any gates are one group a role must match one of, so a ranking can say "in Denmark, or remote", which require alone could not. The group is gated only when some member had evidence against it.

`remote_of(place)` fills `remote` from the location line the way `country_of` fills `country`, and the startup backfill does both, since Greenhouse writes "Hybrid" as the location and gives no flag.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 19:30:06 +02:00
1 parent e602eb3388
commit fb83ae5099
10 files changed
+143 -28

No files matched your search

+27 -8
View File
@@ -4,8 +4,16 @@ A role is scored per agent, `(uid, agent) -> score`, because a role is only
good for a given search. For each agent:
require gates a role that fails one keeps its row, with score 0 and the
reason ("place unknown", "remote not remote")
reason ("remote not remote")
any gates one group: a role that matches none of them, and has the
column filled for at least one, is gated ("none of
country DK / remote remote")
prefer gates `weight` when the role matches, 0 when it does not
A gate rejects on evidence, never on absence: a role whose column is empty
is not gated by it. `extract` is what fills an empty column, and it reads
only the roles that rank, so gating on an empty column would keep those
roles out of extract's reach for good.
fit cos(role vector, intent vector), min-max scaled across
the roles this agent scores in this run: the closest is 1,
the farthest 0, a lone role 1
@@ -117,21 +125,32 @@ def scale(cosines: dict[str, float]) -> dict[str, float]:
return {uid: (value - low) / (high - low) for uid, value in cosines.items()}
def _reason(gate: Gate, state: int) -> str:
if state < 0:
return f"{gate.field} unknown"
def _wanted(gate: Gate) -> str:
if gate.field == "salary_min":
return f"salary_min {min(gate.values, key=lambda v: float(v))}"
return f"{gate.field} {' / '.join(str(v) for v in gate.values)}"
def _reason(gate: Gate) -> str:
if gate.field == "salary_min":
return f"salary_min under {min(gate.values, key=lambda v: float(v))}"
return f"{gate.field} not {' / '.join(str(v) for v in gate.values)}"
def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
"""Every require gate this role fails, as reasons. None for a favourite,
which skips the gates."""
"""Why this role is gated, as reasons: every require gate it fails, and
the `any` group when it matches none of them. A gate with an empty column
(state -1) neither passes nor fails, so the group fails only when some
member had evidence. None for a favourite, which skips the gates."""
if candidate.affinity == 2:
return []
return [_reason(g, state) for g, state in zip(gates, candidate.gates, strict=True)
if g.mode == "require" and state != 1]
states = list(zip(gates, candidate.gates, strict=True))
reasons = [_reason(g) for g, state in states if g.mode == "require" and state == 0]
group = [(g, state) for g, state in states if g.mode == "any"]
if group and not any(state == 1 for _, state in group) \
and any(state == 0 for _, state in group):
reasons.append("none of " + ", ".join(_wanted(g) for g, _ in group))
return reasons
def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
+4 -3
View File
@@ -46,9 +46,10 @@ def create_app(config: Config | None = None) -> FastAPI:
store = Store(config.database)
jobs.seed_agents(config, store)
jobs.seed_searches(config, store)
# Roles pulled before `country` was read from `place` have none; after the
# first start only the places the lookup cannot place are left to read.
store.backfill_country()
# Roles stored before a word reached the place lookups have no country or
# remote from it; after the first start only the lines the lookups cannot
# read are left, and those are read again each start, which is cheap.
store.backfill_from_place()
app = FastAPI(title="roledesk", docs_url="/api/docs",
summary="ATS boards and job searches in, roles scored per search agent, "
+30 -3
View File
@@ -188,6 +188,30 @@ def country_of(place: str) -> str:
Remote = Literal["", "remote", "hybrid", "onsite"]
REMOTE: tuple[str, ...] = get_args(Remote)
#: Words in a location line that say how the role is worked, for a board that
#: gives no remote flag of its own: Greenhouse writes "Remote", "Hybrid" or
#: "Distributed" as the location and nothing else.
_REMOTE_WORDS: tuple[tuple[str, str], ...] = (
("hybrid", "hybrid"),
("remote", "remote"), ("distributed", "remote"), ("home based", "remote"),
("home-based", "remote"), ("work from home", "remote"), ("anywhere", "remote"),
("worldwide", "remote"), ("telecommute", "remote"),
("on-site", "onsite"), ("onsite", "onsite"), ("on site", "onsite"),
("in-office", "onsite"), ("in office", "onsite"),
)
def remote_of(place: str) -> str:
"""How a board's location line says the role is worked, as one of
`REMOTE`, or '' when it does not say. "Hybrid" wins over "remote" in the
same line ("Remote or hybrid, Berlin" is hybrid: some days in an office),
and a line that names only a place is ''."""
folded = _fold(place or "")
for word, mode in _REMOTE_WORDS:
if word in folded:
return mode
return ""
Seniority = Literal["", "intern", "junior", "mid", "senior", "staff", "lead", "manager",
"director", "exec"]
SENIORITIES: tuple[str, ...] = get_args(Seniority)
@@ -363,13 +387,16 @@ GateField = Literal["place", "country", "remote", "seniority", "function", "sala
"currency", "permit", "languages", "company"]
GATE_FIELDS: tuple[str, ...] = get_args(GateField)
GateMode = Literal["require", "prefer"]
GateMode = Literal["require", "any", "prefer"]
class Gate(Model):
"""One condition of an agent. `require` gates a role that fails it (the
row is kept with the reason); `prefer` adds `weight` to its score when it
matches."""
row is kept with the reason); the `any` gates together are one group a
role must match at least one of ("in Denmark, or remote"); `prefer` adds
`weight` to its score when it matches. A gate rejects on evidence only: a
role whose column is empty is not rejected, since `extract` fills the
column later for the roles that rank, and only for those."""
field: GateField
values: list[str | int | float] = Field(min_length=1)
+16 -8
View File
@@ -22,7 +22,7 @@ import numpy as np
from desk.models import Item
from app.models import (
AFFINITY, REMOTE, STATUSES, Agent, Application, ApplicationEvent, Candidate,
Company, Gate, Role, ScoredRole, Subscription, Weights, company_key, country_of,
Company, Gate, Role, ScoredRole, Subscription, Weights, company_key, country_of, remote_of,
place_key, title_key,
)
from app.storage import schema
@@ -291,6 +291,7 @@ class Store:
}
row |= {name: str(raw.get(name) or "") for name in _RAW_TEXT}
row["country"] = row["country"] or country_of(place)
row["remote"] = row["remote"] or remote_of(place)
row |= {name: _int_or_none(raw.get(name)) for name in _RAW_INT}
keep_filled = ("company", "company_key", "place_key", "remote", "description",
@@ -608,14 +609,21 @@ class Store:
"UPDATE roles SET closed_at = ? WHERE subscription_id = ? AND closed_at IS NULL",
(self.now(), subscription_id))
def backfill_country(self) -> int:
"""Fill `country` from `place` on every role that has none, the way
`upsert_role` does for a new one. Returns how many it filled."""
rows = self._rows("SELECT uid, place FROM roles WHERE country = '' AND place != ''")
filled = [(code, r["uid"]) for r in rows if (code := country_of(r["place"]))]
def backfill_from_place(self) -> int:
"""Fill `country` and `remote` from `place` on every role that has
none, the way `upsert_role` does for a new one, so a word added to the
lookups reaches the roles already stored. Returns how many columns it
filled."""
rows = self._rows("SELECT uid, place FROM roles "
"WHERE place != '' AND (country = '' OR remote = '')")
countries = [(code, r["uid"]) for r in rows if (code := country_of(r["place"]))]
remotes = [(mode, r["uid"]) for r in rows if (mode := remote_of(r["place"]))]
with self.transaction() as conn:
conn.executemany("UPDATE roles SET country = ? WHERE uid = ?", filled)
return len(filled)
conn.executemany("UPDATE roles SET country = ? WHERE uid = ? AND country = ''",
countries)
conn.executemany("UPDATE roles SET remote = ? WHERE uid = ? AND remote = ''",
remotes)
return len(countries) + len(remotes)
# -------------------------------------------------------------- extract
+1 -1
View File
@@ -34,7 +34,7 @@
<summary>Advanced</summary>
<label>Gates
<textarea id="a-gates" class="code" rows="6" spellcheck="false">[]</textarea>
<span class="hint">Rules a role must meet (require) or that lift it (prefer), as JSON: <code>[{"field": "country", "values": ["DK"], "mode": "require"}, {"field": "remote", "values": ["remote"], "mode": "prefer", "weight": 0.05}]</code>. Fields: place, country, remote, seniority, function, salary_min, currency, permit, languages, company. EU is a role open anywhere in Europe.</span></label>
<span class="hint">Rules a role must meet (require), must meet one of (any), or that lift it (prefer), as JSON: <code>[{"field": "country", "values": ["DK"], "mode": "any"}, {"field": "remote", "values": ["remote"], "mode": "any"}, {"field": "seniority", "values": ["senior", "staff"], "mode": "prefer", "weight": 0.05}]</code> is "in Denmark, or remote". Fields: place, country, remote, seniority, function, salary_min, currency, permit, languages, company. EU is a role open anywhere in Europe. A rule only rejects a role whose column is filled; an empty one ranks until extract reads the posting.</span></label>
</details>
<div class="agent-actions">
<button type="submit">Save and score</button>