Merge main (the R3 bug fixes) into wp-review-docs

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-30 15:46:52 +02:00
commit dd0eee9ebb
9 files changed
+119 -22

No files matched your search

+13 -7
View File
@@ -9,6 +9,8 @@ good for a given search. For each agent:
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
exclude gates a role that matches one of the values keeps its row, with
score 0 and the value ("title account executive")
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
@@ -29,7 +31,8 @@ roles out of extract's reach for good.
Every term is 0..1. The score is the weighted sum over the sum of the weights
(the agent's four and its prefer gates'), so it stays 0..1. A favourite
company (`affinity = 2`) skips the `any` group but not the `require` gates, and
company (`affinity = 2`) skips the `any` group but not the `require` or
`exclude` gates, and
is scored like any other company with its affinity term at 1: nothing puts
its roles above a better fit. A hidden one (`-1`) is not scored at all. A
role with no vector is scored without `fit` and `taste`, unless `fit` is all
@@ -156,14 +159,17 @@ def _reason(gate: Gate) -> str:
def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
"""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. A favourite company's roles skip the `any` group but
not the require gates, so a star widens a search to a company's roles
within e.g. Europe, not to the whole world."""
"""Why this role is gated, as reasons: every require gate it fails, every
exclude gate it matches, 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. A favourite company's
roles skip the `any` group but not the require and exclude gates, so a
star widens a search to a company's roles within e.g. Europe, not to the
whole world, and not to the titles the agent leaves out."""
states = list(zip(gates, candidate.gates, strict=True))
reasons = [_reason(g) for g, state in states if g.mode == "require" and state == 0]
reasons += [f"{g.field} {g.values[state - 1]}" for g, state in states
if g.mode == "exclude" and state > 0]
group = [(g, state) for g, state in states if g.mode == "any"]
if candidate.affinity != 2 and group and not any(state == 1 for _, state in group) \
and any(state == 0 for _, state in group):
+12 -5
View File
@@ -1167,21 +1167,26 @@ class Application(Model):
#: The role columns a gate can name. `company` matches on the company key;
#: `place` takes the Place filter's tokens (`app.places`: `country:DK`,
#: `region:skane`, `place:malmo`, bare text a `place:`) on whole words; the rest are
#: `region:skane`, `place:malmo`, bare text a `place:`) on whole words; `title`
#: matches a value as whole words anywhere in the title, folded as `title_key`
#: folds it, so `account executive` finds "Enterprise Account Executive, UK"
#: and `data engineer` does not find "Data Engineering Manager"; the rest are
#: case-insensitive equality, except `salary_min` (at least the value) and
#: `languages` (every language the role requires is one of the values).
GateField = Literal["place", "country", "remote", "seniority", "function", "salary_min",
"currency", "permit", "languages", "company"]
"currency", "permit", "languages", "company", "title"]
GATE_FIELDS: tuple[str, ...] = get_args(GateField)
GateMode = Literal["require", "any", "prefer"]
GateMode = Literal["require", "any", "prefer", "exclude"]
class Gate(Model):
"""One condition of an agent. `require` gates a role that fails it (the
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
`weight` to its score when it matches; `exclude` gates a role that matches
any of its values ("title account executive"), a favourite's too. 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."""
@@ -1297,7 +1302,9 @@ class Agent(Model):
class Candidate(Model):
"""What scoring reads about one open role for one agent: its posted
date (for `recency`), its company's affinity for that agent, and per
gate `1` match, `0` no match, `-1` the column is empty."""
gate `1` match, `0` no match, `-1` the column is empty. An `exclude`
gate's match is the position of the first value it matched, from 1, so
the reason can name it."""
uid: str
posted_at: str
+13 -4
View File
@@ -39,8 +39,8 @@
"HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE",
"IS", "LI", "NO", "GB", "CH", "EU"];
const FIELDS = ["place", "country", "remote", "seniority", "function", "salary_min",
"currency", "permit", "languages", "company"];
const MODES = [["require", "must"], ["any", "one of"], ["prefer", "prefer"]];
"currency", "permit", "languages", "company", "title"];
const MODES = [["require", "must"], ["any", "one of"], ["prefer", "prefer"], ["exclude", "not"]];
const HYBRID_WEIGHT = 0.05;
/** @type {object[]} every agent, as the server lists them */
@@ -227,11 +227,14 @@
const must = of("require").map(phrase);
const prefer = of("prefer").map((g) => phrase(g).replace(/^with /, ""));
if (where.hybrid) prefer.unshift("hybrid");
const not = of("exclude").map(phrase);
const sentences = [];
const any = whereSentence(where, of("any"));
if (any) sentences.push(any);
if (must.length) sentences.push(`Only roles ${must.join(" and ")}.`);
if (prefer.length) sentences.push(`Prefers ${prefer.join("; ")}.`);
if (where.titles) sentences.push(`Leaves out titles with ${orList(where.titles.values.map((t) => `“${t}”`))}.`);
if (not.length) sentences.push(`Leaves out roles ${not.join(" or ")}.`);
return sentences.join(" ");
}
@@ -497,7 +500,7 @@
// that is Europe and the countries line exactly, and only with Remote
// ticked; any other must on country is a row, and Remote reads anywhere.
function distribute(gates) {
const where = { countries: null, places: null, remote: null, europe: null, hybrid: null };
const where = { countries: null, places: null, remote: null, europe: null, hybrid: null, titles: null };
const rest = [];
const musts = [];
const plain = (g) => g.weight === undefined || g.weight === 1;
@@ -512,6 +515,7 @@
else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote")) slot = "remote";
else if (g.field === "place" && g.mode === "any" && plain(g)) slot = "places";
else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid")) slot = "hybrid";
else if (g.field === "title" && g.mode === "exclude" && plain(g)) slot = "titles";
if (slot && !where[slot]) where[slot] = g;
else rest.push(g);
}
@@ -561,7 +565,9 @@
const { where, rest } = distribute(row ? row.gates : []);
const countries = countryInput(where.countries ? where.countries.values : []);
const places = wordInput(where.places ? where.places.values : [], "Add a town");
const titles = wordInput(where.titles ? where.titles.values : [], "account executive");
const terms = wordInput(row ? row.fetch_terms || [] : [], "machine learning, data science");
$("#a-titles", f).replaceWith(titles.node);
$("#a-terms", f).replaceWith(terms.node);
$("#a-countries", f).replaceWith(countries.node);
$("#a-towns", f).replaceWith(places.node);
@@ -601,7 +607,8 @@
});
// The gates the Where block says, in the order the starter agents have
// them: the must on country, the lines, then hybrid.
// them: the must on country, the lines, then hybrid; and the titles left
// out, the block under it.
function whereGates() {
const out = [];
const within = countries.values();
@@ -615,6 +622,8 @@
if ($("#a-hybrid", f).checked) {
out.push({ field: "remote", values: ["hybrid"], mode: "prefer", weight: Number($("#a-hybrid-weight", f).value) });
}
const left = titles.values();
if (left.length) out.push({ field: "title", values: left, mode: "exclude" });
return out;
}
// The gates Save sends: the Where block's, then the rows. The sentence
+2 -1
View File
@@ -1223,7 +1223,8 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
border-radius: .3rem; padding: .35rem .5rem;
}
/* The fieldsets that hold rows: a column, the Add button under the rows. */
.agent-form fieldset.prompts, .agent-form fieldset.where, .agent-form fieldset.terms,
.agent-form fieldset.prompts, .agent-form fieldset.where, .agent-form fieldset.titles,
.agent-form fieldset.terms,
.agent-form fieldset.rules {
display: flex; flex-direction: column; align-items: stretch; gap: .5rem; min-width: 0;
border: 1px solid var(--line); border-radius: .3rem;
+16 -4
View File
@@ -219,6 +219,13 @@ def _gate_sql(gate: Gate, gaz: places.Gazetteer) -> tuple[str, str, list[Any]]:
if gate.field == "place":
match, params = _places_sql(values, gaz, table="r")
return "r.place = ''", match, params
if gate.field == "title":
# Whole words of the folded title: " account executive " inside
# " enterprise account executive uk ". A fold drops `%` and `_`, so a
# value cannot smuggle a LIKE wildcard in.
words = [f"% {title_key(v)} %" for v in values if title_key(v)]
match = " OR ".join("(' ' || r.title_key || ' ') LIKE ?" for _ in words) or "0"
return "r.title_key = ''", f"({match})", words
if gate.field == "company":
keys = [company_key(v) for v in values]
return ("r.company_key = ''",
@@ -1830,10 +1837,15 @@ class Store:
params: list[Any] = []
gaz = self.gazetteer()
for n, gate in enumerate(gates):
empty, match, values = _gate_sql(gate, gaz)
columns.append(
f"CASE WHEN {empty} THEN -1 WHEN {match} THEN 1 ELSE 0 END AS g{n}")
params += values
# An exclude gate says which of its values matched: one WHEN each.
parts = ([gate.model_copy(update={"values": [v]}) for v in gate.values]
if gate.mode == "exclude" else [gate])
whens = []
for k, part in enumerate(parts, 1):
empty, match, values = _gate_sql(part, gaz)
whens.append(f"WHEN {match} THEN {k}")
params += values
columns.append(f"CASE WHEN {empty} THEN -1 {' '.join(whens)} ELSE 0 END AS g{n}")
select = ", ".join(["r.uid", "r.posted_at",
"COALESCE(ac.affinity, 0) AS affinity", *columns])
rows = self._rows(
+8
View File
@@ -49,6 +49,14 @@
<span class="hint">This one ranks rather than filters: a hybrid role gains a little.</span>
<p id="a-where-sum" class="where-sum" role="status"></p>
</fieldset>
<fieldset class="titles">
<legend>Which titles to leave out?</legend>
<div class="where-line">
<span>Leave out titles with</span>
<div id="a-titles"></div>
</div>
<span class="hint">Separate phrases with a comma or Enter. A phrase matches whole words anywhere in the title, whatever the case: <code>account executive</code> takes "Enterprise Account Executive, UK", and <code>data engineer</code> leaves "Data Engineering Manager" alone. A shorter phrase takes more: <code>sales</code> takes Sales Engineer too. It applies to liked companies as well. A role left out keeps its row, and Show gated on Roles lists it with the phrase that took it.</span>
</fieldset>
<fieldset class="terms">
<legend>What big boards send</legend>
<div class="where-line">
+2
View File
@@ -164,6 +164,8 @@ What was decided for roledesk and the one reason for each. The longer reasoning
**Gates match loosely where the column is free text.** `place` takes the Place filter's tokens on whole folded words, so `Berlin` matches "Berlin, Germany" and `Lund` no longer matches "Billund"; `company` compares company keys, `languages` passes when every required language is a value, `salary_min` is at least the smallest value, and the rest are case-insensitive equality. Each gate is one SQL `CASE` column, so a require gate filters while the gated row keeps every failed gate as its reason.
**`exclude` gates titles out by phrase, not by `function`.** Sales titles (Account Executive, Account Director, Client Partner) and individual data engineering ranked high for the owner's agent, since their postings read like the sales engineering and data leadership the prompts describe. `function = sales` could not remove them: the keyword classifier files "Solutions Engineer" and "pre-sales" under sales, so on the data of 2026-09-30 it would also have gated Field CTO, Director Field Engineering, Staff Solutions Engineer and every AI Deployment Strategist in the agent's top 400. The fourth mode, `exclude`, gates a role that matches any of its values, and the gate's `CASE` column returns the position of the first value that matched so the reason names it ("title account executive"). It applies to favourites, which skip only the `any` group. The new `title` field matches a value as whole words of `title_key`, `LIKE '% phrase %'` over the padded key, so `data engineer` gates "Senior MLOps/Data Engineer" and not "Data Engineering Manager", and Forward Deployed Engineer is untouched. The form has a Leave out titles line under Where. Bare `sales` and `vice president` stay off the owner's list, because they would take Sales Engineer and VP roles, and `account manager` stays off because it would take Technical Account Manager. Measured on the agent's 5,089 ranked roles, the list the owner took gated 283, 13 of them in the top 100.
**A role with no vector is scored without `fit`.** The fit weight leaves the denominator, so a role `embed` has not reached yet ranks on recency, affinity and prefer gates instead of sinking to the bottom. It is gated as "no vector" only when fit is the only weighted term, and as "no intent vector" when the intent could not be embedded.
**Each run replaces an agent's scores.** `replace_scores` deletes and inserts in one transaction, so a role closed or muted since the last run drops out rather than keeping a stale score, and a reader sees one list or the other.
+3 -1
View File
@@ -42,7 +42,9 @@ Open roles without copies: 20,578. `remote` is `remote` on 3,177, `hybrid` on 3,
4. **A role whose area is not stated matches no remote chip in the feed.** In an agent's gate it is empty, which by the gate rule neither passes nor fails, so it ranks, `extract` reads it and the rescore gates it.
5. **For remote, the model wins, as it does for seniority.** `remote_model` is new, and `remote` is the model's value, else the host's word, else the place line. The prompt says remote when the hire works from home most of the time, even with a regular office week, and hybrid when there are set office days each week. Black Forest Labs then reads as remote.
6. **Extract reads the area once more for the roles it has read.** A role waits while `remote_where_model` is NULL (never asked). `[]` means asked and not stated. The existing per-agent bounds apply, so no new cost bound is needed.
7. **Agents get a gate field `remote_from`, whose values are place tokens.** It matches as the chip does. The live agent's `remote: [remote]` gate keeps working until the owner edits it, since the Where block then writes `remote_from`.
7. **An agent's scope is explicit** (owner, 2026-09-30). The `require` gate on `country`, Europe for the owner's agent, is the first line of the Where block: "Only roles in: Europe / these countries / everywhere". A company set to All countries is read within it, as `reach` already does. A remote role is in scope when its area overlaps the scope or is Anywhere, so the scope gate reads a remote role through its area, and "Home Based - Worldwide" stays in Europe's scope.
8. **Plain Remote is every remote role within the scope.** The token `remote:any` (label "Remote") and the agent's existing `remote: [remote]` any gate both mean it. "Remote · Denmark" narrows it to the roles open to someone living in Denmark, which includes Europe-wide and Anywhere roles. There is no "Remote · anywhere" suggestion. Anywhere is part of every remote chip, and the badge still says "remote · anywhere".
9. **Agents get a gate field `remote_from`, whose values are place tokens.** It matches as the chip does and is the Where block's "only when open to someone in" line. The `remote: [remote]` gate stays the plain "remote within the scope" line, so the live agent loads and saves unchanged.
## Contract between the packages
+50
View File
@@ -365,6 +365,56 @@ def test_failed_gates_reads_evidence_only() -> None:
"none of remote remote, seniority senior"]
def test_an_exclude_gate_on_title_gates_whole_words_and_names_the_value(
store: Store, config: Config, fake: FakeEmbedder) -> None:
"""The sales and data engineering titles the owner does not want: a
phrase matches whole words of the folded title, so "Data Engineering
Manager" and "Forward Deployed Engineer" stay, and the reason names the
phrase that matched."""
ae = role(store, "1", "Enterprise Account Executive, UK")
de = role(store, "2", "Senior MLOps/Data Engineer")
manager = role(store, "3", "Data Engineering Manager")
fde = role(store, "4", "Forward Deployed Engineer")
se = role(store, "5", "Sales Engineer (SE)")
agent = store.save_agent("No sales", "", [
Gate(field="title", values=["Account Executive", "data engineer"], mode="exclude")])
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert scores[ae] == (0.0, "title Account Executive")
assert scores[de] == (0.0, "title data engineer")
assert all(scores[uid][1] == "" and scores[uid][0] > 0 for uid in (manager, fde, se))
def test_a_favourite_is_gated_by_an_exclude_gate_it_matches(
store: Store, config: Config, fake: FakeEmbedder) -> None:
"""A star skips the `any` group, not the titles the agent leaves out."""
store.add_company("Fave")
director = role(store, "1", "Account Director, Nordics", company="Fave")
engineer = role(store, "2", "Forward Deployed Engineer", company="Fave")
agent = store.save_agent("No sales", "", [
Gate(field="title", values=["account director"], mode="exclude")])
store.set_affinity(agent.id, "fave", 2)
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert scores[director] == (0.0, "title account director")
assert scores[engineer][1] == ""
def test_failed_gates_names_the_value_an_exclude_gate_matched() -> None:
gates = [Gate(field="country", values=["DK"]),
Gate(field="title", values=["account executive", "rvp"], mode="exclude")]
def cand(*states: int) -> Candidate:
return Candidate(uid="u", posted_at=NOW.isoformat(), affinity=2, gates=list(states))
assert score.failed_gates(cand(1, 0), gates) == []
assert score.failed_gates(cand(1, -1), gates) == []
assert score.failed_gates(cand(1, 2), gates) == ["title rvp"]
assert score.failed_gates(cand(0, 1), gates) == ["country not DK", "title account executive"]
def test_a_prefer_gate_adds_its_weight_to_the_score(
store: Store, config: Config, fake: FakeEmbedder) -> None:
remote = role(store, "1", remote="remote")