Let the model report a verdict per must-have and cap career at 39 in code when one is broken

The judge numbers an agent's must-haves (one per line) and answers met, broken or unclear for each; career is stored as the model gave it and counts as at most BROKEN_CAP when a role is served, in cv_score, Store.judgement and the SQL of Best CV match. Migration 29 adds role_judgements.musts and broken; the judge's input_key carries a format version so earlier judgements are made again. The reader lists the must-haves with their verdicts and the cap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet 5.5 committed 2026-10-03 22:40:54 +02:00
1 parent 64fecf57ad
commit 001fc9002b
19 files changed
+336 -61

No files matched your search

+24 -2
View File
@@ -400,8 +400,11 @@ CREATE TABLE IF NOT EXISTS scores (
-- and the role closing. skills, experience and career are 0 to 100,
-- cv_score their weighted total, strengths and gaps JSON lists. input_key
-- is a hash of the CV, prompts, avoid text and the role's text it read: a
-- different one is read again. tries counts replies that left the role
-- without one since; at 3 it is given up until the agent is saved again. A
-- different one is read again. musts is a JSON list of {id, text, verdict},
-- the model's verdict on each of the agent's must-haves (one per line of its
-- must text), broken how many are "broken": career counts as at most 39 then
-- (app.models.BROKEN_CAP), applied when the role is served. tries counts
-- replies that left the role without one since; at 3 it is given up until the agent is saved again. A
-- row with judged_at NULL holds only tries.
CREATE TABLE IF NOT EXISTS role_judgements (
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
@@ -412,6 +415,8 @@ CREATE TABLE IF NOT EXISTS role_judgements (
cv_score REAL,
strengths TEXT NOT NULL DEFAULT '[]',
gaps TEXT NOT NULL DEFAULT '[]',
musts TEXT NOT NULL DEFAULT '[]',
broken INTEGER NOT NULL DEFAULT 0,
input_key TEXT NOT NULL DEFAULT '',
tries INTEGER NOT NULL DEFAULT 0,
judged_at TEXT,
@@ -698,6 +703,10 @@ UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
(28, "agents.cv_text, cv_languages, avoid_text and must_text, roles.languages_required and the "
"deadline columns, and role_judgements: the CV match, the language flag and the "
"deadline", lambda conn: _add_cv_match(conn)),
# A Python step: it adds the columns only where they are missing. Rows
# keep their numbers; the judge reads them again (judge.FORMAT).
(29, "role_judgements.musts and broken: the verdict on each must-have, and how many are "
"broken", lambda conn: _add_musts(conn)),
)
#: What a file created from `SCHEMA` today is already at.
@@ -1025,6 +1034,19 @@ def _add_cv_match(conn: sqlite3.Connection) -> None:
PRIMARY KEY (uid, agent_id))""")
def _add_musts(conn: sqlite3.Connection) -> None:
"""Migration 29's step: `role_judgements.musts`, a JSON list, and
`broken`, the count of must-haves it holds as broken, empty and 0 on
every row. `judge.input_key` changed with it, so each judgement is read
again; until then it serves with no must-haves and no cap. Runs twice
without harm."""
columns = {r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
for column, ddl in (("musts", "TEXT NOT NULL DEFAULT '[]'"),
("broken", "INTEGER NOT NULL DEFAULT 0")):
if column not in columns:
conn.execute(f"ALTER TABLE role_judgements ADD COLUMN {column} {ddl}")
def _add_all_roles(conn: sqlite3.Connection) -> None:
"""Migration 21's step. The column; the tag for every company that is a
favourite of any agent, since favourite no longer widens what a pull
+29 -16
View File
@@ -11,7 +11,7 @@ from __future__ import annotations
import json
import sqlite3
from collections import Counter
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
from contextlib import closing, contextmanager
from datetime import UTC, datetime, timedelta
from pathlib import Path
@@ -26,7 +26,7 @@ from app.models import (
AFFINITY, HAND_REASONS, LEVELS, STATUSES, Agent, Application,
ApplicationEvent, Candidate, Company, CvLanguage, Gate, Judgement, Limits, Prompt, Role,
RoleCopy, RolePlace, RoleRow, ScoredRole, cv_languages as normal_languages, cv_score,
language_flag, role_languages,
BROKEN_CAP, capped_career, language_flag, role_languages,
Subscription, Weights, check_prompts, company_fold, company_key, country_of, excerpt, place_key,
fetch_terms as normal_terms, host_word, iso_day, posted_at, posted_host, remote_of, title_key,
)
@@ -120,7 +120,7 @@ _VOTED_SCORE = ("MIN(1.0, s.score * CASE v.vote WHEN -1 THEN 0.5 "
_WITH_VOTES = "LEFT JOIN role_votes v ON v.uid = roles.uid AND v.agent_id = ?"
#: The agent's `judge` readings beside every role, the same way: `j.skills`,
#: `j.experience` and `j.career` are NULL for a role not judged and with no
#: `j.experience`, `j.career` and `j.broken` are NULL for a role not judged and with no
#: agent.
_WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agent_id = ? "
"AND j.judged_at IS NOT NULL")
@@ -129,15 +129,19 @@ _WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agen
def _cv_sql(weights: Weights | None) -> str:
"""`cv_score` as SQL for one agent's weights, unrounded (`app.models.cv_score`
rounds it): NULL for a role not judged, and for all three weights 0. The
rounds it): NULL for a role not judged, and for all three weights 0. Career
counts as at most `BROKEN_CAP` when the judgement holds a broken
must-have (`j.broken`), as `app.models.capped_career` has it. The
numbers are the model's validated, finite floats, so they are written in
rather than bound, the select's placeholders being then no concern."""
w = weights or Weights()
total = w.cv_skills + w.cv_experience + w.cv_career
if not total:
return "NULL"
career = (f"(CASE WHEN j.broken > 0 AND j.career > {BROKEN_CAP} THEN {BROKEN_CAP} "
"ELSE j.career END)")
return (f"(({w.cv_skills!r} * j.skills + {w.cv_experience!r} * j.experience "
f"+ {w.cv_career!r} * j.career) / {total!r})")
f"+ {w.cv_career!r} * {career}) / {total!r})")
def _by_cv(expression: str) -> str:
@@ -1888,27 +1892,34 @@ class Store:
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
experience: int, career: int, strengths: Sequence[str],
gaps: Sequence[str]) -> bool:
gaps: Sequence[str], musts: Sequence[Mapping[str, str]] = ()) -> bool:
"""Store `judge`'s reading of one role for one agent, replacing the
one before, with `cv_score` (`app.models.cv_score`, at the default weights: the
table's column is not read, see `judgement`) and its tries
back at 0. False for an unknown role or agent."""
one before: the three numbers as the model gave them, the verdict on
each of the agent's must-haves (`musts`, `{id, text, verdict}`) and how
many are broken, `cv_score` (`app.models.cv_score`, at the default
weights and with the cap: the table's column is not read, see
`judgement`) and its tries back at 0. False for an unknown role or
agent."""
broken = sum(1 for m in musts if m.get("verdict") == "broken")
try:
with self.transaction() as conn:
conn.execute(
"""INSERT INTO role_judgements (uid, agent_id, skills, experience, career,
cv_score, strengths, gaps, input_key, tries,
judged_at)
VALUES (?,?,?,?,?,?,?,?,?,0,?)
cv_score, strengths, gaps, musts, broken,
input_key, tries, judged_at)
VALUES (?,?,?,?,?,?,?,?,?,?,?,0,?)
ON CONFLICT(uid, agent_id) DO UPDATE SET
skills=excluded.skills, experience=excluded.experience,
career=excluded.career, cv_score=excluded.cv_score,
strengths=excluded.strengths, gaps=excluded.gaps,
musts=excluded.musts, broken=excluded.broken,
input_key=excluded.input_key, tries=0, judged_at=excluded.judged_at""",
(uid, agent_id, skills, experience, career,
cv_score(skills, experience, career),
cv_score(skills, experience, career, broken=broken),
json.dumps(list(strengths), ensure_ascii=False),
json.dumps(list(gaps), ensure_ascii=False), input_key, self.now()))
json.dumps(list(gaps), ensure_ascii=False),
json.dumps([dict(m) for m in musts], ensure_ascii=False), broken,
input_key, self.now()))
except sqlite3.IntegrityError:
return False
return True
@@ -1935,7 +1946,8 @@ class Store:
def judgement(self, agent_id: int | None, uid: str) -> Judgement | None:
"""The agent's judgement of one role, None when it has none, its
`cv_score` the three numbers under the agent's weights as they are
now, not as stored."""
now, not as stored, and `career_capped` the model's career as the
broken must-haves leave it (`BROKEN_CAP`)."""
if agent_id is None:
return None
row = self._row("SELECT * FROM role_judgements WHERE agent_id = ? AND uid = ? "
@@ -1944,8 +1956,9 @@ class Store:
return None
found = Judgement.from_row(row)
agent = self.agent(agent_id)
found.career_capped = capped_career(found.career, found.broken)
found.cv_score = cv_score(found.skills, found.experience, found.career,
agent.weights if agent else None)
agent.weights if agent else None, found.broken)
return found
def set_article_text(self, uid: str, text: str) -> Role | None: